Module: Eaco::Resource::ClassMethods
- Defined in:
- lib/eaco/resource.rb
Overview
Singleton methods added to authorized Resources.
Instance Method Summary collapse
- #allows?(action, actor, resource) ⇒ Boolean
-
#permissions ⇒ Object
The permissions defined for each role.
-
#role?(role) ⇒ Boolean
context of this Resource.
-
#role_of(actor_or_designator, resource) ⇒ Symbol
access is granted.
-
#roles ⇒ Object
The defined roles.
-
#roles_priority ⇒ Object
Roles’ priority map keyed by role symbol.
-
#roles_with_labels ⇒ Object
Role labels map keyed by role symbol.
Instance Method Details
#allows?(action, actor, resource) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/eaco/resource.rb', line 55 def allows?(action, actor, resource) return true if actor.is_admin? role = role_of(actor, resource) return false unless role perms = [role] return false unless perms perms.include?(action) end |
#permissions ⇒ Object
The permissions defined for each role.
108 109 |
# File 'lib/eaco/resource.rb', line 108 def end |
#role?(role) ⇒ Boolean
context of this Resource.
39 40 41 |
# File 'lib/eaco/resource.rb', line 39 def role?(role) role.to_sym.in?(roles) end |
#role_of(actor_or_designator, resource) ⇒ Symbol
access is granted.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/eaco/resource.rb', line 74 def role_of(actor_or_designator, resource) designators = if actor_or_designator.is_a?(Eaco::Designator) [actor_or_designator] elsif actor_or_designator.respond_to?(:designators) actor_or_designator.designators else raise Error, " \#{__method__} expects \#{actor_or_designator.inspect}\n to be a Designator or to `respond_to?(:designators)`\n EOF\n end\n\n role_priority = nil\n resource.acl.each do |designator, role|\n if designators.include?(designator)\n priority = roles_priority[role]\n end\n\n if priority && (role_priority.nil? || priority < role_priority)\n role_priority = priority\n break if role_priority == 0\n end\n end\n\n roles[role_priority] if role_priority\nend\n" |
#roles ⇒ Object
The defined roles.
115 116 |
# File 'lib/eaco/resource.rb', line 115 def roles end |
#roles_priority ⇒ Object
Roles’ priority map keyed by role symbol.
122 123 |
# File 'lib/eaco/resource.rb', line 122 def roles_priority end |
#roles_with_labels ⇒ Object
Role labels map keyed by role symbol
129 130 |
# File 'lib/eaco/resource.rb', line 129 def roles_with_labels end |