0
0

Refactor, lint fix, and bug fix on admin/roles/form partial (#27558)

This commit is contained in:
Matt Jankowski 2023-11-29 05:00:52 -05:00 committed by GitHub
parent 3e1e41054b
commit 186895fc88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -0,0 +1,24 @@
# frozen_string_literal: true
module Admin
module RolesHelper
def privilege_label(privilege)
safe_join(
[
t("admin.roles.privileges.#{privilege}"),
content_tag(:span, t("admin.roles.privileges.#{privilege}_description"), class: 'hint'),
]
)
end
def disable_permissions?(permissions)
permissions.filter { |privilege| role_flag_value(privilege).zero? }
end
private
def role_flag_value(privilege)
UserRole::FLAGS[privilege] & current_user.role.computed_permissions
end
end
end

View File

@ -49,7 +49,7 @@ class UserRole < ApplicationRecord
invite_users
).freeze,
moderation: %w(
moderation: %i(
view_dashboard
view_audit_log
manage_users
@ -63,7 +63,7 @@ class UserRole < ApplicationRecord
manage_invites
).freeze,
administration: %w(
administration: %i(
manage_settings
manage_rules
manage_roles
@ -72,7 +72,7 @@ class UserRole < ApplicationRecord
manage_announcements
).freeze,
devops: %w(
devops: %i(
view_devops
).freeze,

View File

@ -31,6 +31,6 @@
- (form.object.everyone? ? UserRole::Flags::CATEGORIES.slice(:invites) : UserRole::Flags::CATEGORIES).each do |category, permissions|
%h4= t(category, scope: 'admin.roles.categories')
= form.input :permissions_as_keys, collection: permissions, wrapper: :with_block_label, include_blank: false, label_method: ->(privilege) { safe_join([t("admin.roles.privileges.#{privilege}"), content_tag(:span, t("admin.roles.privileges.#{privilege}_description"), class: 'hint')]) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', label: false, hint: false, disabled: permissions.filter { |privilege| UserRole::FLAGS[privilege] & current_user.role.computed_permissions == 0 }
= form.input :permissions_as_keys, collection: permissions, wrapper: :with_block_label, include_blank: false, label_method: ->(privilege) { privilege_label(privilege) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', label: false, hint: false, disabled: disable_permissions?(permissions)
%hr.spacer/