demarches-normaliennes/app/graphql/mutations/base_mutation.rb
2020-12-10 18:35:24 +01:00

25 lines
847 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
private
def validate_blob(blob_id)
begin
blob = ActiveStorage::Blob.find_signed(blob_id)
blob.identify
true
rescue ActiveStorage::FileNotFoundError
return false, { errors: ['Le fichier na pas été correctement téléversé sur le serveur de stockage'] }
rescue ActiveSupport::MessageVerifier::InvalidSignature
return false, { errors: ['Le hash du fichier téléversé est invalide'] }
end
end
def dossier_authorized_for?(dossier, instructeur)
if instructeur.is_a?(Instructeur) && instructeur.dossiers.exists?(id: dossier.id)
true
else
return false, { errors: ['Linstructeur na pas les droits daccès à ce dossier'] }
end
end
end
end