Send a mail to usager if somebody else wrote a new commentaire on his dossier
This commit is contained in:
parent
4880101202
commit
c7934b2f97
9 changed files with 87 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -34,3 +34,4 @@ config/fog_credentials.yml
|
|||
uploads/*
|
||||
coverage/**/*
|
||||
.DS_Store
|
||||
.byebug_history
|
||||
|
|
|
@ -42,20 +42,20 @@ class CommentairesController < ApplicationController
|
|||
flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe."
|
||||
end
|
||||
|
||||
notify_user_with_mail(@commentaire)
|
||||
|
||||
if is_gestionnaire?
|
||||
unless current_gestionnaire.follow? @commentaire.dossier
|
||||
current_gestionnaire.toggle_follow_dossier @commentaire.dossier
|
||||
end
|
||||
|
||||
NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved
|
||||
|
||||
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
|
||||
else
|
||||
if current_user.email != @commentaire.dossier.user.email
|
||||
invite = Invite.where(dossier: @commentaire.dossier, email: current_user.email).first
|
||||
redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id)
|
||||
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
|
||||
|
@ -63,4 +63,10 @@ class CommentairesController < ApplicationController
|
|||
def is_gestionnaire?
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notify_user_with_mail(commentaire)
|
||||
NotificationMailer.new_answer(commentaire.dossier).deliver_now! unless current_user.email == commentaire.dossier.user.email
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,23 +10,19 @@
|
|||
- elsif gestionnaire_signed_in?
|
||||
Usager
|
||||
%div.col-lg-2.col-md-2.col-sm-2.col-xs-2.count
|
||||
- message_count = @facade.commentaires.count
|
||||
= (message_count == 1) ? "1 message" : "#{message_count} messages"
|
||||
= pluralize(@facade.commentaires.count, "message")
|
||||
%div.body
|
||||
- unless @facade.commentaires.empty?
|
||||
%div.commentaires
|
||||
- @facade.commentaires.object.sort.each do |commentaire|
|
||||
= render partial: 'dossiers/commentaire', locals: {commentaire: commentaire}
|
||||
= render partial: 'dossiers/commentaires/commentaire', locals: {commentaire: commentaire}
|
||||
.row
|
||||
.col-lg-12.col-md-12.col-sm-12.col-xs-12
|
||||
%div.split-hr
|
||||
.row
|
||||
%div.col-lg-12.col-md-12.col-sm-12.col-xs-12#new-commentaire
|
||||
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: @facade.dossier.id, champ_id: @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"}
|
||||
%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'
|
||||
%input#save-message.form-control.btn.btn-send{ type: 'submit', value: 'ENVOYER' }
|
||||
= render partial: 'dossiers/commentaires/form', locals: { facade: @facade }
|
||||
|
||||
- if last_comment = @facade.commentaires.first
|
||||
%div.last-commentaire
|
||||
.row
|
||||
|
@ -118,4 +114,3 @@
|
|||
= (private_fields_count == 1) ? "1 champ" : "#{private_fields_count} champs"
|
||||
%div.body
|
||||
= render partial: '/dossiers/infos_private_fields'
|
||||
|
||||
|
|
5
app/views/dossiers/commentaires/_form.html.haml
Normal file
5
app/views/dossiers/commentaires/_form.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
|||
= form_tag(url_for({ controller: 'commentaires', action: :create, dossier_id: facade.dossier.id, champ_id: 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"}
|
||||
%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'
|
||||
%input#save-message.form-control.btn.btn-send{ type: 'submit', value: 'ENVOYER' }
|
|
@ -39,9 +39,15 @@ Rails.application.configure do
|
|||
# Raises helpful error messages.
|
||||
config.assets.raise_runtime_errors = true
|
||||
|
||||
config.action_mailer.delivery_method = :test
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
||||
|
||||
config.action_mailer.smtp_settings = {
|
||||
:address => "localhost",
|
||||
:port => 1025,
|
||||
:locale => 'fr'
|
||||
}
|
||||
|
||||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
|
|
|
@ -21,3 +21,7 @@ end
|
|||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
# inflect.acronym 'RESTful'
|
||||
# end
|
||||
ActiveSupport::Inflector.inflections(:fr) do |inflect|
|
||||
inflect.plural(/$/, 's')
|
||||
inflect.plural(/(hib|ch|bij|caill|p|gen|jouj)ou$/i, '\1oux')
|
||||
end
|
||||
|
|
|
@ -5,19 +5,67 @@ describe Users::Dossiers::CommentairesController, type: :controller do
|
|||
let(:texte_commentaire) { 'Commentaire de test' }
|
||||
|
||||
describe '#POST create' do
|
||||
|
||||
subject {
|
||||
post :create, params:{dossier_id: dossier.id, texte_commentaire: texte_commentaire}
|
||||
dossier.reload
|
||||
}
|
||||
|
||||
context 'when invite is connected' do
|
||||
let!(:invite) { create(:invite, :with_user, dossier: dossier) }
|
||||
|
||||
before do
|
||||
sign_in invite.user
|
||||
dossier.replied!
|
||||
|
||||
post :create, params:{dossier_id: dossier.id, texte_commentaire: texte_commentaire}
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to users_dossiers_invite_path(invite.id) }
|
||||
it { expect(dossier.state).to eq 'replied' }
|
||||
it do
|
||||
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
|
||||
|
|
|
@ -46,5 +46,9 @@ FactoryGirl.define do
|
|||
dossier.cerfa << create(:cerfa)
|
||||
end
|
||||
end
|
||||
|
||||
trait :replied do
|
||||
state 'replied'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue