[Fix #1479] Avis creation can fail gracefully
This commit is contained in:
parent
ba3b0b4687
commit
247526578c
6 changed files with 41 additions and 12 deletions
|
@ -3,7 +3,7 @@ module NewGestionnaire
|
|||
before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire]
|
||||
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
|
||||
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire, :update]
|
||||
|
||||
A_DONNER_STATUS = 'a-donner'
|
||||
DONNES_STATUS = 'donnes'
|
||||
|
@ -29,12 +29,18 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def instruction
|
||||
@new_avis = Avis.new
|
||||
end
|
||||
|
||||
def update
|
||||
avis.update(avis_params)
|
||||
flash.notice = 'Votre réponse est enregistrée.'
|
||||
redirect_to instruction_gestionnaire_avis_path(avis)
|
||||
if @avis.update(avis_params)
|
||||
flash.notice = 'Votre réponse est enregistrée.'
|
||||
redirect_to instruction_gestionnaire_avis_path(@avis)
|
||||
else
|
||||
flash.now.alert = @avis.errors.full_messages
|
||||
@new_avis = Avis.new
|
||||
render :instruction
|
||||
end
|
||||
end
|
||||
|
||||
def messagerie
|
||||
|
@ -55,8 +61,16 @@ module NewGestionnaire
|
|||
|
||||
def create_avis
|
||||
confidentiel = avis.confidentiel || params[:avis][:confidentiel]
|
||||
Avis.create(create_avis_params.merge(claimant: current_gestionnaire, dossier: avis.dossier, confidentiel: confidentiel))
|
||||
redirect_to instruction_gestionnaire_avis_path(avis)
|
||||
@new_avis = Avis.new(create_avis_params.merge(claimant: current_gestionnaire, dossier: avis.dossier, confidentiel: confidentiel))
|
||||
|
||||
if @new_avis.save
|
||||
flash.notice = "Une demande d'avis a été envoyée à #{@new_avis.email_to_display}"
|
||||
redirect_to instruction_gestionnaire_avis_path(avis)
|
||||
else
|
||||
flash.now.alert = @new_avis.errors.full_messages
|
||||
set_avis_and_dossier
|
||||
render :instruction
|
||||
end
|
||||
end
|
||||
|
||||
def sign_up
|
||||
|
|
|
@ -27,6 +27,7 @@ module NewGestionnaire
|
|||
|
||||
def avis
|
||||
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
|
||||
@avis = Avis.new
|
||||
end
|
||||
|
||||
def personnes_impliquees
|
||||
|
@ -159,8 +160,15 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def create_avis
|
||||
Avis.create(avis_params.merge(claimant: current_gestionnaire, dossier: dossier))
|
||||
redirect_to avis_gestionnaire_dossier_path(procedure, dossier)
|
||||
@avis = Avis.new(avis_params.merge(claimant: current_gestionnaire, dossier: dossier))
|
||||
if @avis.save
|
||||
flash.notice = "Une demande d'avis a été envoyée à #{@avis.email_to_display}"
|
||||
redirect_to avis_gestionnaire_dossier_path(procedure, dossier)
|
||||
else
|
||||
flash.now.alert = @avis.errors.full_messages
|
||||
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
|
||||
render :avis
|
||||
end
|
||||
end
|
||||
|
||||
def update_annotations
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
.send-wrapper
|
||||
= f.submit 'Envoyer votre avis', class: 'button send'
|
||||
|
||||
= render partial: "new_gestionnaire/shared/avis/form", locals: { url: avis_gestionnaire_avis_path(@avis), must_be_confidentiel: @avis.confidentiel? }
|
||||
= render partial: "new_gestionnaire/shared/avis/form", locals: { url: avis_gestionnaire_avis_path(@avis), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis }
|
||||
|
||||
= render partial: 'new_gestionnaire/shared/avis/list', locals: { avis: @dossier.avis_for(current_gestionnaire), avis_seen_at: nil }
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
= render partial: "header", locals: { dossier: @dossier }
|
||||
|
||||
.container
|
||||
= render partial: "new_gestionnaire/shared/avis/form", locals: { url: avis_gestionnaire_dossier_path(@dossier.procedure, @dossier), must_be_confidentiel: false }
|
||||
= render partial: "new_gestionnaire/shared/avis/form", locals: { url: avis_gestionnaire_dossier_path(@dossier.procedure, @dossier), must_be_confidentiel: false, avis: @avis }
|
||||
|
||||
= render partial: 'new_gestionnaire/shared/avis/list', locals: { avis: @dossier.avis, avis_seen_at: @avis_seen_at }
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
%h1.tab-title Inviter une personne à donner son avis
|
||||
%p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier.
|
||||
|
||||
= form_for Avis.new, url: url, html: { class: 'form' } do |f|
|
||||
= form_for avis, url: url, html: { class: 'form' } do |f|
|
||||
= f.email_field :email, placeholder: 'Adresse email', required: true
|
||||
= f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||
.flex.justify-between.align-baseline
|
||||
- if must_be_confidentiel
|
||||
%p.confidentiel.flex
|
||||
|
|
7
config/locales/models/avis/fr.yml
Normal file
7
config/locales/models/avis/fr.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
fr:
|
||||
activerecord:
|
||||
models:
|
||||
avis: 'Avis'
|
||||
attributes:
|
||||
avis:
|
||||
answer: "Réponse"
|
Loading…
Reference in a new issue