Merge pull request #417 from sgmap/fix-388
Improve the avis email links
This commit is contained in:
commit
689a7257f2
7 changed files with 16 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
class Backoffice::DossiersController < Backoffice::DossiersListController
|
class Backoffice::DossiersController < Backoffice::DossiersListController
|
||||||
respond_to :html, :xlsx, :ods, :csv
|
respond_to :html, :xlsx, :ods, :csv
|
||||||
|
|
||||||
|
prepend_before_action :store_current_location, only: :show
|
||||||
before_action :ensure_gestionnaire_is_authorized, only: :show
|
before_action :ensure_gestionnaire_is_authorized, only: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -192,6 +193,12 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def store_current_location
|
||||||
|
if !gestionnaire_signed_in?
|
||||||
|
store_location_for(:gestionnaire, request.url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_gestionnaire_is_authorized
|
def ensure_gestionnaire_is_authorized
|
||||||
unless current_gestionnaire.can_view_dossier?(params[:id])
|
unless current_gestionnaire.can_view_dossier?(params[:id])
|
||||||
flash.alert = t('errors.messages.dossier_not_found')
|
flash.alert = t('errors.messages.dossier_not_found')
|
||||||
|
|
|
@ -33,7 +33,8 @@ class Users::SessionsController < Sessions::SessionsController
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
redirect_to after_sign_in_path_for(:user)
|
redirect_to after_sign_in_path_for(:user)
|
||||||
elsif gestionnaire_signed_in?
|
elsif gestionnaire_signed_in?
|
||||||
redirect_to backoffice_path
|
location = stored_location_for(:gestionnaire) || backoffice_path
|
||||||
|
redirect_to location
|
||||||
elsif administrateur_signed_in?
|
elsif administrateur_signed_in?
|
||||||
redirect_to admin_path
|
redirect_to admin_path
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class AvisMailer < ApplicationMailer
|
class AvisMailer < ApplicationMailer
|
||||||
|
|
||||||
def you_are_invited_on_dossier(avis)
|
def avis_invitation(avis)
|
||||||
@avis = avis
|
@avis = avis
|
||||||
email = @avis.gestionnaire.try(:email) || @avis.email
|
email = @avis.gestionnaire.try(:email) || @avis.email
|
||||||
mail(to: email, subject: "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})")
|
mail(to: email, subject: "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})")
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Avis < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_gestionnaire
|
def notify_gestionnaire
|
||||||
AvisMailer.you_are_invited_on_dossier(self).deliver_now
|
AvisMailer.avis_invitation(self).deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.link_avis_to_gestionnaire(gestionnaire)
|
def self.link_avis_to_gestionnaire(gestionnaire)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
- if @avis.gestionnaire.present?
|
- if @avis.gestionnaire.present?
|
||||||
%p
|
%p
|
||||||
= link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url
|
= link_to "Connectez-vous pour donner votre avis", backoffice_dossier_url(@avis.dossier)
|
||||||
- else
|
- else
|
||||||
%p
|
%p
|
||||||
= link_to "Inscrivez-vous pour donner votre avis", avis_sign_up_url(@avis.id, @avis.email)
|
= link_to "Inscrivez-vous pour donner votre avis", avis_sign_up_url(@avis.id, @avis.email)
|
|
@ -1,10 +1,10 @@
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
RSpec.describe AvisMailer, type: :mailer do
|
RSpec.describe AvisMailer, type: :mailer do
|
||||||
describe '.you_are_invited_on_dossier' do
|
describe '.avis_invitation' do
|
||||||
let(:avis) { create(:avis) }
|
let(:avis) { create(:avis) }
|
||||||
|
|
||||||
subject { described_class.you_are_invited_on_dossier(avis) }
|
subject { described_class.avis_invitation(avis) }
|
||||||
|
|
||||||
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
||||||
it { expect(subject.body).to include("Vous avez été invité par #{avis.claimant.email} à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") }
|
it { expect(subject.body).to include("Vous avez été invité par #{avis.claimant.email} à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Preview all emails at http://localhost:3000/rails/mailers/avis_mailer
|
# Preview all emails at http://localhost:3000/rails/mailers/avis_mailer
|
||||||
class AvisMailerPreview < ActionMailer::Preview
|
class AvisMailerPreview < ActionMailer::Preview
|
||||||
|
|
||||||
def you_are_invited_on_dossier
|
def avis_invitation
|
||||||
AvisMailer.you_are_invited_on_dossier(Avis.last)
|
AvisMailer.avis_invitation(Avis.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue