Sha256: eefbed840571e422b047c15548288c82051d3a7c5bb584b0bf9911303d590fb2
Contents?: true
Size: 1.85 KB
Versions: 3
Compression:
Stored size: 1.85 KB
Contents
module Authz # Represents a real-life process of the business. # For example, a newspaper might have "publish reports" and "write reports" processes. class BusinessProcess < self::ApplicationRecord # Validations # ========================================================================== validates :code, presence: true, uniqueness: true, format: { with: /\A[a-z][a-z0-9]*(_[a-z0-9]+)*\z/, message: 'only snake_case allowed' } validates :name, presence: true, uniqueness: true validates :description, presence: true # Callbacks # ========================================================================== before_validation :extract_code_from_name, on: [:create] after_touch :touch_roles after_update :touch_roles # Associations # ========================================================================== has_many :business_process_has_controller_actions, class_name: 'Authz::BusinessProcessHasControllerAction', foreign_key: 'authz_business_process_id', inverse_of: :business_process, dependent: :destroy has_many :controller_actions, through: :business_process_has_controller_actions, dependent: :destroy has_many :role_has_business_processes, class_name: 'Authz::RoleHasBusinessProcess', foreign_key: 'authz_business_process_id', inverse_of: :business_process, dependent: :destroy has_many :roles, through: :role_has_business_processes, dependent: :destroy has_many :role_grants, through: :roles private def extract_code_from_name self.code = name.parameterize(separator: '_') if name.present? end def touch_roles roles.update_all(updated_at: Time.now) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
authz-0.0.5 | app/models/authz/business_process.rb |
authz-0.0.4 | app/models/authz/business_process.rb |
authz-0.0.3 | app/models/authz/business_process.rb |