FIX: purge unactivated users with a message from non-human users
This commit is contained in:
parent
15bb8954de
commit
7550e9ff95
|
@ -1,5 +1,5 @@
|
|||
module Jobs
|
||||
class PurgeUnactived < Jobs::Scheduled
|
||||
class PurgeUnactivated < Jobs::Scheduled
|
||||
every 1.day
|
||||
|
||||
def execute(args)
|
||||
|
|
|
@ -1222,7 +1222,9 @@ class User < ActiveRecord::Base
|
|||
.where(active: false)
|
||||
.where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago)
|
||||
.where("NOT admin AND NOT moderator")
|
||||
.where("NOT EXISTS (SELECT 1 FROM topic_allowed_users WHERE user_id = users.id LIMIT 1)")
|
||||
.where("NOT EXISTS
|
||||
(SELECT 1 FROM topic_allowed_users tu JOIN topics t ON t.id = tu.topic_id AND t.user_id > 0 WHERE tu.user_id = users.id)
|
||||
")
|
||||
.limit(200)
|
||||
.find_each do |user|
|
||||
begin
|
||||
|
|
|
@ -1257,26 +1257,34 @@ describe User do
|
|||
let!(:user) { Fabricate(:user) }
|
||||
let!(:unactivated) { Fabricate(:user, active: false) }
|
||||
let!(:unactivated_old) { Fabricate(:user, active: false, created_at: 1.month.ago) }
|
||||
let!(:unactivated_old_with_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }
|
||||
let!(:unactivated_old_with_system_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }
|
||||
let!(:unactivated_old_with_human_pm) { Fabricate(:user, active: false, created_at: 2.months.ago) }
|
||||
|
||||
before do
|
||||
PostCreator.new(Discourse.system_user,
|
||||
title: "Welcome to our Discourse",
|
||||
raw: "This is a welcome message",
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: [unactivated_old_with_pm.username],
|
||||
target_usernames: [unactivated_old_with_system_pm.username],
|
||||
).create
|
||||
|
||||
PostCreator.new(user,
|
||||
title: "Welcome to our Discourse",
|
||||
raw: "This is a welcome message",
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: [unactivated_old_with_human_pm.username],
|
||||
).create
|
||||
end
|
||||
|
||||
it 'should only remove old, unactivated users' do
|
||||
User.purge_unactivated
|
||||
expect(User.real.all).to match_array([user, unactivated, unactivated_old_with_pm])
|
||||
expect(User.real.all).to match_array([user, unactivated, unactivated_old_with_human_pm])
|
||||
end
|
||||
|
||||
it "does nothing if purge_unactivated_users_grace_period_days is 0" do
|
||||
SiteSetting.purge_unactivated_users_grace_period_days = 0
|
||||
User.purge_unactivated
|
||||
expect(User.real.all).to match_array([user, unactivated, unactivated_old, unactivated_old_with_pm])
|
||||
expect(User.real.all).to match_array([user, unactivated, unactivated_old, unactivated_old_with_system_pm, unactivated_old_with_human_pm])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue