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.60.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.59.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.58.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.57.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.56.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.55.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.54.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.53.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.52.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.51.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.50.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.49.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.48.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.45.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.44.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.43.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.42.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.41.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.40.pre app/models/cmor/rbac/user_role.rb
cmor_rbac-0.0.39.pre app/models/cmor/rbac/user_role.rb