diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index 2c3ef9a9d..e096591ef 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -19,7 +19,7 @@ class Attachment::EditComponent < ApplicationComponent @user_can_destroy = user_can_destroy @user_can_replace = user_can_replace @as_multiple = as_multiple - + @auto_attach_url = auto_attach_url # Adaptation pour la gestion des pièces jointes multiples @attachments = attachments.presence || (kwargs.key?(:attachment) ? [kwargs.delete(:attachment)] : []) @attachments << attached_file.attachment if attached_file.respond_to?(:attachment) && @attachments.empty? diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 8d9435d17..bca75c292 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -30,4 +30,8 @@ class Champs::PieceJustificativeChamp < Champ def blank? piece_justificative_file.blank? end + + def allow_multiple_attachments? + false + end end diff --git a/app/models/champs/titre_identite_champ.rb b/app/models/champs/titre_identite_champ.rb index 05b67e802..88983fa6e 100644 --- a/app/models/champs/titre_identite_champ.rb +++ b/app/models/champs/titre_identite_champ.rb @@ -25,4 +25,8 @@ class Champs::TitreIdentiteChamp < Champ def blank? piece_justificative_file.blank? end + + def allow_multiple_attachments? + false + end end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index cab033348..8c72c29bd 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -7,7 +7,7 @@ class Commentaire < ApplicationRecord validate :messagerie_available?, on: :create, unless: -> { dossier.brouillon? } - has_one_attached :piece_jointe + has_many_attached :piece_jointe validates :body, presence: { message: "ne peut être vide" }, unless: :discarded? @@ -67,12 +67,6 @@ class Commentaire < ApplicationRecord sent_by?(connected_user) && (sent_by_instructeur? || sent_by_expert?) && !discarded? end - def file_url - if piece_jointe.attached? && piece_jointe.virus_scanner.safe? - Rails.application.routes.url_helpers.url_for(piece_jointe) - end - end - def soft_delete! transaction do discard! @@ -80,7 +74,7 @@ class Commentaire < ApplicationRecord update! body: '' end - piece_jointe.purge_later if piece_jointe.attached? + piece_jointe.each(&:purge_later) if piece_jointe.attached? end def flagged_pending_correction? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 334d883a7..3212a4f80 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -54,7 +54,7 @@ class Dossier < ApplicationRecord has_many :prefilled_champs_public, -> { root.public_only.prefilled }, class_name: 'Champ', inverse_of: false has_many :commentaires, inverse_of: :dossier, dependent: :destroy - has_many :preloaded_commentaires, -> { includes(:dossier_correction, piece_jointe_attachment: :blob) }, class_name: 'Commentaire', inverse_of: :dossier + has_many :preloaded_commentaires, -> { includes(:dossier_correction, piece_jointe_attachments: :blob) }, class_name: 'Commentaire', inverse_of: :dossier has_many :invites, dependent: :destroy has_many :follows, -> { active }, inverse_of: :dossier @@ -294,7 +294,7 @@ class Dossier < ApplicationRecord scope :for_api, -> { with_champs .with_annotations - .includes(commentaires: { piece_jointe_attachment: :blob }, + .includes(commentaires: { piece_jointe_attachments: :blob }, justificatif_motivation_attachment: :blob, attestation: [], avis: { piece_justificative_file_attachment: :blob },