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 @@ ...@@ -69,7 +69,7 @@
- if can?(current_user, :read_issue_link, @project) - if can?(current_user, :read_issue_link, @project)
.js-related-issues-root{ data: { endpoint: project_issue_links_path(@project, @issue), .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') } } help_path: help_page_path('user/project/issues/related_issues') } }
.related-issues-block .related-issues-block
.panel-slim.panel-default .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' require 'rails_helper'
describe 'Related issues', :js do describe 'Related issues', :js do
let(:user) { create(:user) }
let(:project) { create(:project_empty_repo, :public) } let(:project) { create(:project_empty_repo, :public) }
let(:project_b) { create(:project_empty_repo, :public) } let(:project_b) { create(:project_empty_repo, :public) }
let(:project_unauthorized) { create(:project_empty_repo, :public) } let(:project_unauthorized) { create(:project_empty_repo, :public) }
...@@ -10,7 +11,6 @@ describe 'Related issues', :js do ...@@ -10,7 +11,6 @@ describe 'Related issues', :js do
let(:issue_d) { create(:issue, project: project) } let(:issue_d) { create(:issue, project: project) }
let(:issue_project_b_a) { create(:issue, project: project_b) } let(:issue_project_b_a) { create(:issue, project: project_b) }
let(:issue_project_unauthorized_a) { create(:issue, project: project_unauthorized) } let(:issue_project_unauthorized_a) { create(:issue, project: project_unauthorized) }
let(:user) { create(:user) }
context 'widget visibility' do context 'widget visibility' do
before do before do
...@@ -43,6 +43,7 @@ describe 'Related issues', :js do ...@@ -43,6 +43,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end end
end end
...@@ -58,6 +59,7 @@ describe 'Related issues', :js do ...@@ -58,6 +59,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end end
it 'does not show widget when private project' do it 'does not show widget when private project' do
...@@ -76,10 +78,21 @@ describe 'Related issues', :js do ...@@ -76,10 +78,21 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') 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
end end
context 'when logged in and a member' do context 'when logged in and a guest' do
before do before do
gitlab_sign_in(user) gitlab_sign_in(user)
end end
...@@ -92,6 +105,7 @@ describe 'Related issues', :js do ...@@ -92,6 +105,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end end
it 'shows widget when private project' do it 'shows widget when private project' do
...@@ -102,6 +116,7 @@ describe 'Related issues', :js do ...@@ -102,6 +116,7 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') expect(page).to have_css('.related-issues-block')
expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end end
it 'shows widget when public project' do it 'shows widget when public project' do
...@@ -112,26 +127,72 @@ describe 'Related issues', :js do ...@@ -112,26 +127,72 @@ describe 'Related issues', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
expect(page).to have_css('.related-issues-block') expect(page).to have_css('.related-issues-block')
end expect(page).not_to have_selector('.js-issue-count-badge-add-button')
end end
end end
context 'when user has no permission to update related issues' do context 'when logged in and a reporter' do
before do before do
project.add_guest(user)
gitlab_sign_in(user) gitlab_sign_in(user)
end end
context 'with related_issues enabled' do it 'shows widget when internal project' do
before do project = create :project_empty_repo, :internal
stub_licensed_features(related_issues: true) 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 end
context 'with existing related issues' do 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 manage related issues' do
let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b } 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 } let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }
context 'visiting issue_a' do before do
stub_licensed_features(related_issues: true)
project.add_guest(user)
gitlab_sign_in(user)
end
context 'visiting some issue someone else created' do
before do before do
visit project_issue_path(project, issue_a) visit project_issue_path(project, issue_a)
wait_for_requests wait_for_requests
...@@ -140,10 +201,6 @@ describe 'Related issues', :js do ...@@ -140,10 +201,6 @@ describe 'Related issues', :js do
it 'shows related issues count' do it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('2') expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end 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 end
context 'visiting issue_b which was targeted by issue_a' do context 'visiting issue_b which was targeted by issue_a' do
...@@ -157,10 +214,8 @@ describe 'Related issues', :js do ...@@ -157,10 +214,8 @@ describe 'Related issues', :js do
end end
end end
end 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 before do
project.add_master(user) project.add_master(user)
project_b.add_master(user) project_b.add_master(user)
...@@ -196,10 +251,6 @@ describe 'Related issues', :js do ...@@ -196,10 +251,6 @@ describe 'Related issues', :js do
expect(find('.js-related-issues-header-issue-count')).to have_content('0') expect(find('.js-related-issues-header-issue-count')).to have_content('0')
end 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 it 'add related issue' do
find('.js-issue-count-badge-add-button').click find('.js-issue-count-badge-add-button').click
find('.js-add-issuable-form-input').set "#{issue_b.to_reference(project)} " 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