[#45084] Check permission instead of module activation

pull/11825/head
Christophe Bliard 2 years ago
parent 6d5f9e36fc
commit 36a2e1de9d
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 2
      app/helpers/projects_helper.rb
  2. 11
      spec/helpers/projects_helper_spec.rb

@ -93,7 +93,7 @@ module ProjectsHelper
end
def project_more_menu_activity_item(project)
if project.enabled_module_names.include?('activity')
if User.current.allowed_to?(:view_project_activity, project)
[
t(:label_project_activity),
project_activity_index_path(project, event_types: ['project_attributes']),

@ -112,8 +112,9 @@ describe ProjectsHelper do
end
describe '#project_more_menu_items' do
shared_let(:project) { create(:project) }
shared_let(:current_user) { create(:user) }
# need to use refind: true because @allowed_permissions is cached in the instance
shared_let(:project, refind: true) { create(:project) }
shared_let(:current_user) { create(:user, member_in_project: project) }
subject(:menu) do
items = project_more_menu_items(project)
@ -125,6 +126,8 @@ describe ProjectsHelper do
allow(User).to receive(:current).and_return(current_user)
end
# "Archive project" menu entry
context 'when current user is admin' do
before do
current_user.update(admin: true)
@ -135,7 +138,7 @@ describe ProjectsHelper do
context 'when current user has archive_project permission' do
before do
create(:member, user: current_user, project:, roles: [build(:role, permissions: [:archive_project])])
current_user.roles(project).first.add_permission!(:archive_project)
end
it { is_expected.to include(t(:button_archive)) }
@ -153,6 +156,8 @@ describe ProjectsHelper do
it { is_expected.not_to include(t(:button_archive)) }
end
# "Project activity" menu entry
context 'when project does not have activity module enabled' do
before do
project.enabled_module_names -= ['activity']

Loading…
Cancel
Save