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.38.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.37.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.36.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.35.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.34.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.33.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.32.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.31.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.30.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.29.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.28.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.27.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.26.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.25.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.24.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.22.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.21.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.20.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.19.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.18.pre app/models/cmor/rbac/user_role.rb