accept or refuse merge
This commit is contained in:
parent
6625c6bac3
commit
652b8367be
4 changed files with 71 additions and 0 deletions
|
@ -3,6 +3,7 @@ module Users
|
||||||
before_action :ensure_update_email_is_authorized, only: :update_email
|
before_action :ensure_update_email_is_authorized, only: :update_email
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@waiting_merge_emails = waiting_merge_emails
|
||||||
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
|
@waiting_transfers = current_user.dossiers.joins(:transfer).group('dossier_transfers.email').count.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,8 +33,32 @@ module Users
|
||||||
redirect_to profil_path
|
redirect_to profil_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accept_merge
|
||||||
|
users_requesting_merge.each { |user| current_user.merge(user) }
|
||||||
|
users_requesting_merge.update_all(requested_merge_into_id: nil)
|
||||||
|
|
||||||
|
flash.notice = "Vous avez absorbé le compte #{waiting_merge_emails.join(', ')}"
|
||||||
|
redirect_to profil_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def refuse_merge
|
||||||
|
users = users_requesting_merge
|
||||||
|
users.update_all(requested_merge_into_id: nil)
|
||||||
|
|
||||||
|
flash.notice = 'La fusion a été refusé'
|
||||||
|
redirect_to profil_path
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def waiting_merge_emails
|
||||||
|
users_requesting_merge.pluck(:email)
|
||||||
|
end
|
||||||
|
|
||||||
|
def users_requesting_merge
|
||||||
|
@requesting_merge ||= User.where(requested_merge_into: current_user)
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_update_email_is_authorized
|
def ensure_update_email_is_authorized
|
||||||
if current_user.instructeur? && !target_email_allowed?
|
if current_user.instructeur? && !target_email_allowed?
|
||||||
flash.alert = t('users.profil.ensure_update_email_is_authorized.email_not_allowed', contact_email: CONTACT_EMAIL, requested_email: requested_email)
|
flash.alert = t('users.profil.ensure_update_email_is_authorized.email_not_allowed', contact_email: CONTACT_EMAIL, requested_email: requested_email)
|
||||||
|
|
|
@ -5,6 +5,16 @@
|
||||||
#profil-page.container
|
#profil-page.container
|
||||||
%h1 Profil
|
%h1 Profil
|
||||||
|
|
||||||
|
- if @waiting_merge_emails.any?
|
||||||
|
.card
|
||||||
|
.card-title Demande de fusion de comptes
|
||||||
|
%p
|
||||||
|
Acceptez-vous d’absorber le compte de
|
||||||
|
%span.email-address= @waiting_merge_emails.join(', ')
|
||||||
|
|
||||||
|
= link_to 'Refuser la fusion', refuse_merge_path, method: :post, class: 'button', data: { confirm: "Confirmez-vous le refus ?" }
|
||||||
|
= link_to 'Accepter la fusion', accept_merge_path, method: :post, class: 'button', data: { confirm: "Confirmez-vous la fusion des comptes ?" }
|
||||||
|
|
||||||
.card
|
.card
|
||||||
.card-title Coordonnées
|
.card-title Coordonnées
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -280,6 +280,8 @@ Rails.application.routes.draw do
|
||||||
get 'renew-api-token' => redirect('/profil')
|
get 'renew-api-token' => redirect('/profil')
|
||||||
patch 'update_email' => 'profil#update_email'
|
patch 'update_email' => 'profil#update_email'
|
||||||
post 'transfer_all_dossiers' => 'profil#transfer_all_dossiers'
|
post 'transfer_all_dossiers' => 'profil#transfer_all_dossiers'
|
||||||
|
post 'accept_merge' => 'profil#accept_merge'
|
||||||
|
post 'refuse_merge' => 'profil#refuse_merge'
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -126,4 +126,38 @@ describe Users::ProfilController, type: :controller do
|
||||||
expect(flash.notice).to eq("Le transfert de 3 dossiers à #{next_owner} est en cours")
|
expect(flash.notice).to eq("Le transfert de 3 dossiers à #{next_owner} est en cours")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'POST #accept_merge' do
|
||||||
|
let!(:requesting_user) { create(:user, requested_merge_into: user) }
|
||||||
|
|
||||||
|
subject { post :accept_merge }
|
||||||
|
|
||||||
|
it 'merges the account' do
|
||||||
|
expect_any_instance_of(User).to receive(:merge)
|
||||||
|
|
||||||
|
subject
|
||||||
|
requesting_user.reload
|
||||||
|
|
||||||
|
expect(requesting_user.requested_merge_into).to be_nil
|
||||||
|
expect(flash.notice).to include('Vous avez absorbé')
|
||||||
|
expect(response).to redirect_to(profil_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'POST #refuse_merge' do
|
||||||
|
let!(:requesting_user) { create(:user, requested_merge_into: user) }
|
||||||
|
|
||||||
|
subject { post :refuse_merge }
|
||||||
|
|
||||||
|
it 'merges the account' do
|
||||||
|
expect_any_instance_of(User).not_to receive(:merge)
|
||||||
|
|
||||||
|
subject
|
||||||
|
requesting_user.reload
|
||||||
|
|
||||||
|
expect(requesting_user.requested_merge_into).to be_nil
|
||||||
|
expect(flash.notice).to include('La fusion a été refusé')
|
||||||
|
expect(response).to redirect_to(profil_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue