PiecesJustificativesServices: refactor upload_one!

This commit is contained in:
Simon Lehericey 2017-03-29 21:58:26 +02:00
parent 03e9cd523e
commit 591ed2037e

View file

@ -19,19 +19,20 @@ class PiecesJustificativesService
end
def self.upload_one! dossier, user, params
if ClamavService.safe_file? params[:piece_justificative][:content].path
piece_justificative = PieceJustificative.new(content: params[:piece_justificative][:content],
dossier: dossier,
type_de_piece_justificative: nil,
user: user)
content = params[:piece_justificative][:content]
if ClamavService.safe_file? content.path
pj = PieceJustificative.new(content: content,
dossier: dossier,
type_de_piece_justificative: nil,
user: user)
piece_justificative.save
pj.save
else
piece_justificative = PieceJustificative.new
piece_justificative.errors.add(:content, params[:piece_justificative][:content].original_filename+": <b>Virus détecté !!</b>")
pj = PieceJustificative.new
pj.errors.add(:content, content.original_filename + ': <b>Virus détecté !!</b>')
end
piece_justificative
pj
end
def self.save_pj(content, dossier, tpj, user)