Module: RightOn::RoleModel

Defined in:
lib/right_on/role_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/right_on/role_model.rb', line 3

def self.included(base)
  base.module_eval 'has_and_belongs_to_many :roles, :class_name => "RightOn::Role"'
  Role.module_eval "has_and_belongs_to_many :#{base.table_name}"
end

Instance Method Details

#has_access_to?(client_type) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/right_on/role_model.rb', line 20

def has_access_to?(client_type)
  has_right?(client_type.right)
end

#has_privileges_of?(other_user) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/right_on/role_model.rb', line 29

def has_privileges_of?(other_user)
  (other_user.rights - rights).empty?
end

#has_right?(right_or_string) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/right_on/role_model.rb', line 24

def has_right?(right_or_string)
  right = right_or_string.is_a?(Right) ? right_or_string : Right.find_by_name(right_or_string)
  rights.include?(right)
end

#rightsObject



12
13
14
15
16
17
18
# File 'lib/right_on/role_model.rb', line 12

def rights
  @rights ||=
    Right
      .select('distinct rights.*')
      .joins(:roles)
      .where('rights_roles.role_id IN (?)', role_ids)
end

#roles_allowed_to_assignObject



8
9
10
# File 'lib/right_on/role_model.rb', line 8

def roles_allowed_to_assign
  Role.accessible_to(self)
end