Merge pull request #2041 from betagouv/fix-1735

Fix #1735
This commit is contained in:
gregoirenovel 2018-06-04 10:12:02 +02:00 committed by GitHub
commit 54c08826d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 11 deletions

View file

@ -14,7 +14,7 @@ module Manager
end end
def reinvite 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" flash.notice = "Invitation renvoyée"
redirect_to manager_administrateur_path(params[:id]) redirect_to manager_administrateur_path(params[:id])
end end

48
app/lib/biz_dev.rb Normal file
View file

@ -0,0 +1,48 @@
module BizDev
BIZ_DEV_MAPPING = {
8 =>
{
full_name: "Camille Garrigue",
pipedrive_id: 3189424
},
9 =>
{
full_name: "Philippe Vrignaud",
pipedrive_id: 2753338
},
10 =>
{
full_name: "Benjamin Doberset",
pipedrive_id: 4223834
},
11 =>
{
full_name: "Rédouane Bouchane",
pipedrive_id: 4438645
}
}
BIZ_DEV_IDS = BIZ_DEV_MAPPING.keys
def full_name(administration_id)
id = ensure_proper_administration_id(administration_id)
BIZ_DEV_MAPPING[id][:full_name]
end
def pipedrive_id(administration_id)
id = ensure_proper_administration_id(administration_id)
BIZ_DEV_MAPPING[id][:pipedrive_id]
end
private
def ensure_proper_administration_id(administration_id)
if administration_id.in?(BIZ_DEV_IDS)
administration_id
else
BIZ_DEV_IDS[administration_id % BIZ_DEV_IDS.length]
end
end
end

View file

@ -10,9 +10,10 @@ class AdministrationMailer < ApplicationMailer
subject: subject) subject: subject)
end end
def invite_admin(admin, reset_password_token) def invite_admin(admin, reset_password_token, administration_id)
@reset_password_token = reset_password_token @reset_password_token = reset_password_token
@admin = admin @admin = admin
@author_name = BizDev.full_name(administration_id)
subject = "Activez votre compte administrateur" subject = "Activez votre compte administrateur"
mail(to: admin.email, mail(to: admin.email,

View file

@ -44,14 +44,14 @@ class Administrateur < ApplicationRecord
end end
end end
def invite! def invite!(administration_id)
if active? if active?
raise "Impossible d'inviter un utilisateur déjà actif !" raise "Impossible d'inviter un utilisateur déjà actif !"
end end
reset_password_token = set_reset_password_token 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 reset_password_token
end end

View file

@ -18,7 +18,7 @@ class Administration < ApplicationRecord
if administrateur.save if administrateur.save
AdministrationMailer.new_admin_email(administrateur, self).deliver_later AdministrationMailer.new_admin_email(administrateur, self).deliver_later
administrateur.invite! administrateur.invite!(id)
User.create({ User.create({
email: email, email: email,
password: password password: password

View file

@ -15,4 +15,4 @@
Nous restons à votre disposition si vous avez besoin daccompagnement. Nous restons à votre disposition si vous avez besoin daccompagnement.
%p %p
= render partial: "layouts/mailers/bizdev_signature" = render partial: "layouts/mailers/bizdev_signature", locals: { author_name: "Camille Garrigue" }

View file

@ -20,4 +20,4 @@
= link_to(DOC_URL, DOC_URL) = link_to(DOC_URL, DOC_URL)
%p %p
= render partial: "layouts/mailers/bizdev_signature" = render partial: "layouts/mailers/bizdev_signature", locals: { author_name: @author_name }

View file

@ -1,7 +1,7 @@
Cordialement, Cordialement,
%br %br
%br %br
Camille Garrigue = author_name
%br %br
%br %br
Équipe demarches-simplifiees.fr Équipe demarches-simplifiees.fr

View file

@ -8,7 +8,7 @@ class AdministrationMailerPreview < ActionMailer::Preview
end end
def invite_admin def invite_admin
AdministrationMailer.invite_admin(Administrateur.last, "12345678") AdministrationMailer.invite_admin(Administrateur.last, "12345678", 0)
end end
def refuse_admin def refuse_admin

View file

@ -1,6 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Administrateur, type: :model do describe Administrateur, type: :model do
let(:administration) { create(:administration) }
describe 'assocations' do describe 'assocations' do
it { is_expected.to have_and_belong_to_many(:gestionnaires) } it { is_expected.to have_and_belong_to_many(:gestionnaires) }
it { is_expected.to have_many(:procedures) } it { is_expected.to have_many(:procedures) }
@ -53,14 +55,14 @@ describe Administrateur, type: :model do
describe '#find_inactive_by_token' do describe '#find_inactive_by_token' do
let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } 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 } it { expect(Administrateur.find_inactive_by_token(reset_password_token)).not_to be_nil }
end end
describe '#reset_password' do describe '#reset_password' do
let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } 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(reset_password_token, '12345678').errors).to be_empty }
it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty } it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty }