Module: RightOn::RoleModel
- Defined in:
- lib/right_on/role_model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #has_access_to?(client_type) ⇒ Boolean
- #has_privileges_of?(other_user) ⇒ Boolean
- #has_right?(right_or_string) ⇒ Boolean
- #rights ⇒ Object
- #roles_allowed_to_assign ⇒ Object
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
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
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
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 |
#rights ⇒ Object
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_assign ⇒ Object
8 9 10 |
# File 'lib/right_on/role_model.rb', line 8 def roles_allowed_to_assign Role.accessible_to(self) end |