demarches-normaliennes/app/graphql/mutations/base_mutation.rb

29 lines
1 KiB
Ruby
Raw Normal View History

2018-11-20 22:59:13 +01:00
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
2020-12-10 16:23:24 +01:00
private
def validate_blob(blob_id)
2020-12-10 16:23:24 +01:00
begin
blob = ActiveStorage::Blob.find_signed(blob_id)
# open downloads the file and checks its hash
blob.open { |f| }
2020-12-10 16:23:24 +01:00
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: ['Lidentifiant du fichier téléversé est invalide'] }
rescue ActiveStorage::IntegrityError
2020-12-10 16:23:24 +01:00
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
2018-11-20 22:59:13 +01:00
end
end