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
|
module Jobs
|
||||||
class PurgeUnactived < Jobs::Scheduled
|
class PurgeUnactivated < Jobs::Scheduled
|
||||||
every 1.day
|
every 1.day
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
|
|
|
@ -1222,7 +1222,9 @@ class User < ActiveRecord::Base
|
||||||
.where(active: false)
|
.where(active: false)
|
||||||
.where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago)
|
.where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago)
|
||||||
.where("NOT admin AND NOT moderator")
|
.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)
|
.limit(200)
|
||||||
.find_each do |user|
|
.find_each do |user|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -1257,26 +1257,34 @@ describe User do
|
||||||
let!(:user) { Fabricate(:user) }
|
let!(:user) { Fabricate(:user) }
|
||||||
let!(:unactivated) { Fabricate(:user, active: false) }
|
let!(:unactivated) { Fabricate(:user, active: false) }
|
||||||
let!(:unactivated_old) { Fabricate(:user, active: false, created_at: 1.month.ago) }
|
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
|
before do
|
||||||
PostCreator.new(Discourse.system_user,
|
PostCreator.new(Discourse.system_user,
|
||||||
title: "Welcome to our Discourse",
|
title: "Welcome to our Discourse",
|
||||||
raw: "This is a welcome message",
|
raw: "This is a welcome message",
|
||||||
archetype: Archetype.private_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
|
).create
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should only remove old, unactivated users' do
|
it 'should only remove old, unactivated users' do
|
||||||
User.purge_unactivated
|
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
|
end
|
||||||
|
|
||||||
it "does nothing if purge_unactivated_users_grace_period_days is 0" do
|
it "does nothing if purge_unactivated_users_grace_period_days is 0" do
|
||||||
SiteSetting.purge_unactivated_users_grace_period_days = 0
|
SiteSetting.purge_unactivated_users_grace_period_days = 0
|
||||||
User.purge_unactivated
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue