Merge branch 'send_user_notification_when_invite_send_a_message' into develop
This commit is contained in:
commit
e99746639b
9 changed files with 102 additions and 48 deletions
|
@ -42,20 +42,20 @@ class CommentairesController < ApplicationController
|
||||||
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."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
notify_user_with_mail(@commentaire)
|
||||||
|
|
||||||
if is_gestionnaire?
|
if is_gestionnaire?
|
||||||
unless current_gestionnaire.follow? @commentaire.dossier
|
unless current_gestionnaire.follow? @commentaire.dossier
|
||||||
current_gestionnaire.toggle_follow_dossier @commentaire.dossier
|
current_gestionnaire.toggle_follow_dossier @commentaire.dossier
|
||||||
end
|
end
|
||||||
|
|
||||||
NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved
|
|
||||||
|
|
||||||
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
|
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
|
||||||
else
|
else
|
||||||
if current_user.email != @commentaire.dossier.user.email
|
if current_user.email != @commentaire.dossier.user.email
|
||||||
invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
|
invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
|
||||||
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
|
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
|
||||||
else
|
else
|
||||||
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: params['dossier_id'])
|
redirect_to users_dossier_recapitulatif_path(params['dossier_id'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,4 +63,10 @@ class CommentairesController < ApplicationController
|
||||||
def is_gestionnaire?
|
def is_gestionnaire?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def notify_user_with_mail(commentaire)
|
||||||
|
NotificationMailer.new_answer(commentaire.dossier).deliver_now! unless current_user.try(:email) == commentaire.dossier.user.email
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
%div.commentaire
|
|
||||||
.row
|
|
||||||
%div.col-lg-12.col-md-12.col-sm-12.col-xs-12.comment-header
|
|
||||||
= commentaire.header
|
|
||||||
.row
|
|
||||||
%div.col-lg-12.col-md-12.col-sm-12.col-xs-12.content
|
|
||||||
= commentaire.body.html_safe
|
|
||||||
- if file = commentaire.piece_justificative
|
|
||||||
.row
|
|
||||||
%div.col-lg-12.col-md-12.col-sm-12.col-xs-12.file
|
|
||||||
= link_to file.content_url, class: 'link', target: '_blank' do
|
|
||||||
%span.fa.fa-file
|
|
||||||
%div
|
|
||||||
= file.original_filename
|
|
|
@ -7,41 +7,25 @@
|
||||||
MESSAGERIE
|
MESSAGERIE
|
||||||
|
|
||||||
.col-xs-2.count
|
.col-xs-2.count
|
||||||
- message_count = dossier_facade.commentaires.count
|
= pluralize(@facade.commentaires.count, "message")
|
||||||
= (message_count == 1) ? "1 message" : "#{message_count} messages"
|
|
||||||
.alert.alert-info
|
.alert.alert-info
|
||||||
Cette messagerie permet d'échanger entre le demandeur et le service instructeur.
|
Cette messagerie permet d'échanger entre le demandeur et le service instructeur.
|
||||||
.body
|
.body
|
||||||
- if dossier_facade.commentaires.any?
|
- if dossier_facade.commentaires.any?
|
||||||
.commentaires
|
.commentaires
|
||||||
= render partial: 'dossiers/commentaire', collection: dossier_facade.commentaires.object.sort
|
= render partial: 'dossiers/commentaires/commentaire', collection: dossier_facade.commentaires.object.sort
|
||||||
.split-hr
|
.split-hr
|
||||||
#new-commentaire
|
#new-commentaire
|
||||||
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: dossier_facade.dossier.id, champ_id: dossier_facade.champ_id }), class: 'form-inline', method: 'POST', multipart: true) do
|
= render partial: 'dossiers/commentaires/form', locals: { dossier_facade: @facade }
|
||||||
|
|
||||||
%textarea.form-control{id: 'texte_commentaire', class: 'wysihtml5', name: 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', placeholder:"Commentaire"}
|
|
||||||
|
|
||||||
.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'
|
|
||||||
|
|
||||||
.col-md-6
|
|
||||||
%input#save-message.form-control.btn.btn-send{ type: 'submit', value: 'ENVOYER' }
|
|
||||||
|
|
||||||
|
|
||||||
.last-commentaire.clearfix
|
.last-commentaire.clearfix
|
||||||
- if last_comment = dossier_facade.commentaires.first
|
- if last_comment = dossier_facade.commentaires.first
|
||||||
%div
|
%div
|
||||||
DERNIER MESSAGE
|
DERNIER MESSAGE
|
||||||
= render partial: 'dossiers/commentaire', object: last_comment
|
= render partial: 'dossiers/commentaires/commentaire', object: last_comment
|
||||||
-# = "DERNIER MESSAGE (#{last_comment.header})"
|
|
||||||
-# .content
|
|
||||||
-# = last_comment.body.html_safe
|
|
||||||
-# - if file = last_comment.piece_justificative
|
|
||||||
-# .file
|
|
||||||
-# = link_to file.content_url, class: 'link', target: '_blank' do
|
|
||||||
-# %span.fa.fa-file
|
|
||||||
-# = file.original_filename
|
|
||||||
#open-message.new-action
|
#open-message.new-action
|
||||||
ENVOYER UN MESSAGE
|
ENVOYER UN MESSAGE
|
||||||
|
|
11
app/views/dossiers/commentaires/_commentaire.html.haml
Normal file
11
app/views/dossiers/commentaires/_commentaire.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
%div.commentaire
|
||||||
|
.comment-header
|
||||||
|
= commentaire.header
|
||||||
|
.content
|
||||||
|
= commentaire.body.html_safe
|
||||||
|
- if file = commentaire.piece_justificative
|
||||||
|
.file
|
||||||
|
= link_to file.content_url, class: 'link', target: '_blank' do
|
||||||
|
%span.fa.fa-file
|
||||||
|
%div
|
||||||
|
= file.original_filename
|
11
app/views/dossiers/commentaires/_form.html.haml
Normal file
11
app/views/dossiers/commentaires/_form.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: dossier_facade.dossier.id, champ_id: dossier_facade.champ_id }), class: 'form-inline', method: 'POST', multipart: true) do
|
||||||
|
|
||||||
|
%textarea.form-control{id: 'texte_commentaire', class: 'wysihtml5', name: 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', placeholder:"Commentaire"}
|
||||||
|
|
||||||
|
.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'
|
||||||
|
|
||||||
|
.col-md-6
|
||||||
|
%input#save-message.form-control.btn.btn-send{ type: 'submit', value: 'ENVOYER' }
|
|
@ -21,3 +21,7 @@ end
|
||||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
# inflect.acronym 'RESTful'
|
# inflect.acronym 'RESTful'
|
||||||
# end
|
# end
|
||||||
|
ActiveSupport::Inflector.inflections(:fr) do |inflect|
|
||||||
|
inflect.plural(/$/, 's')
|
||||||
|
inflect.plural(/(hib|ch|bij|caill|p|gen|jouj)ou$/i, '\1oux')
|
||||||
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ describe Users::CommentairesController, type: :controller do
|
||||||
context 'création correct d\'un commentaire' do
|
context 'création correct d\'un commentaire' do
|
||||||
subject do
|
subject do
|
||||||
sign_in dossier.user
|
sign_in dossier.user
|
||||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'depuis la page récapitulatif' do
|
it 'depuis la page récapitulatif' do
|
||||||
|
@ -34,12 +34,12 @@ describe Users::CommentairesController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_sers_commentaires_controller_upload_doc'} do
|
context 'when document is upload whith a commentaire', vcr: { cassette_name: 'controllers_sers_commentaires_controller_upload_doc' } do
|
||||||
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
sign_in dossier.user
|
sign_in dossier.user
|
||||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}}
|
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire, piece_justificative: { content: document_upload } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'create a new piece justificative' do
|
it 'create a new piece justificative' do
|
||||||
|
@ -88,7 +88,7 @@ describe Users::CommentairesController, type: :controller do
|
||||||
sign_in dossier.user
|
sign_in dossier.user
|
||||||
dossier.replied!
|
dossier.replied!
|
||||||
|
|
||||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire }
|
||||||
dossier.reload
|
dossier.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,67 @@ describe Users::Dossiers::CommentairesController, type: :controller do
|
||||||
let(:texte_commentaire) { 'Commentaire de test' }
|
let(:texte_commentaire) { 'Commentaire de test' }
|
||||||
|
|
||||||
describe '#POST create' do
|
describe '#POST create' do
|
||||||
|
|
||||||
|
subject {
|
||||||
|
post :create, params:{dossier_id: dossier.id, texte_commentaire: texte_commentaire}
|
||||||
|
dossier.reload
|
||||||
|
}
|
||||||
|
|
||||||
context 'when invite is connected' do
|
context 'when invite is connected' do
|
||||||
let!(:invite) { create(:invite, :with_user, dossier: dossier) }
|
let!(:invite) { create(:invite, :with_user, dossier: dossier) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in invite.user
|
sign_in invite.user
|
||||||
dossier.replied!
|
dossier.replied!
|
||||||
|
|
||||||
post :create, params:{dossier_id: dossier.id, texte_commentaire: texte_commentaire}
|
|
||||||
dossier.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to redirect_to users_dossiers_invite_path(invite.id) }
|
it do
|
||||||
it { expect(dossier.state).to eq 'replied' }
|
subject
|
||||||
|
is_expected.to redirect_to users_dossiers_invite_path(invite.id)
|
||||||
|
expect(dossier.state).to eq 'replied'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should notify user' do
|
||||||
|
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
|
||||||
|
expect(NotificationMailer).to receive(:deliver_now!)
|
||||||
|
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user is connected' do
|
||||||
|
before do
|
||||||
|
sign_in dossier.user
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'do not send a mail to notify user' do
|
||||||
|
expect(NotificationMailer).to_not receive(:new_answer)
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#notify_user_with_mail' do
|
||||||
|
let(:commentaire){create(:commentaire)}
|
||||||
|
|
||||||
|
context 'when usager is writing a commentaire on dossier' do
|
||||||
|
before { sign_in commentaire.dossier.user }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(NotificationMailer).to_not receive(:new_answer)
|
||||||
|
subject.send(:notify_user_with_mail, commentaire)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when anybody else but usager is writing a commentaire' do
|
||||||
|
before { sign_in create(:user, email: 'administrateur@test.fr') }
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
|
||||||
|
expect(NotificationMailer).to receive(:deliver_now!)
|
||||||
|
subject.send(:notify_user_with_mail, commentaire)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,5 +46,9 @@ FactoryGirl.define do
|
||||||
dossier.cerfa << create(:cerfa)
|
dossier.cerfa << create(:cerfa)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :replied do
|
||||||
|
state 'replied'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue