FIX: Destroy associated user api keys when making a user anonymous. (#11760)
This commit is contained in:
parent
2092152b03
commit
afe6db5f33
|
@ -59,11 +59,12 @@ class UserAnonymizer
|
|||
)
|
||||
end
|
||||
|
||||
@user.user_avatar.try(:destroy)
|
||||
@user.single_sign_on_record.try(:destroy)
|
||||
@user.oauth2_user_infos.try(:destroy_all)
|
||||
@user.user_associated_accounts.try(:destroy_all)
|
||||
@user.api_keys.find_each { |x| x.try(:destroy) }
|
||||
@user.user_avatar&.destroy!
|
||||
@user.single_sign_on_record&.destroy!
|
||||
@user.oauth2_user_infos.destroy_all
|
||||
@user.user_associated_accounts.destroy_all
|
||||
@user.api_keys.destroy_all
|
||||
@user.user_api_keys.destroy_all
|
||||
@user.user_emails.secondary.destroy_all
|
||||
|
||||
@user_history = log_action
|
||||
|
|
|
@ -210,12 +210,23 @@ describe UserAnonymizer do
|
|||
end
|
||||
|
||||
it "removes api key" do
|
||||
ApiKey.create(user_id: user.id)
|
||||
ApiKey.create!(user_id: user.id)
|
||||
|
||||
expect { make_anonymous }.to change { ApiKey.count }.by(-1)
|
||||
|
||||
user.reload
|
||||
expect(user.api_keys).to be_empty
|
||||
end
|
||||
|
||||
it "removes user api key" do
|
||||
user_api_key = Fabricate(:user_api_key, user: user)
|
||||
|
||||
expect { make_anonymous }.to change { UserApiKey.count }.by(-1)
|
||||
|
||||
user.reload
|
||||
expect(user.user_api_keys).to be_empty
|
||||
end
|
||||
|
||||
context "executes job" do
|
||||
before do
|
||||
Jobs.run_immediately!
|
||||
|
|
Loading…
Reference in New Issue