From b0b075226355bbc8c20ca8534491681a8515a70a Mon Sep 17 00:00:00 2001 From: Kaio Magalhaes Date: Wed, 13 Mar 2024 08:24:40 -0300 Subject: [PATCH] improve the visibility of the permissions in the admin panel --- app/models/permission.rb | 4 ++++ app/models/user_permission.rb | 4 ++++ config/initializers/rails_admin.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/app/models/permission.rb b/app/models/permission.rb index dea1018..1f7e13e 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -16,4 +16,8 @@ class Permission < ApplicationRecord validates :target, presence: true validates :ability, presence: true + + def name + "#{target} - #{ability}" + end end diff --git a/app/models/user_permission.rb b/app/models/user_permission.rb index b030c06..dd2cc4f 100644 --- a/app/models/user_permission.rb +++ b/app/models/user_permission.rb @@ -27,4 +27,8 @@ class UserPermission < ApplicationRecord validates :user, presence: { message: 'must be present' } validates :permission, presence: { message: 'must be present' } + + def name + [user&.email, permission&.name].join(' - ') + end end diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index a9f4f93..bb93d7c 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -35,6 +35,18 @@ ## To disable Gravatar integration in Navigation Bar set to false # config.show_gravatar = true + config.model 'Permission' do + object_label_method do + :name + end + end + + config.model 'UserPermission' do + object_label_method do + :name + end + end + config.actions do dashboard # mandatory index # mandatory