2016-03-22 17:36:36 +01:00
|
|
|
class PiecesJustificativesService
|
|
|
|
def self.upload! dossier, user, params
|
|
|
|
errors = ''
|
|
|
|
|
|
|
|
dossier.types_de_piece_justificative.each do |type_de_pieces_justificatives|
|
|
|
|
unless params["piece_justificative_#{type_de_pieces_justificatives.id}"].nil?
|
|
|
|
|
2016-04-15 15:32:15 +02:00
|
|
|
if ClamavService.safe_file? params["piece_justificative_#{type_de_pieces_justificatives.id}"].path
|
|
|
|
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
|
|
|
|
dossier: dossier,
|
|
|
|
type_de_piece_justificative: type_de_pieces_justificatives,
|
|
|
|
user: user)
|
2016-04-14 17:29:26 +02:00
|
|
|
|
2016-04-15 15:32:15 +02:00
|
|
|
unless piece_justificative.save
|
|
|
|
errors << piece_justificative.errors.messages[:content][0]+" (#{piece_justificative.libelle})"+"<br>"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
errors << params["piece_justificative_#{type_de_pieces_justificatives.id}"].original_filename+": <b>Virus détecté !!</b>"+"<br>"
|
2016-03-22 17:36:36 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
errors
|
|
|
|
end
|
2016-04-20 16:51:57 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
piece_justificative.save
|
|
|
|
else
|
|
|
|
piece_justificative = PieceJustificative.new
|
|
|
|
piece_justificative.errors.add(:content, params[:piece_justificative][:content].original_filename+": <b>Virus détecté !!</b>")
|
|
|
|
end
|
|
|
|
|
|
|
|
piece_justificative
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|