class Patriarch::AuthorizationService
Public Instance Methods
check_types(transac)
click to toggle source
When declaring behaviours in model thanks to add_behaviour helper we enforce that ONLY the declared behaviours are authorized. We hence verify that when a behaviour is called. For example User could be able to like Items and thus be blessed with like as an instance method. But then we can call like upon from any user instance to like any object, this method prevents it. @transac [Patriarch::Transaction] the transaction to be authorized (or not)
# File lib/patriarch/authorization_service.rb, line 23 def check_types(transac) protagonists_models = transac.protagonists_models behaviour = transac.relation_type.to_s.sub(/undo_/,'').underscore.to_sym auths = [] # See register behaviour to see how it is implemented. # TODO Couplage trop grand ici. protagonists_models.each do |protagonist_model| auths << protagonist_model.patriarch_behaviours[behaviour].include?(protagonists_models) end !auths.include?(false) end
grant?(transac)
click to toggle source
All authorization services are called by method grant Since type verification is an eternal we implement grant in the mother class and let daughter classes call it with super and benefit from verify_types or bypass it completely and override the function
# File lib/patriarch/authorization_service.rb, line 14 def grant?(transac) check_types(transac) || raise(Patriarch::ForbiddenBehaviourException, "that behaviour is not authorized") end