Module: CubaApi::Guard
- Defined in:
- lib/cuba_api/guard.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #allowed_associations ⇒ Object
- #current_groups ⇒ Object
- #on_association ⇒ Object
- #on_context(name, &block) ⇒ Object
- #on_guard(method, *args) ⇒ Object
Instance Method Details
#allowed_associations ⇒ Object
51 52 53 |
# File 'lib/cuba_api/guard.rb', line 51 def allowed_associations guard.associations( guard_context, @_method ) end |
#current_groups ⇒ Object
47 48 49 |
# File 'lib/cuba_api/guard.rb', line 47 def current_groups current_user.groups end |
#on_association ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cuba_api/guard.rb', line 72 def on_association on :association do |association| # TODO one method in guard asso = guard.( guard_context ).associations if asso.empty? or asso.include?( association ) yield( association ) else no_body :forbidden end end end |
#on_context(name, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cuba_api/guard.rb', line 55 def on_context( name, &block ) perm = guard.( name ) if perm && perm.parent && perm.parent.resource != guard_context raise 'parent resource is not guarded' end on name do begin old = guard_context guard_context( name ) yield( *captures ) ensure guard_context( old ) end end end |
#on_guard(method, *args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cuba_api/guard.rb', line 84 def on_guard( method, *args) args.insert( 0, send( method ) ) on *args do @_method = method warn "[CubaApi::Guard] check #{method.to_s.upcase} #{guard_context}: #{guard.allow?( guard_context, method )}" # TODO guard needs no association here if guard.allow?( guard_context, method, (allowed_associations || []).first ) yield( *captures ) else no_body :forbidden # 403 end end end |