PiecesJustificativesServices: refactor upload_one!
This commit is contained in:
parent
03e9cd523e
commit
591ed2037e
1 changed files with 10 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue