dossier: remove UI for uploading old pieces justificatives

This commit is contained in:
Pierre de La Morinerie 2019-07-24 12:41:56 +00:00
parent 0c4cb3b498
commit 5502f2e42e
5 changed files with 5 additions and 268 deletions

View file

@ -1,38 +1,5 @@
class PiecesJustificativesService
def self.upload!(dossier, user, params)
tpj_contents = dossier.types_de_piece_justificative
.map { |tpj| [tpj, params["piece_justificative_#{tpj.id}"]] }
.select { |_, content| content.present? }
without_virus, with_virus = tpj_contents
.partition { |_, content| ClamavService.safe_file?(content.path) }
errors = with_virus
.map { |_, content| "#{content.original_filename} : virus détecté" }
errors + without_virus
.map { |tpj, content| save_pj(content, dossier, tpj, user) }
.compact()
end
def self.save_pj(content, dossier, tpj, user)
pj = PieceJustificative.new(content: content,
dossier: dossier,
type_de_piece_justificative: tpj,
user: user)
pj.save ? nil : "le fichier #{content.original_filename} (#{pj.libelle.truncate(200)}) n'a pas pu être sauvegardé"
end
def self.missing_pj_error_messages(dossier)
mandatory_pjs = dossier.types_de_piece_justificative.select(&:mandatory)
present_pjs = dossier.pieces_justificatives.map(&:type_de_piece_justificative)
missing_pjs = mandatory_pjs - present_pjs
missing_pjs.map { |pj| "La pièce jointe #{pj.libelle.truncate(200)} doit être fournie." }
end
def self.types_pj_as_types_de_champ(procedure)
def self.types_pj_as_types_de_champ(procedure)
max_order_place = procedure.types_de_champ.pluck(:order_place).compact.max || -1
order_place = max_order_place + 1