From 41e8350cbec116b1aee644d6a57d7ecab3154918 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 18:07:19 +0200 Subject: [PATCH] [Fix #1735] Sign the admin account creation email --- app/controllers/manager/administrateurs_controller.rb | 2 +- app/mailers/administration_mailer.rb | 3 ++- app/models/administrateur.rb | 4 ++-- app/models/administration.rb | 2 +- app/views/administration_mailer/invite_admin.html.haml | 2 +- spec/mailers/previews/administration_mailer_preview.rb | 2 +- spec/models/administrateur_spec.rb | 6 ++++-- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/manager/administrateurs_controller.rb b/app/controllers/manager/administrateurs_controller.rb index 0b5cb39b3..3f0a63438 100644 --- a/app/controllers/manager/administrateurs_controller.rb +++ b/app/controllers/manager/administrateurs_controller.rb @@ -14,7 +14,7 @@ module Manager end def reinvite - Administrateur.find_inactive_by_id(params[:id]).invite! + Administrateur.find_inactive_by_id(params[:id]).invite!(current_administration.id) flash.notice = "Invitation renvoyée" redirect_to manager_administrateur_path(params[:id]) end diff --git a/app/mailers/administration_mailer.rb b/app/mailers/administration_mailer.rb index cbba1eb39..1c3442263 100644 --- a/app/mailers/administration_mailer.rb +++ b/app/mailers/administration_mailer.rb @@ -10,9 +10,10 @@ class AdministrationMailer < ApplicationMailer subject: subject) end - def invite_admin(admin, reset_password_token) + def invite_admin(admin, reset_password_token, administration_id) @reset_password_token = reset_password_token @admin = admin + @author_name = BizDev.full_name(administration_id) subject = "Activez votre compte administrateur" mail(to: admin.email, diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index e4fd48ca8..37242cb4b 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -44,14 +44,14 @@ class Administrateur < ApplicationRecord end end - def invite! + def invite!(administration_id) if active? raise "Impossible d'inviter un utilisateur déjà actif !" end reset_password_token = set_reset_password_token - AdministrationMailer.invite_admin(self, reset_password_token).deliver_later + AdministrationMailer.invite_admin(self, reset_password_token, administration_id).deliver_later reset_password_token end diff --git a/app/models/administration.rb b/app/models/administration.rb index 2428749f3..75b83697c 100644 --- a/app/models/administration.rb +++ b/app/models/administration.rb @@ -18,7 +18,7 @@ class Administration < ApplicationRecord if administrateur.save AdministrationMailer.new_admin_email(administrateur, self).deliver_later - administrateur.invite! + administrateur.invite!(id) User.create({ email: email, password: password diff --git a/app/views/administration_mailer/invite_admin.html.haml b/app/views/administration_mailer/invite_admin.html.haml index 3fb77f3a3..1b0c515cf 100644 --- a/app/views/administration_mailer/invite_admin.html.haml +++ b/app/views/administration_mailer/invite_admin.html.haml @@ -20,4 +20,4 @@ = link_to(DOC_URL, DOC_URL) %p - = render partial: "layouts/mailers/bizdev_signature", locals: { author_name: "Camille Garrigue" } + = render partial: "layouts/mailers/bizdev_signature", locals: { author_name: @author_name } diff --git a/spec/mailers/previews/administration_mailer_preview.rb b/spec/mailers/previews/administration_mailer_preview.rb index a74761967..7e5633c31 100644 --- a/spec/mailers/previews/administration_mailer_preview.rb +++ b/spec/mailers/previews/administration_mailer_preview.rb @@ -8,7 +8,7 @@ class AdministrationMailerPreview < ActionMailer::Preview end def invite_admin - AdministrationMailer.invite_admin(Administrateur.last, "12345678") + AdministrationMailer.invite_admin(Administrateur.last, "12345678", 0) end def refuse_admin diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index cba312218..46eb0d920 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Administrateur, type: :model do + let(:administration) { create(:administration) } + describe 'assocations' do it { is_expected.to have_and_belong_to_many(:gestionnaires) } it { is_expected.to have_many(:procedures) } @@ -53,14 +55,14 @@ describe Administrateur, type: :model do describe '#find_inactive_by_token' do let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } - let(:reset_password_token) { administrateur.invite! } + let(:reset_password_token) { administrateur.invite!(administration.id) } it { expect(Administrateur.find_inactive_by_token(reset_password_token)).not_to be_nil } end describe '#reset_password' do let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } - let(:reset_password_token) { administrateur.invite! } + let(:reset_password_token) { administrateur.invite!(administration.id) } it { expect(Administrateur.reset_password(reset_password_token, '12345678').errors).to be_empty } it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty }