refactor(graphql): extract compute_demarche_authorization

This commit is contained in:
Paul Chavard 2023-03-01 17:47:38 +01:00
parent 42e74dfc76
commit d481222110

View file

@ -49,7 +49,17 @@ 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[: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?
@ -58,9 +68,6 @@ class API::V2::Context < GraphQL::Query::Context
end
end
self[:authorized][demarche.id]
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.