[28036] Give admin all roles in a project

https://community.openproject.com/wp/28036
pull/7314/head
Oliver Günther 6 years ago
parent 1030d470f5
commit 67b3e575ce
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 15
      app/cells/members/row_cell.rb
  2. 5
      app/models/user.rb
  3. 1
      config/locales/en.yml
  4. 18
      spec/features/work_packages/edit_work_package_spec.rb
  5. 2
      spec_legacy/unit/user_spec.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

@ -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 }

@ -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"

@ -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 }

@ -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

Loading…
Cancel
Save