[Fix #888] New UI : Add upload on commentaire form
This commit is contained in:
parent
5775901868
commit
ae5e6653cb
3 changed files with 26 additions and 7 deletions
|
@ -99,7 +99,7 @@ module NewGestionnaire
|
||||||
end
|
end
|
||||||
|
|
||||||
def commentaire_params
|
def commentaire_params
|
||||||
params.require(:commentaire).permit(:body)
|
params.require(:commentaire).permit(:body, :file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def avis_params
|
def avis_params
|
||||||
|
|
|
@ -15,15 +15,21 @@
|
||||||
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
||||||
%span.guest Invité
|
%span.guest Invité
|
||||||
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
|
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
|
||||||
.rich-text
|
%p.rich-text= sanitize(commentaire.body)
|
||||||
= sanitize(commentaire.body)
|
|
||||||
- if file = commentaire.piece_justificative
|
- if commentaire.file.present?
|
||||||
.attachment-link
|
.attachment-link
|
||||||
= link_to file.content_url, class: "button", target: "_blank", title: "Télécharger" do
|
= link_to commentaire.file.url, class: "button", target: "_blank", title: "Télécharger" do
|
||||||
.icon.attachment
|
.icon.attachment
|
||||||
= file.original_filename
|
= commentaire.file_identifier
|
||||||
|
- elsif commentaire.piece_justificative
|
||||||
|
.attachment-link
|
||||||
|
= link_to commentaire.piece_justificative.content_url, class: "button", target: "_blank", title: "Télécharger" do
|
||||||
|
.icon.attachment
|
||||||
|
= commentaire.piece_justificative.original_filename
|
||||||
|
|
||||||
= form_for(Commentaire.new, url: commentaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' }) do |f|
|
= form_for(Commentaire.new, url: commentaire_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' }) do |f|
|
||||||
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
|
||||||
|
= f.file_field :file
|
||||||
.send-wrapper
|
.send-wrapper
|
||||||
= f.submit 'Envoyer', class: 'button send', data: { disable_with: "Envoi..." }
|
= f.submit 'Envoyer', class: 'button send', data: { disable_with: "Envoi..." }
|
||||||
|
|
|
@ -111,12 +111,18 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
|
|
||||||
describe "#create_commentaire" do
|
describe "#create_commentaire" do
|
||||||
let(:saved_commentaire) { dossier.commentaires.first }
|
let(:saved_commentaire) { dossier.commentaires.first }
|
||||||
|
let(:file) { nil }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
||||||
|
|
||||||
post :create_commentaire, params: {
|
post :create_commentaire, params: {
|
||||||
procedure_id: procedure.id,
|
procedure_id: procedure.id,
|
||||||
dossier_id: dossier.id,
|
dossier_id: dossier.id,
|
||||||
commentaire: { body: 'body' }
|
commentaire: {
|
||||||
|
body: 'body',
|
||||||
|
file: file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -125,6 +131,13 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
||||||
it { expect(saved_commentaire.dossier).to eq(dossier) }
|
it { expect(saved_commentaire.dossier).to eq(dossier) }
|
||||||
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
|
it { expect(response).to redirect_to(messagerie_dossier_path(dossier.procedure, dossier)) }
|
||||||
it { expect(gestionnaire.followed_dossiers).to include(dossier) }
|
it { expect(gestionnaire.followed_dossiers).to include(dossier) }
|
||||||
|
it { expect(saved_commentaire.file.present?).to eq(false) }
|
||||||
|
|
||||||
|
context "with a file" do
|
||||||
|
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
|
it { expect(saved_commentaire.file.present?).to eq(true) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#create_avis" do
|
describe "#create_avis" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue