From 67b3e575ce5de6a0f0a70a8f9003f4e728254ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 22 May 2019 09:17:42 +0200 Subject: [PATCH] [28036] Give admin all roles in a project https://community.openproject.com/wp/28036 --- app/cells/members/row_cell.rb | 15 +++++++++++++-- app/models/user.rb | 5 +++++ config/locales/en.yml | 1 + .../work_packages/edit_work_package_spec.rb | 18 ++++++++++++++++++ spec_legacy/unit/user_spec.rb | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/cells/members/row_cell.rb b/app/cells/members/row_cell.rb index 19c63a3490..a444f99c0e 100644 --- a/app/cells/members/row_cell.rb +++ b/app/cells/members/row_cell.rb @@ -39,7 +39,12 @@ module Members end def roles - label = h member.roles.sort.collect(&:name).join(', ') + label = + if user&.admin? + I18n.t(:label_member_all_admin) + else + h member.roles.sort.collect(&:name).join(', ') + end span = content_tag "span", label, id: "member-#{member.id}-roles" if may_update? @@ -72,12 +77,18 @@ module Members end def may_update? + !user&.admin && table.authorize_update + end + + def may_delete? table.authorize_update end def button_links - if may_update? + if may_update? && may_delete? [edit_link, delete_link].compact + elsif may_delete? + [delete_link].compact else [] end diff --git a/app/models/user.rb b/app/models/user.rb index 494353a73b..ae466e6b96 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -561,8 +561,13 @@ class User < Principal # Return user's roles for project def roles_for_project(project) roles = [] + # No role on archived projects return roles unless project && project.active? + + # Return all roles if user is admin + return Role.givable.to_a if admin? + if logged? # Find project membership membership = memberships.detect { |m| m.project_id == project.id } diff --git a/config/locales/en.yml b/config/locales/en.yml index 3049e943c1..0bd350c8a4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1398,6 +1398,7 @@ en: label_max_size: "Maximum size" label_me: "me" label_member_new: "New member" + label_member_all_admin: "(All roles due to admin status)" label_member_plural: "Members" label_view_all_members: "View all members" label_menu_item_name: "Name of menu item" diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb index 199983465a..aa45ec4d18 100644 --- a/spec/features/work_packages/edit_work_package_spec.rb +++ b/spec/features/work_packages/edit_work_package_spec.rb @@ -91,6 +91,24 @@ describe 'edit work package', js: true do end end + context 'as an admin without roles' do + let(:visit_before) { false } + let(:work_package) { FactoryBot.create(:work_package, project: project, type: type2) } + let(:admin) { FactoryBot.create :admin } + + it 'can still use the manager role' do + # A role must still exist + workflow + login_as admin + visit! + + wp_page.update_attributes status: status2.name + wp_page.expect_attributes status: status2.name + + wp_page.expect_activity_message("Status changed from #{status.name}\nto #{status2.name}") + end + end + context 'with progress' do let(:visit_before) { false } diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb index 9120645baf..b51017fa7b 100644 --- a/spec_legacy/unit/user_spec.rb +++ b/spec_legacy/unit/user_spec.rb @@ -400,7 +400,7 @@ describe User, type: :model do it 'should authorize nearly everything for admin users' do project = Project.find(1) project.enabled_module_names = ['work_package_tracking', 'news', 'wiki', 'repository'] - assert ! @admin.member_of?(project) + assert @admin.member_of?(project) %w(edit_work_packages delete_work_packages manage_news manage_repository manage_wiki).each do |p| assert @admin.allowed_to?(p.to_sym, project) end