module CubaApi::Guard
Public Instance Methods
allowed_associations()
click to toggle source
# File lib/cuba_api/guard.rb, line 62 def allowed_associations guard.associations( guard_context, @_method ) end
current_groups()
click to toggle source
# File lib/cuba_api/guard.rb, line 54 def current_groups if current_user current_user.groups else [] end end
on_association() { |association| ... }
click to toggle source
# File lib/cuba_api/guard.rb, line 85 def on_association on :association do |association| if allowed_associations && allowed_associations.include?( association ) yield( association ) else no_body :forbidden end end end
on_context( name ) { |*captures| ... }
click to toggle source
# File lib/cuba_api/guard.rb, line 66 def on_context( name, &block ) on name do begin guard.check_parent( name, guard_context ) old = guard_context guard_context( name ) yield( *captures ) rescue Ixtlan::UserManagement::GuardException if respond_to?( :authenticated? ) && authenticated? no_body :not_found else no_body :forbidden end ensure guard_context( old ) end end end
on_guard( method, *args) { |*captures| ... }
click to toggle source
# File lib/cuba_api/guard.rb, line 95 def on_guard( method, *args) args.insert( 0, send( method ) ) on *args do @_method = method allowed = allowed( method ) guard_logger.debug { "check #{method.to_s.upcase} #{guard_context}: #{allowed}" } # TODO guard needs no association here if allowed yield( *captures ) else no_body :forbidden # 403 end end end
Private Instance Methods
allowed( method )
click to toggle source
# File lib/cuba_api/guard.rb, line 116 def allowed( method ) if allowed_associations && !allowed_associations.empty? allowed_associations.select do |asso| guard.allow?( guard_context, method, asso ) end.size > 0 else guard.allow?( guard_context, method ) end end
guard()
click to toggle source
# File lib/cuba_api/guard.rb, line 134 def guard self.class.guard.call( current_groups ) end
guard_context( ctx = nil )
click to toggle source
# File lib/cuba_api/guard.rb, line 126 def guard_context( ctx = nil ) if ctx @_context = (req.env[ 'guard_context' ] = ctx) else @_context ||= req.env[ 'guard_context' ] end end
guard_logger()
click to toggle source
# File lib/cuba_api/guard.rb, line 138 def guard_logger self.class.guard_logger end