Merge pull request #7905 from mfo/US/clean_pending_user_with_requested_merge_into_id_similar_to_their_id
correctif(fusion de compte): correctif sur les comptes usagers ayant initiés la fusion de leur compte sur lui même [ce qui detruit la donnée]
This commit is contained in:
commit
2f573619d6
3 changed files with 11 additions and 1 deletions
|
@ -214,6 +214,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def merge(old_user)
|
||||
raise "Merging same user, no way" if old_user.id == self.id
|
||||
transaction do
|
||||
old_user.dossiers.update_all(user_id: id)
|
||||
old_user.invites.update_all(user_id: id)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class CleanPendingUserWithRequestedMergeIntoIdSimilarToTheirId < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
User.where('users.id = users.requested_merge_into_id').update_all(requested_merge_into_id: nil)
|
||||
end
|
||||
end
|
|
@ -423,7 +423,11 @@ describe User, type: :model do
|
|||
let(:targeted_user) { create(:user) }
|
||||
|
||||
subject { targeted_user.merge(old_user) }
|
||||
|
||||
context 'merge myself' do
|
||||
it 'fails' do
|
||||
expect { old_user.merge(old_user) }.to raise_error 'Merging same user, no way'
|
||||
end
|
||||
end
|
||||
context 'and the old account has some stuff' do
|
||||
let!(:dossier) { create(:dossier, user: old_user) }
|
||||
let!(:hidden_dossier) { create(:dossier, user: old_user, hidden_by_user_at: 1.hour.ago) }
|
||||
|
|
Loading…
Reference in a new issue