New UI : Regular messagerie and avis messagerie should use same partials
This commit is contained in:
parent
886d278d77
commit
eae16f7746
3 changed files with 50 additions and 27 deletions
|
@ -2,6 +2,8 @@ module NewGestionnaire
|
|||
class AvisController < ApplicationController
|
||||
layout 'new_application'
|
||||
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
|
||||
|
||||
A_DONNER_STATUS = 'a-donner'
|
||||
DONNES_STATUS = 'donnes'
|
||||
|
||||
|
@ -23,13 +25,9 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def show
|
||||
@avis = avis
|
||||
@dossier = avis.dossier
|
||||
end
|
||||
|
||||
def instruction
|
||||
@avis = avis
|
||||
@dossier = avis.dossier
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -39,13 +37,19 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def messagerie
|
||||
@avis = avis
|
||||
@dossier = avis.dossier
|
||||
@commentaire = Commentaire.new
|
||||
end
|
||||
|
||||
def create_commentaire
|
||||
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
|
||||
redirect_to messagerie_avis_path(avis)
|
||||
@commentaire = Commentaire.new(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
|
||||
|
||||
if @commentaire.save
|
||||
flash.notice = "Message envoyé"
|
||||
redirect_to messagerie_avis_path(avis)
|
||||
else
|
||||
flash.alert = @commentaire.errors.full_messages
|
||||
render :messagerie
|
||||
end
|
||||
end
|
||||
|
||||
def create_avis
|
||||
|
@ -56,6 +60,11 @@ module NewGestionnaire
|
|||
|
||||
private
|
||||
|
||||
def set_avis_and_dossier
|
||||
@avis = avis
|
||||
@dossier = avis.dossier
|
||||
end
|
||||
|
||||
def avis
|
||||
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
||||
end
|
||||
|
@ -65,7 +74,7 @@ module NewGestionnaire
|
|||
end
|
||||
|
||||
def commentaire_params
|
||||
params.require(:commentaire).permit(:body)
|
||||
params.require(:commentaire).permit(:body, :file)
|
||||
end
|
||||
|
||||
def create_avis_params
|
||||
|
|
|
@ -3,21 +3,9 @@
|
|||
= render partial: 'header', locals: { avis: @avis, dossier: @dossier }
|
||||
|
||||
.messagerie.container
|
||||
%ul
|
||||
%ul.messages-list
|
||||
- @dossier.commentaires.each do |commentaire|
|
||||
%li
|
||||
= render partial: 'new_gestionnaire/dossiers/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
|
||||
= render partial: "new_gestionnaire/shared/commentaires/commentaire", locals: { commentaire: commentaire }
|
||||
|
||||
.width-100
|
||||
%h2
|
||||
%span.mail
|
||||
= render partial: 'new_gestionnaire/dossiers/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
|
||||
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
||||
%span.guest Invité
|
||||
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
|
||||
%p= sanitize(commentaire.body)
|
||||
|
||||
= form_for(Commentaire.new, url: commentaire_avis_path(@avis), html: { class: 'form' }) do |f|
|
||||
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
|
||||
.send-wrapper
|
||||
= f.submit 'Envoyer', class: 'button send'
|
||||
= render partial: "new_gestionnaire/shared/commentaires/form", locals: { commentaire: @commentaire, form_url: commentaire_avis_path(@avis) }
|
||||
|
|
|
@ -63,12 +63,38 @@ describe NewGestionnaire::AvisController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#create_commentaire' do
|
||||
let(:file) { nil }
|
||||
let(:scan_result) { true }
|
||||
|
||||
subject { post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body', file: file } } }
|
||||
|
||||
before do
|
||||
post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body' } }
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||
end
|
||||
|
||||
it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) }
|
||||
it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) }
|
||||
it do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to(messagerie_avis_path(avis_without_answer))
|
||||
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
|
||||
end
|
||||
|
||||
context "with a file" do
|
||||
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||
|
||||
it do
|
||||
subject
|
||||
expect(Commentaire.last.file.path).to include("piece_justificative_0.pdf")
|
||||
end
|
||||
|
||||
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
||||
|
||||
context "and a virus" do
|
||||
let(:scan_result) { false }
|
||||
|
||||
it { expect { subject }.not_to change(Commentaire, :count) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create_avis' do
|
||||
|
|
Loading…
Reference in a new issue