fix(dossier_correction): don't allow to save with a missing (invalid) commentaire
This commit is contained in:
parent
b495e0aff0
commit
52c8553576
5 changed files with 24 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
= render Dropdown::MenuComponent.new(wrapper: :div, button_options: { class: "fr-btn--secondary" }, wrapper_options: { data: {'turbo-force': true} }, role: :region) do |menu|
|
||||
= render Dropdown::MenuComponent.new(wrapper: :div, menu_options: { id: "menu-en-construction" }, button_options: { class: "fr-btn--secondary" }, role: :region) do |menu|
|
||||
- menu.with_button_inner_html do
|
||||
= menu_label
|
||||
|
||||
|
|
|
@ -232,11 +232,16 @@ module Instructeurs
|
|||
flash.alert = dossier.termine? ? "Impossible de demander de corriger un dossier terminé." : "Le dossier est déjà en attente de correction."
|
||||
else
|
||||
commentaire = CommentaireService.build(current_instructeur, dossier, { body: message, piece_jointe: })
|
||||
dossier.flag_as_pending_correction!(commentaire)
|
||||
dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
current_instructeur.follow(dossier)
|
||||
|
||||
flash.notice = "Dossier marqué comme en attente de correction."
|
||||
if commentaire.valid?
|
||||
dossier.flag_as_pending_correction!(commentaire)
|
||||
dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
current_instructeur.follow(dossier)
|
||||
|
||||
flash.notice = "Dossier marqué comme en attente de correction."
|
||||
else
|
||||
flash.alert = commentaire.errors.full_messages.map { "Commentaire : #{_1}" }
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -7,7 +7,7 @@ module DossierCorrectableConcern
|
|||
def flag_as_pending_correction!(commentaire)
|
||||
return unless may_flag_as_pending_correction?
|
||||
|
||||
corrections.create(commentaire:)
|
||||
corrections.create!(commentaire:)
|
||||
|
||||
return if en_construction?
|
||||
|
||||
|
@ -32,7 +32,7 @@ module DossierCorrectableConcern
|
|||
end
|
||||
|
||||
def resolve_pending_correction!
|
||||
corrections.pending.update(resolved_at: Time.current)
|
||||
corrections.pending.update!(resolved_at: Time.current)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,5 +13,7 @@ class DossierCorrection < ApplicationRecord
|
|||
belongs_to :dossier
|
||||
belongs_to :commentaire
|
||||
|
||||
validates_associated :commentaire
|
||||
|
||||
scope :pending, -> { where(resolved_at: nil) }
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue