Module: SkillTree::Resource::InstanceMethods
- Defined in:
- lib/skill_tree/resource/instance_methods.rb
Instance Method Summary collapse
- #acl ⇒ Object
- #acl!(value) ⇒ Object
- #acl=(value) ⇒ Object
- #default_permission?(action, role = :user) ⇒ Boolean (also: #has_default_permission?)
- #permissions_for(user) ⇒ Object
Instance Method Details
#acl ⇒ Object
4 5 6 |
# File 'lib/skill_tree/resource/instance_methods.rb', line 4 def acl acl_ownerships.first.acl if acl_ownerships.first end |
#acl!(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/skill_tree/resource/instance_methods.rb', line 17 def acl!(value) new_acl = parse_acl(value) ActiveRecord::Base.transaction do acl_ownerships.destroy_all acl_ownerships.create!(acl: new_acl) end if new_acl != acl end |
#acl=(value) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/skill_tree/resource/instance_methods.rb', line 8 def acl=(value) if acl_ownerships.empty? acl_ownerships.new(acl: value) else fail SkillTree::AclAlreadySet, "#{self.class.name} already has an acl. Use .acl! instead." end end |
#default_permission?(action, role = :user) ⇒ Boolean Also known as: has_default_permission?
33 34 35 36 37 |
# File 'lib/skill_tree/resource/instance_methods.rb', line 33 def (action, role = :user) acls.joins(acl_mappings: [:permission, :role]) .where('"permissions"."name" = ?', action.to_s) .where('"roles"."name" = ?', role.to_s).any? end |
#permissions_for(user) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/skill_tree/resource/instance_methods.rb', line 25 def (user) role = SkillTree::Models::Role.find_for(user, self) SkillTree::Models::Permission.joins( acl_mappings: [:role, :acl]) .where('("roles"."id" = ?)', role) .where('("acls"."id" = ?)', acl) end |