Old UI : Plug messagerie on new commentaire file system

This commit is contained in:
Mathieu Magnin 2017-10-31 17:45:04 +01:00
parent eae16f7746
commit fa95c312ff
5 changed files with 18 additions and 60 deletions

View file

@ -26,21 +26,13 @@ class CommentairesController < ApplicationController
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
end
unless params[:piece_justificative].nil?
pj = PiecesJustificativesService.upload_one! @commentaire.dossier, current_user, params
if pj.errors.empty?
@commentaire.piece_justificative = pj
else
flash.alert = pj.errors.full_messages
end
end
@commentaire.file = params["file"]
@commentaire.body = params['texte_commentaire']
unless @commentaire.body.blank? && @commentaire.piece_justificative.nil?
@commentaire.save unless flash.alert
if @commentaire.save
flash.notice = "Votre message a été envoyé"
else
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe (maximum 20 Mo)"
end
if is_gestionnaire?

View file

@ -3,7 +3,13 @@
= commentaire.header
.content
= sanitize(commentaire.body)
- if file = commentaire.piece_justificative
- if commentaire.file.present?
.file
= link_to commentaire.file_url, class: 'link', target: '_blank' do
%span.fa.fa-file
%div
= commentaire.file_identifier
- elsif file = commentaire.piece_justificative
.file
= link_to file.content_url, class: 'link', target: '_blank' do
%span.fa.fa-file

View file

@ -5,6 +5,6 @@
.row
.col-md-6
%h4.text-primary{ style: 'margin-top: 0px;' } Ajouter un fichier
= file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px;'
= file_field_tag "file", accept: Commentaire.new.file.accept_extension_list, style: 'float: left; margin-left: 20px;'
.col-md-6.text-right
= submit_tag 'Envoyer', id: 'save-message', class: 'form-control btn btn-danger', data: { disable_with: 'Envoi...' }

View file

@ -65,11 +65,7 @@ describe Backoffice::CommentairesController, type: :controller do
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
subject do
post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}}
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
post :create, params: { dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
@ -81,22 +77,6 @@ describe Backoffice::CommentairesController, type: :controller do
expect { subject }.to change(Notification, :count).by (1)
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
@ -105,8 +85,8 @@ describe Backoffice::CommentairesController, type: :controller do
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
expect(commentaire.file.present?).to eq true
expect(commentaire.file.class).to eq(CommentaireFileUploader)
end
end
end

View file

@ -61,11 +61,7 @@ describe Users::CommentairesController, type: :controller do
subject do
sign_in dossier.user
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: { content: document_upload } }
end
it 'create a new piece justificative' do
expect { subject }.to change(PieceJustificative, :count).by(1)
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, file: document_upload }
end
it 'clamav check the pj' do
@ -73,22 +69,6 @@ describe Users::CommentairesController, type: :controller do
subject
end
describe 'piece justificative created' do
let(:pj) { PieceJustificative.last }
before do
subject
end
it 'not have a type de pj' do
expect(pj.type_de_piece_justificative).to be_nil
end
it 'content not be nil' do
expect(pj.content).not_to be_nil
end
end
describe 'commentaire created' do
let(:commentaire) { Commentaire.last }
@ -97,8 +77,8 @@ describe Users::CommentairesController, type: :controller do
end
it 'have a piece justificative reference' do
expect(commentaire.piece_justificative).not_to be_nil
expect(commentaire.piece_justificative).to eq PieceJustificative.last
expect(commentaire.file.present?).to be true
expect(commentaire.file.class).to eq CommentaireFileUploader
end
end
end