This commit is contained in:
Kara Diaby 2024-02-13 07:04:07 +00:00
parent 1e9b7fbbb6
commit bec9af90e8
5 changed files with 13 additions and 11 deletions

View file

@ -19,7 +19,7 @@ class Attachment::EditComponent < ApplicationComponent
@user_can_destroy = user_can_destroy @user_can_destroy = user_can_destroy
@user_can_replace = user_can_replace @user_can_replace = user_can_replace
@as_multiple = as_multiple @as_multiple = as_multiple
@auto_attach_url = auto_attach_url
# Adaptation pour la gestion des pièces jointes multiples # Adaptation pour la gestion des pièces jointes multiples
@attachments = attachments.presence || (kwargs.key?(:attachment) ? [kwargs.delete(:attachment)] : []) @attachments = attachments.presence || (kwargs.key?(:attachment) ? [kwargs.delete(:attachment)] : [])
@attachments << attached_file.attachment if attached_file.respond_to?(:attachment) && @attachments.empty? @attachments << attached_file.attachment if attached_file.respond_to?(:attachment) && @attachments.empty?

View file

@ -30,4 +30,8 @@ class Champs::PieceJustificativeChamp < Champ
def blank? def blank?
piece_justificative_file.blank? piece_justificative_file.blank?
end end
def allow_multiple_attachments?
false
end
end end

View file

@ -25,4 +25,8 @@ class Champs::TitreIdentiteChamp < Champ
def blank? def blank?
piece_justificative_file.blank? piece_justificative_file.blank?
end end
def allow_multiple_attachments?
false
end
end end

View file

@ -7,7 +7,7 @@ class Commentaire < ApplicationRecord
validate :messagerie_available?, on: :create, unless: -> { dossier.brouillon? } 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? 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? sent_by?(connected_user) && (sent_by_instructeur? || sent_by_expert?) && !discarded?
end 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! def soft_delete!
transaction do transaction do
discard! discard!
@ -80,7 +74,7 @@ class Commentaire < ApplicationRecord
update! body: '' update! body: ''
end end
piece_jointe.purge_later if piece_jointe.attached? piece_jointe.each(&:purge_later) if piece_jointe.attached?
end end
def flagged_pending_correction? def flagged_pending_correction?

View file

@ -54,7 +54,7 @@ class Dossier < ApplicationRecord
has_many :prefilled_champs_public, -> { root.public_only.prefilled }, class_name: 'Champ', inverse_of: false 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 :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 :invites, dependent: :destroy
has_many :follows, -> { active }, inverse_of: :dossier has_many :follows, -> { active }, inverse_of: :dossier
@ -294,7 +294,7 @@ class Dossier < ApplicationRecord
scope :for_api, -> { scope :for_api, -> {
with_champs with_champs
.with_annotations .with_annotations
.includes(commentaires: { piece_jointe_attachment: :blob }, .includes(commentaires: { piece_jointe_attachments: :blob },
justificatif_motivation_attachment: :blob, justificatif_motivation_attachment: :blob,
attestation: [], attestation: [],
avis: { piece_justificative_file_attachment: :blob }, avis: { piece_justificative_file_attachment: :blob },