FEATURE: add option to delete user associated account on password reset (#27696)

This commit is contained in:
Arpit Jalan 2024-07-04 06:58:00 +05:30 committed by GitHub
parent 72a5389459
commit 947249719a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 0 deletions

View File

@ -901,6 +901,10 @@ class UsersController < ApplicationController
secure_session["password-#{token}"] = nil
secure_session["second-factor-#{token}"] = nil
if SiteSetting.delete_associated_accounts_on_password_reset
@user.user_associated_accounts.destroy_all
end
UserHistory.create!(
target_user: @user,
acting_user: @user,

View File

@ -2369,6 +2369,8 @@ en:
allow_users_to_hide_profile: "Allow users to hide their profile and presence"
hide_user_activity_tab: "Hide the activity tab on user profiles except for Admin and self."
delete_associated_accounts_on_password_reset: "Delete user associated account when user changes the password."
allow_featured_topic_on_user_profiles: "Allow users to feature a link to a topic on their user card and profile."
show_inactive_accounts: "Allow logged in users to browse profiles of inactive accounts."

View File

@ -793,6 +793,8 @@ users:
hide_user_activity_tab:
default: false
client: true
delete_associated_accounts_on_password_reset:
default: false
groups:
enable_group_directory:

View File

@ -304,6 +304,31 @@ RSpec.describe UsersController do
expect(user1.user_option.reload.timezone).to eq("America/Chicago")
end
it "deletes user associated accounts" do
SiteSetting.delete_associated_accounts_on_password_reset = true
UserAssociatedAccount.create(
user_id: user.id,
provider_uid: "example0",
provider_name: "facebook",
)
UserAssociatedAccount.create(
user_id: user1.id,
provider_uid: "example1",
provider_name: "facebook",
)
get "/u/password-reset/#{email_token.token}"
expect do
put "/u/password-reset/#{email_token.token}",
params: {
password: "hg9ow8yhg98oadminlonger",
}
end.to change { UserAssociatedAccount.count }.by(-1)
expect(UserAssociatedAccount.count).to eq(1)
end
it "logs the password change" do
get "/u/password-reset/#{email_token.token}"