Skip to content

Commit

Permalink
Revert "AO3-6141 Disable user role checkboxes based on admin permissi…
Browse files Browse the repository at this point in the history
…ons" (#4531)

Revert "AO3-6141 Disable user role checkboxes based on admin permissions (#4355)"

This reverts commit 630812b.
  • Loading branch information
sarken authored Jun 19, 2023
1 parent 1162f92 commit 3a6c84e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
12 changes: 0 additions & 12 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ class UserPolicy < ApplicationPolicy
"tag_wrangling" => [roles: []]
}.freeze

# Define which admin roles can edit which user roles.
ALLOWED_USER_ROLES_BY_ADMIN_ROLES = {
"open_doors" => %w[archivist opendoors],
"policy_and_abuse" => %w[no_resets protected_user],
"superadmin" => %w[archivist no_resets official opendoors protected_user tag_wrangler],
"tag_wrangling" => %w[tag_wrangler]
}.freeze

def can_manage_users?
user_has_roles?(MANAGE_ROLES)
end
Expand All @@ -45,10 +37,6 @@ def permitted_attributes
ALLOWED_ATTRIBUTES_BY_ROLES.values_at(*user.roles).compact.flatten
end

def can_edit_user_role?(role)
ALLOWED_USER_ROLES_BY_ADMIN_ROLES.values_at(*user.roles).compact.flatten.include?(role.name)
end

alias index? can_manage_users?
alias bulk_search? can_manage_users?
alias show? can_manage_users?
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/admin_users/_user_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td><%= text_field_tag "user[email]", user.email, title: ts("Email"), disabled: !admin_can_update_user_email? %></td>
<% for role in @roles %>
<td>
<%= check_box_tag "user[roles][]", role.id, user.roles.include?(role), title: role.name, id: "user_roles_#{role.id}", disabled: !policy(User).can_edit_user_role?(role) %>
<%= check_box_tag "user[roles][]", role.id, user.roles.include?(role), title: role.name, id: "user_roles_#{role.id}", disabled: !admin_can_update_user_roles? %>
</td>
<% end %>
<td>
Expand Down

0 comments on commit 3a6c84e

Please sign in to comment.