Sha256: 9972d6348e64fea18b4b89eb1bdac343f4e53fab227479515d51f4ce77063532

Contents?: true

Size: 825 Bytes

Versions: 6

Compression:

Stored size: 825 Bytes

Contents

module Ecm::Rbac
  class UserRole < ActiveRecord::Base
    # associations
    belongs_to :user, class_name: Ecm::Rbac::Configuration.user_class, foreign_key: 'user_id', inverse_of: :user_roles
    # belongs_to :enabled_user, foreign_key: 'user_id', class_name: 'User'
    belongs_to :role, inverse_of: :user_roles

    belongs_to :enabled_role, -> { enabled }, foreign_key: 'role_id', class_name: 'Ecm::Rbac::Role'
    has_many :enabled_role_permissions, through: :enabled_role, source: :user_roles, class_name: 'Ecm::Rbac::RolePermission'
    has_many :enabled_permissions, through: :enabled_role_permissions, class_name: 'Ecm::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

6 entries across 6 versions & 1 rubygems

Version Path
ecm_rbac-0.0.10 app/models/ecm/rbac/user_role.rb
ecm_rbac-0.0.9 app/models/ecm/rbac/user_role.rb
ecm_rbac-0.0.8 app/models/ecm/rbac/user_role.rb
ecm_rbac-0.0.4 app/models/ecm/rbac/user_role.rb
ecm_rbac-0.0.3 app/models/ecm/rbac/user_role.rb
ecm_rbac-0.0.2 app/models/ecm/rbac/user_role.rb