Sha256: 3ada31d2294e0856f1e0f7a581cce3fe1c05436db0bfc60dc281ef8803588a65

Contents?: true

Size: 930 Bytes

Versions: 57

Compression:

Stored size: 930 Bytes

Contents

module Cmor::Rbac
  class UserRole < ActiveRecord::Base
    # associations
    belongs_to :user, class_name: Cmor::Rbac::Configuration.user_class_name, foreign_key: 'user_id', inverse_of: :user_roles
    belongs_to :role, inverse_of: :user_roles

    if Rails.version >= '5.0.0'
      belongs_to :enabled_role, -> { enabled }, foreign_key: 'role_id', class_name: 'Cmor::Rbac::Role', optional: true
    else
      belongs_to :enabled_role, -> { enabled }, foreign_key: 'role_id', class_name: 'Cmor::Rbac::Role'
    end
    has_many :enabled_role_permissions, through: :enabled_role, source: :user_roles, class_name: 'Cmor::Rbac::RolePermission'
    has_many :enabled_permissions, through: :enabled_role_permissions, class_name: 'Cmor::Rbac::Permission', source: :permission

    # validations
    validates :user, presence: true
    validates :user_id, uniqueness: { scope: :role_id }
    validates :role, presence: true
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
cmor_rbac-0.0.17.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.16.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.15.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.14.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.13.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.12.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.11.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.10.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.9.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.8.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.7.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.6.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.5.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.4.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.3.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.2.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.1.pre app/models/cmor/rbac/user_role.rb