Commit 9191e87f authored by Mark Florian's avatar Mark Florian

Merge branch 'kp-fix-new-requirement-access' into 'master'

Fix new requirement & reopen button visibility

See merge request gitlab-org/gitlab!29715
parents 04efedbf 895f41af
...@@ -170,7 +170,7 @@ export default { ...@@ -170,7 +170,7 @@ export default {
<gl-loading-icon v-else /> <gl-loading-icon v-else />
</gl-deprecated-button> </gl-deprecated-button>
</li> </li>
<li v-if="isArchived" class="requirement-reopen d-sm-block"> <li v-if="canArchive && isArchived" class="requirement-reopen d-sm-block">
<gl-deprecated-button <gl-deprecated-button
size="xs" size="xs"
class="p-2" class="p-2"
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
%span.badge.badge-pill.js-all-count= total_requirements %span.badge.badge-pill.js-all-count= total_requirements
.nav-controls .nav-controls
- if is_open_tab - if is_open_tab && can?(current_user, :create_requirement, @project)
%button.btn.btn-success.js-new-requirement.qa-new-requirement-button{ type: 'button' } %button.btn.btn-success.js-new-requirement.qa-new-requirement-button{ type: 'button' }
= _('New requirement') = _('New requirement')
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
describe 'Requirements list', :js do describe 'Requirements list', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:user_guest) { create(:user) }
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:requirement1) { create(:requirement, project: project, title: 'Some requirement-1', author: user, created_at: 5.days.ago, updated_at: 2.days.ago) } let_it_be(:requirement1) { create(:requirement, project: project, title: 'Some requirement-1', author: user, created_at: 5.days.ago, updated_at: 2.days.ago) }
let_it_be(:requirement2) { create(:requirement, project: project, title: 'Some requirement-2', author: user, created_at: 6.days.ago, updated_at: 2.days.ago) } let_it_be(:requirement2) { create(:requirement, project: project, title: 'Some requirement-2', author: user, created_at: 6.days.ago, updated_at: 2.days.ago) }
...@@ -27,6 +28,7 @@ describe 'Requirements list', :js do ...@@ -27,6 +28,7 @@ describe 'Requirements list', :js do
stub_licensed_features(requirements: true) stub_licensed_features(requirements: true)
stub_feature_flags(requirements_management: { enabled: true, thing: project }) stub_feature_flags(requirements_management: { enabled: true, thing: project })
project.add_maintainer(user) project.add_maintainer(user)
project.add_guest(user_guest)
sign_in(user) sign_in(user)
end end
...@@ -242,4 +244,19 @@ describe 'Requirements list', :js do ...@@ -242,4 +244,19 @@ describe 'Requirements list', :js do
end end
end end
end end
context 'when accessing project as guest user' do
before do
sign_in(user_guest)
visit project_requirements_path(project)
wait_for_requests
end
it 'open tab does not show button "New requirement"' do
page.within('.nav-controls') do
expect(page).not_to have_selector('button.js-new-requirement')
end
end
end
end end
...@@ -235,7 +235,7 @@ describe('RequirementItem', () => { ...@@ -235,7 +235,7 @@ describe('RequirementItem', () => {
}); });
}); });
it('renders `Reopen` button when current requirement is archived', () => { it('renders `Reopen` button when current requirement is archived and `requirement.userPermissions.adminRequirement` is true', () => {
const reopenButton = wrapperArchived.find('.requirement-reopen').find(GlDeprecatedButton); const reopenButton = wrapperArchived.find('.requirement-reopen').find(GlDeprecatedButton);
expect(reopenButton.exists()).toBe(true); expect(reopenButton.exists()).toBe(true);
...@@ -243,6 +243,22 @@ describe('RequirementItem', () => { ...@@ -243,6 +243,22 @@ describe('RequirementItem', () => {
expect(reopenButton.text()).toBe('Reopen'); expect(reopenButton.text()).toBe('Reopen');
}); });
it('does not render `Reopen` button when current requirement is archived and `requirement.userPermissions.adminRequirement` is false', () => {
wrapperArchived.setProps({
requirement: {
...requirementArchived,
userPermissions: {
...mockUserPermissions,
adminRequirement: false,
},
},
});
return wrapperArchived.vm.$nextTick(() => {
expect(wrapperArchived.contains('.controls .requirement-reopen')).toBe(false);
});
});
it('renders element containing requirement updated at', () => { it('renders element containing requirement updated at', () => {
const updatedAtEl = wrapper.find('.issuable-meta .issuable-updated-at > span'); const updatedAtEl = wrapper.find('.issuable-meta .issuable-updated-at > span');
......
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