Commit 82d44d3d authored by Sean McGivern's avatar Sean McGivern

Merge branch '3080-present-related-issues-add-badge-when-admin-issue-link' into 'master'

Show add badge only when user can manage Related Issues

Closes #3080 and #3069

See merge request !2583
parents 4dd5bd4c b0e5261d
......@@ -69,7 +69,7 @@
- if can?(current_user, :read_issue_link, @project)
.js-related-issues-root{ data: { endpoint: project_issue_links_path(@project, @issue),
can_add_related_issues: "#{can?(current_user, :update_issue, @issue)}",
can_add_related_issues: "#{can?(current_user, :admin_issue_link, @issue)}",
help_path: help_page_path('user/project/issues/related_issues') } }
.related-issues-block
.panel-slim.panel-default
......
---
title: Present Related Issues add badge only when user can manage related issues (previously
when user could edit issue)
merge_request:
author:
require 'rails_helper'
describe 'Related issues', :js do
let(:user) { create(:user) }
let(:project) { create(:project_empty_repo, :public) }
let(:project_b) { create(:project_empty_repo, :public) }
let(:project_unauthorized) { create(:project_empty_repo, :public) }
......@@ -10,7 +11,6 @@ describe 'Related issues', :js do
let(:issue_d) { create(:issue, project: project) }
let(:issue_project_b_a) { create(:issue, project: project_b) }
let(:issue_project_unauthorized_a) { create(:issue, project: project_unauthorized) }
let(:user) { create(:user) }
context 'widget visibility' do
before do
......@@ -43,6 +43,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
end
......@@ -58,6 +59,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
it 'does not show widget when private project' do
......@@ -76,10 +78,21 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget on their own public issue' do
project = create :project_empty_repo, :public
issue = create :issue, project: project, author: user
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
end
context 'when logged in and a member' do
context 'when logged in and a guest' do
before do
gitlab_sign_in(user)
end
......@@ -92,6 +105,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget when private project' do
......@@ -102,6 +116,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget when public project' do
......@@ -112,55 +127,95 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
end
context 'when logged in and a reporter' do
before do
gitlab_sign_in(user)
end
it 'shows widget when internal project' do
project = create :project_empty_repo, :internal
issue = create :issue, project: project
project.add_reporter(user)
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget when private project' do
project = create :project_empty_repo, :private
issue = create :issue, project: project
project.add_reporter(user)
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget when public project' do
project = create :project_empty_repo, :public
issue = create :issue, project: project
project.add_reporter(user)
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).to have_selector('.js-issue-count-badge-add-button')
end
it 'shows widget on their own public issue' do
project = create :project_empty_repo, :public
issue = create :issue, project: project, author: user
project.add_reporter(user)
visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block')
expect(page).to have_selector('.js-issue-count-badge-add-button')
end
end
end
context 'when user has no permission to update related issues' do
context 'when user has no permission to manage related issues' do
let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }
before do
stub_licensed_features(related_issues: true)
project.add_guest(user)
gitlab_sign_in(user)
end
context 'with related_issues enabled' do
context 'visiting some issue someone else created' do
before do
stub_licensed_features(related_issues: true)
visit project_issue_path(project, issue_a)
wait_for_requests
end
context 'with existing related issues' do
let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }
context 'visiting issue_a' do
before do
visit project_issue_path(project, issue_a)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
it 'does not show add related issue badge button' do
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
end
context 'visiting issue_b which was targeted by issue_a' do
before do
visit project_issue_path(project, issue_b)
wait_for_requests
end
context 'visiting issue_b which was targeted by issue_a' do
before do
visit project_issue_path(project, issue_b)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
end
end
context 'when user has permission to update related issues' do
context 'when user has permission to manage related issues' do
before do
project.add_master(user)
project_b.add_master(user)
......@@ -196,10 +251,6 @@ describe 'Related issues', :js do
expect(find('.js-related-issues-header-issue-count')).to have_content('0')
end
it 'shows add related issue badge button' do
expect(page).to have_selector('.js-issue-count-badge-add-button')
end
it 'add related issue' do
find('.js-issue-count-badge-add-button').click
find('.js-add-issuable-form-input').set "#{issue_b.to_reference(project)} "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment