A platform for community discussion. Free, open, simple.
FIX: ensures destroying a user with security keys doesn't fail (#9042)
Joffrey JAFFEUXbaba1cc02ec3
diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rbindex abb5b9b3cab..7844496362f 100644--- a/app/services/user_destroyer.rb+++ b/app/services/user_destroyer.rb@@ -27,6 +27,7 @@ class UserDestroyeroptional_transaction(open_transaction: opts[:transaction]) do+ UserSecurityKey.where(user_id: user.id).delete_allDraft.where(user_id: user.id).delete_allReviewable.where(created_by_id: user.id).delete_alldiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex cb79e3856d4..ee1bea598ac 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -2220,6 +2220,16 @@ describe User doendend+ describe "Destroying a user with security key" do+ let!(:security_key) { Fabricate(:user_security_key_with_random_credential, user: user) }+ fab!(:admin) { Fabricate(:admin) }++ it "removes the security key" do+ UserDestroyer.new(admin).destroy(user)+ expect(UserSecurityKey.where(user_id: user.id).count).to eq(0)+ end+ end+describe 'Secure identifier for a user which is a string other than the ID used to identify the user in some cases e.g. security keys' dodescribe '#create_or_fetch_secure_identifier' docontext 'if the user already has a secure identifier' do