refactor(graphql): extract compute_demarche_authorization
This commit is contained in:
parent
42e74dfc76
commit
d481222110
1 changed files with 14 additions and 7 deletions
|
@ -49,18 +49,25 @@ class API::V2::Context < GraphQL::Query::Context
|
|||
self[:authorized] ||= {}
|
||||
|
||||
if self[:authorized][demarche.id].nil?
|
||||
self[:authorized][demarche.id] = if self[:procedure_ids].present?
|
||||
self[:procedure_ids].include?(demarche.id)
|
||||
elsif self[:token].present?
|
||||
APIToken.find_and_verify(self[:token], demarche.administrateurs).present?
|
||||
else
|
||||
false
|
||||
end
|
||||
self[:authorized][demarche.id] = compute_demarche_authorization(demarche)
|
||||
end
|
||||
|
||||
self[:authorized][demarche.id]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compute_demarche_authorization(demarche)
|
||||
# procedure_ids and token are passed from graphql controller
|
||||
if self[:procedure_ids].present?
|
||||
self[:procedure_ids].include?(demarche.id)
|
||||
elsif self[:token].present?
|
||||
APIToken.find_and_verify(self[:token], demarche.administrateurs).present?
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# This is a query AST visitor that we use to check
|
||||
# if a fragment with a given name is used in the given document.
|
||||
# We check for both inline and standalone fragments.
|
||||
|
|
Loading…
Reference in a new issue