FEATURE: ignore manually deactivated users when purging (#26478)

When a user is manually deactivated, they should not be deleted by our background job that purges inactive users.

In addition, site settings keywords should accept an array of keywords.
This commit is contained in:
Krzysztof Kotlarek 2024-04-03 14:06:31 +11:00 committed by GitHub
parent 477a67e4fb
commit ba04fc6a01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 9 deletions

View File

@ -78,10 +78,12 @@ export default class SiteSettingFilter {
setting.includes(filter) ||
setting.replace(/_/g, " ").includes(filter) ||
item.get("description").toLowerCase().includes(filter) ||
(item.get("keywords") || "")
.replace(/_/g, " ")
.toLowerCase()
.includes(filter.replace(/_/g, " ")) ||
(item.get("keywords") || []).any((keyword) =>
keyword
.replace(/_/g, " ")
.toLowerCase()
.includes(filter.replace(/_/g, " "))
) ||
(item.get("value") || "").toString().toLowerCase().includes(filter);
if (!filterResult && fuzzyRegex && fuzzyRegex.test(setting)) {
// Tightens up fuzzy search results a bit.

View File

@ -21,7 +21,7 @@ export default {
preview: null,
secret: false,
type: "username",
keywords: "blah blah",
keywords: ["blah blah"],
},
{
setting: "logo",

View File

@ -2023,8 +2023,11 @@ class User < ActiveRecord::Base
destroyer = UserDestroyer.new(Discourse.system_user)
User
.joins(
"LEFT JOIN user_histories ON user_histories.target_user_id = users.id AND action = #{UserHistory.actions[:deactivate_user]} AND acting_user_id > 0",
)
.where(active: false)
.where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago)
.where("users.created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago)
.where("NOT admin AND NOT moderator")
.where(
"NOT EXISTS
@ -2036,6 +2039,7 @@ class User < ActiveRecord::Base
(SELECT 1 FROM posts p WHERE p.user_id = users.id LIMIT 1)
",
)
.where("user_histories.id IS NULL")
.limit(200)
.find_each do |user|
begin

View File

@ -2673,6 +2673,14 @@ en:
user_api_key_allowed_groups: "min_trust_level_for_user_api_key"
tag_topic_allowed_groups: "min_trust_level_to_tag_topics"
profile_background_allowed_groups: "min_trust_level_to_allow_profile_background"
clean_up_inactive_users_after_days:
- "deactivated"
- "inactive"
- "unactivated"
purge_unactivated_users_grace_period_days:
- "deactivated"
- "inactive"
- "unactivated"
placeholder:
discourse_connect_provider_secrets:

View File

@ -260,7 +260,7 @@ module SiteSettingExtension
end
def keywords(setting)
I18n.t("site_settings.keywords.#{setting}", default: "")
Array.wrap(I18n.t("site_settings.keywords.#{setting}", default: ""))
end
def placeholder(setting)

View File

@ -1794,6 +1794,7 @@ RSpec.describe User do
describe "#purge_unactivated" do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:admin) { Fabricate(:user) }
fab!(:unactivated) { Fabricate(:user, active: false) }
fab!(:unactivated_old) { Fabricate(:user, active: false, created_at: 1.month.ago) }
fab!(:unactivated_old_with_system_pm) do
@ -1805,6 +1806,12 @@ RSpec.describe User do
fab!(:unactivated_old_with_post) do
Fabricate(:user, active: false, created_at: 1.month.ago, refresh_auto_groups: true)
end
fab!(:unactivated_by_admin) do
Fabricate(:user, active: false, created_at: 1.month.ago, refresh_auto_groups: true)
end
fab!(:unactivated_by_system) do
Fabricate(:user, active: false, created_at: 1.month.ago, refresh_auto_groups: true)
end
before do
PostCreator.new(
@ -1828,12 +1835,30 @@ RSpec.describe User do
title: "Test topic from a user",
raw: "This is a sample message",
).create
UserHistory.create!(
action: UserHistory.actions[:deactivate_user],
acting_user: admin,
target_user: unactivated_by_admin,
)
UserHistory.create!(
action: UserHistory.actions[:deactivate_user],
acting_user: Discourse.system_user,
target_user: unactivated_by_system,
)
end
it "should only remove old, unactivated users" do
it "should only remove old, unactivated users that haven't been manually deactivated" do
User.purge_unactivated
expect(User.real.all).to match_array(
[user, unactivated, unactivated_old_with_human_pm, unactivated_old_with_post],
[
user,
unactivated,
unactivated_old_with_human_pm,
unactivated_old_with_post,
unactivated_by_admin,
admin,
],
)
end
@ -1848,6 +1873,9 @@ RSpec.describe User do
unactivated_old_with_system_pm,
unactivated_old_with_human_pm,
unactivated_old_with_post,
unactivated_by_admin,
unactivated_by_system,
admin,
],
)
end

View File

@ -33,6 +33,13 @@ describe "Admin Site Setting Search", type: :system do
expect(settings_page).to have_search_result("anonymous_posting_allowed_groups")
end
it "finds the associated site setting when many keywords" do
settings_page.visit
settings_page.type_in_search("deactivated")
expect(settings_page).to have_search_result("clean_up_inactive_users_after_days")
expect(settings_page).to have_search_result("purge_unactivated_users_grace_period_days")
end
it "can search for previous site setting without underscores" do
settings_page.visit
settings_page.type_in_search("anonymous posting min")