diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 25f700d4af..0ee2abf166 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.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']), diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 9218d416a4..1e1cbab96b 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -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']