Refactor, lint fix, and bug fix on admin/roles/form partial (#27558)
parent
3e1e41054b
commit
186895fc88
|
@ -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
|
|
@ -49,7 +49,7 @@ class UserRole < ApplicationRecord
|
||||||
invite_users
|
invite_users
|
||||||
).freeze,
|
).freeze,
|
||||||
|
|
||||||
moderation: %w(
|
moderation: %i(
|
||||||
view_dashboard
|
view_dashboard
|
||||||
view_audit_log
|
view_audit_log
|
||||||
manage_users
|
manage_users
|
||||||
|
@ -63,7 +63,7 @@ class UserRole < ApplicationRecord
|
||||||
manage_invites
|
manage_invites
|
||||||
).freeze,
|
).freeze,
|
||||||
|
|
||||||
administration: %w(
|
administration: %i(
|
||||||
manage_settings
|
manage_settings
|
||||||
manage_rules
|
manage_rules
|
||||||
manage_roles
|
manage_roles
|
||||||
|
@ -72,7 +72,7 @@ class UserRole < ApplicationRecord
|
||||||
manage_announcements
|
manage_announcements
|
||||||
).freeze,
|
).freeze,
|
||||||
|
|
||||||
devops: %w(
|
devops: %i(
|
||||||
view_devops
|
view_devops
|
||||||
).freeze,
|
).freeze,
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,6 @@
|
||||||
- (form.object.everyone? ? UserRole::Flags::CATEGORIES.slice(:invites) : UserRole::Flags::CATEGORIES).each do |category, permissions|
|
- (form.object.everyone? ? UserRole::Flags::CATEGORIES.slice(:invites) : UserRole::Flags::CATEGORIES).each do |category, permissions|
|
||||||
%h4= t(category, scope: 'admin.roles.categories')
|
%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/
|
%hr.spacer/
|
||||||
|
|
Loading…
Reference in New Issue