a user can transfer all its dossier

This commit is contained in:
simon lehericey 2021-09-20 13:14:03 +02:00
parent ba1a898b0c
commit c34476a766
5 changed files with 46 additions and 0 deletions

View file

@ -27,6 +27,12 @@ module Users
redirect_to profil_path
end
def transfer_all_dossiers
DossierTransfer.initiate(next_owner_email, current_user.dossiers)
flash.notice = t('.new_transfer', count: current_user.dossiers.count, email: next_owner_email)
redirect_to profil_path
end
private
def update_email_params
@ -40,5 +46,9 @@ module Users
def redirect_if_instructeur
redirect_to profil_path
end
def next_owner_email
params[:next_owner]
end
end
end

View file

@ -23,6 +23,14 @@
= f.email_field :email, value: nil, placeholder: 'Nouvelle adresse email', required: true
= f.submit "Changer mon adresse", class: 'button primary'
.card
.card-title= t('.transfer_title')
= t('.transfer_explication_html')
= form_tag transfer_all_dossiers_path, class: 'form' do
= email_field_tag :next_owner, nil, required: true
= submit_tag "Transférer tous mes dossiers", class: 'button primary'
- if current_administrateur.present?
.card
.card-title Jeton didentification de lAPI (token)

View file

@ -0,0 +1,11 @@
fr:
users:
profil:
show:
transfer_title: Transferer tous vos dossiers
transfer_explication_html: "<p>Cette fonctionnalité vous permet de changer le propriétaire de tous vos dossiers. C'est généralement utile lors d'un changement de poste ou si vous souhaitez fusionner plusieurs comptes.</p>
<p>Adresse email du destinataire de tous vos dossiers</p>"
transfer_all_dossiers:
new_transfer:
one: "Le transfert d'un dossier à %{email} est en cours"
other: "Le transfert de %{count} dossiers à %{email} est en cours"

View file

@ -276,6 +276,7 @@ Rails.application.routes.draw do
# allow refresh 'renew api token' page
get 'renew-api-token' => redirect('/profil')
patch 'update_email' => 'profil#update_email'
post 'transfer_all_dossiers' => 'profil#transfer_all_dossiers'
end
#

View file

@ -72,4 +72,20 @@ describe Users::ProfilController, type: :controller do
it { expect(response).to redirect_to(profil_path) }
end
end
context 'POST #transfer_all_dossiers' do
let!(:dossiers) { Array.new(3) { create(:dossier, user: user) } }
let(:next_owner) { 'loulou@lou.com' }
let(:created_transfer) { DossierTransfer.first }
before do
post :transfer_all_dossiers, params: { next_owner: next_owner }
end
it "transfer all dossiers" do
expect(created_transfer.email).to eq(next_owner)
expect(created_transfer.dossiers).to eq(dossiers)
expect(flash.notice).to eq("Le transfert de 3 dossiers à #{next_owner} est en cours")
end
end
end