Class: PermissionGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PermissionGroup
- Defined in:
- app/models/permission_group.rb
Overview
The PermissionGroup model represents a group of permissions in the system. It is used to manage and organize permissions for different roles and users.
Defined Under Namespace
Classes: Codes
Instance Attribute Summary collapse
-
#code ⇒ String
The unique code for the permission group.
-
#description ⇒ String
The description of the permission group.
-
#permission_group_header_id ⇒ Integer
The primary key of the permission group.
Class Method Summary collapse
-
.employee_portal ⇒ PermissionGroup
Finds the employee portal permission group.
-
.options ⇒ ActiveRecord::Relation
Retrieves a list of permission group options.
-
.payroll_admin ⇒ PermissionGroup
Finds the payroll admin permission group.
Instance Method Summary collapse
-
#active_permission_ids ⇒ Array<Integer>
Retrieves the IDs of active permissions in the permission group.
Methods inherited from ApplicationRecord
define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection
Instance Attribute Details
#code ⇒ String
Returns the unique code for the permission group.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/permission_group.rb', line 12 class PermissionGroup < ApplicationRecord # Constants for permission group codes class Codes PAYROLL_ADMIN = 'PAYROLL-ADMIN' EMPLOYEE_PORTAL = 'EMPLOYEE-PORTAL' EDI = 'EDI' AI_PLATFORM = 'AI-PLATFORM' end self.table_name = 'PERMISSION_GROUP_HEADER' self.primary_key = 'permission_group_header_id' class << self # Retrieves a list of permission group options. # # @return [ActiveRecord::Relation] a relation of permission groups with selected attributes # @example # PermissionGroup.options def select(:permission_group_header_id, :code, :description) .order(code: :asc) end # Finds the payroll admin permission group. # # @return [PermissionGroup] the payroll admin permission group # @raise [ActiveRecord::RecordNotFound] if the payroll admin permission group is not found # @example # PermissionGroup.payroll_admin def payroll_admin find_by!(code: Codes::PAYROLL_ADMIN) end # Finds the employee portal permission group. # # @return [PermissionGroup] the employee portal permission group # @raise [ActiveRecord::RecordNotFound] if the employee portal permission group is not found # @example # PermissionGroup.employee_portal def employee_portal find_by!(code: Codes::EMPLOYEE_PORTAL) end end # Associations has_and_belongs_to_many( :permissions, join_table: PermissionGroupDetails.table_name, foreign_key: primary_key, association_foreign_key: Permission.primary_key ) has_many( :permission_group_details, foreign_key: 'permission_group_header_id', class_name: 'PermissionGroupDetails', dependent: :destroy ) has_many :user_permission_groups, foreign_key: 'permission_group_header_id' has_many :erp_users, through: :user_permission_groups # Validations validates :code, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true validates :description, presence: true, length: { minimum: 1, maximum: 255 } # Retrieves the IDs of active permissions in the permission group. # # @return [Array<Integer>] an array of active permission IDs # @example # permission_group.active_permission_ids def .includes(:permission).where(active: true).map(&:permission).map(&:permission_id) end end |
#description ⇒ String
Returns the description of the permission group.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/permission_group.rb', line 12 class PermissionGroup < ApplicationRecord # Constants for permission group codes class Codes PAYROLL_ADMIN = 'PAYROLL-ADMIN' EMPLOYEE_PORTAL = 'EMPLOYEE-PORTAL' EDI = 'EDI' AI_PLATFORM = 'AI-PLATFORM' end self.table_name = 'PERMISSION_GROUP_HEADER' self.primary_key = 'permission_group_header_id' class << self # Retrieves a list of permission group options. # # @return [ActiveRecord::Relation] a relation of permission groups with selected attributes # @example # PermissionGroup.options def select(:permission_group_header_id, :code, :description) .order(code: :asc) end # Finds the payroll admin permission group. # # @return [PermissionGroup] the payroll admin permission group # @raise [ActiveRecord::RecordNotFound] if the payroll admin permission group is not found # @example # PermissionGroup.payroll_admin def payroll_admin find_by!(code: Codes::PAYROLL_ADMIN) end # Finds the employee portal permission group. # # @return [PermissionGroup] the employee portal permission group # @raise [ActiveRecord::RecordNotFound] if the employee portal permission group is not found # @example # PermissionGroup.employee_portal def employee_portal find_by!(code: Codes::EMPLOYEE_PORTAL) end end # Associations has_and_belongs_to_many( :permissions, join_table: PermissionGroupDetails.table_name, foreign_key: primary_key, association_foreign_key: Permission.primary_key ) has_many( :permission_group_details, foreign_key: 'permission_group_header_id', class_name: 'PermissionGroupDetails', dependent: :destroy ) has_many :user_permission_groups, foreign_key: 'permission_group_header_id' has_many :erp_users, through: :user_permission_groups # Validations validates :code, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true validates :description, presence: true, length: { minimum: 1, maximum: 255 } # Retrieves the IDs of active permissions in the permission group. # # @return [Array<Integer>] an array of active permission IDs # @example # permission_group.active_permission_ids def .includes(:permission).where(active: true).map(&:permission).map(&:permission_id) end end |
#permission_group_header_id ⇒ Integer
Returns the primary key of the permission group.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/permission_group.rb', line 12 class PermissionGroup < ApplicationRecord # Constants for permission group codes class Codes PAYROLL_ADMIN = 'PAYROLL-ADMIN' EMPLOYEE_PORTAL = 'EMPLOYEE-PORTAL' EDI = 'EDI' AI_PLATFORM = 'AI-PLATFORM' end self.table_name = 'PERMISSION_GROUP_HEADER' self.primary_key = 'permission_group_header_id' class << self # Retrieves a list of permission group options. # # @return [ActiveRecord::Relation] a relation of permission groups with selected attributes # @example # PermissionGroup.options def select(:permission_group_header_id, :code, :description) .order(code: :asc) end # Finds the payroll admin permission group. # # @return [PermissionGroup] the payroll admin permission group # @raise [ActiveRecord::RecordNotFound] if the payroll admin permission group is not found # @example # PermissionGroup.payroll_admin def payroll_admin find_by!(code: Codes::PAYROLL_ADMIN) end # Finds the employee portal permission group. # # @return [PermissionGroup] the employee portal permission group # @raise [ActiveRecord::RecordNotFound] if the employee portal permission group is not found # @example # PermissionGroup.employee_portal def employee_portal find_by!(code: Codes::EMPLOYEE_PORTAL) end end # Associations has_and_belongs_to_many( :permissions, join_table: PermissionGroupDetails.table_name, foreign_key: primary_key, association_foreign_key: Permission.primary_key ) has_many( :permission_group_details, foreign_key: 'permission_group_header_id', class_name: 'PermissionGroupDetails', dependent: :destroy ) has_many :user_permission_groups, foreign_key: 'permission_group_header_id' has_many :erp_users, through: :user_permission_groups # Validations validates :code, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true validates :description, presence: true, length: { minimum: 1, maximum: 255 } # Retrieves the IDs of active permissions in the permission group. # # @return [Array<Integer>] an array of active permission IDs # @example # permission_group.active_permission_ids def .includes(:permission).where(active: true).map(&:permission).map(&:permission_id) end end |
Class Method Details
.employee_portal ⇒ PermissionGroup
Finds the employee portal permission group.
51 52 53 |
# File 'app/models/permission_group.rb', line 51 def employee_portal find_by!(code: Codes::EMPLOYEE_PORTAL) end |
.options ⇒ ActiveRecord::Relation
Retrieves a list of permission group options.
30 31 32 33 |
# File 'app/models/permission_group.rb', line 30 def select(:permission_group_header_id, :code, :description) .order(code: :asc) end |
.payroll_admin ⇒ PermissionGroup
Finds the payroll admin permission group.
41 42 43 |
# File 'app/models/permission_group.rb', line 41 def payroll_admin find_by!(code: Codes::PAYROLL_ADMIN) end |
Instance Method Details
#active_permission_ids ⇒ Array<Integer>
Retrieves the IDs of active permissions in the permission group.
86 87 88 |
# File 'app/models/permission_group.rb', line 86 def .includes(:permission).where(active: true).map(&:permission).map(&:permission_id) end |