Sha256: fc2759b12720d4cd41889965c413af33ae33868cd14fd54d36c8540f6bbcdbcd

Contents?: true

Size: 932 Bytes

Versions: 11

Compression:

Stored size: 932 Bytes

Contents

class Permission < ApplicationRecord
    # REFERENCES
    has_many :permission_roles, dependent: :destroy, inverse_of: :permission
    has_many :roles, through: :permission_roles, inverse_of: :permissions
    belongs_to :predicate, inverse_of: :permissions
    belongs_to :action, inverse_of: :permissions
    belongs_to :target, inverse_of: :permissions

    # VALIDATIONS
    validates :predicate_id, presence: true, uniqueness: {scope: [:action_id, :target_id]}
    validates :action_id, presence: true
    validates :target_id, presence: true

    def display_name
        pr = (I18n.t "permissions.predicates.#{predicate.name}", default: predicate.name.titleize rescue nil)
        a = (I18n.t "permissions.actions.#{action.name}", default: action.name.titleize rescue nil)
        m = (I18n.t "activerecord.models.#{target.name}", count: 2, default: target.name.titleize rescue nil)
        [ pr, a, m ].join(" ")
    end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
thecore_auth_commons-3.2.2 app/models/permission.rb
thecore_auth_commons-3.2.1 app/models/permission.rb
thecore_auth_commons-3.1.7 app/models/permission.rb
thecore_auth_commons-3.1.5 app/models/permission.rb
thecore_auth_commons-3.1.4 app/models/permission.rb
thecore_auth_commons-3.1.3 app/models/permission.rb
thecore_auth_commons-3.1.2 app/models/permission.rb
thecore_auth_commons-3.1.1 app/models/permission.rb
thecore_auth_commons-3.1.0 app/models/permission.rb
thecore_auth_commons-3.0.13 app/models/permission.rb
thecore_auth_commons-3.0.12 app/models/permission.rb