mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FEATURE: auto-delete any hidden posts that stay hidden for more than 30 days
This commit is contained in:
parent
b16e6f8289
commit
69400a802f
13
app/jobs/scheduled/destroy_old_hidden_posts.rb
Normal file
13
app/jobs/scheduled/destroy_old_hidden_posts.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module Jobs
|
||||
|
||||
class DestroyOldHiddenPosts < Jobs::Scheduled
|
||||
every 1.day
|
||||
|
||||
def execute(args)
|
||||
return unless SiteSetting.delete_old_hidden_posts
|
||||
PostDestroyer.destroy_old_hidden_posts
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -404,7 +404,7 @@ class PostAction < ActiveRecord::Base
|
||||
reason = guess_hide_reason(old_flags)
|
||||
end
|
||||
|
||||
Post.where(id: post.id).update_all(["hidden = true, hidden_at = CURRENT_TIMESTAMP, hidden_reason_id = COALESCE(hidden_reason_id, ?)", reason])
|
||||
Post.where(id: post.id).update_all(["hidden = true, hidden_at = ?, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Time.now, reason])
|
||||
Topic.where("id = :topic_id AND NOT EXISTS(SELECT 1 FROM POSTS WHERE topic_id = :topic_id AND NOT hidden)", topic_id: post.topic_id).update_all(visible: false)
|
||||
|
||||
# inform user
|
||||
|
@ -639,6 +639,7 @@ en:
|
||||
description: "A message that will be displayed at the top of all notification emails."
|
||||
|
||||
site_settings:
|
||||
delete_old_hidden_posts: "Auto-delete any hidden posts that stay hidden for more than 30 days."
|
||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||
allow_user_locale: "Allow users to choose their own language interface preference"
|
||||
min_post_length: "Minimum allowed post length in characters"
|
||||
|
@ -379,6 +379,7 @@ posting:
|
||||
autohighlight_all_code:
|
||||
client: true
|
||||
default: false
|
||||
delete_old_hidden_posts: true
|
||||
|
||||
email:
|
||||
email_time_window_mins: 10
|
||||
|
@ -4,6 +4,14 @@
|
||||
#
|
||||
class PostDestroyer
|
||||
|
||||
def self.destroy_old_hidden_posts
|
||||
Post.where(deleted_at: nil)
|
||||
.where("hidden_at < ?", 30.days.ago)
|
||||
.find_each do |post|
|
||||
PostDestroyer.new(Discourse.system_user, post).destroy
|
||||
end
|
||||
end
|
||||
|
||||
def self.destroy_stubs
|
||||
# exclude deleted topics and posts that are actively flagged
|
||||
Post.where(deleted_at: nil, user_deleted: true)
|
||||
|
@ -11,6 +11,44 @@ describe PostDestroyer do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:post) { create_post }
|
||||
|
||||
describe "destroy_old_hidden_posts" do
|
||||
|
||||
it "destroys posts that have been hidden for 30 days" do
|
||||
Fabricate(:admin)
|
||||
|
||||
now = Time.now
|
||||
|
||||
freeze_time(now - 60.days)
|
||||
topic = post.topic
|
||||
reply1 = create_post(topic: topic)
|
||||
|
||||
freeze_time(now - 40.days)
|
||||
reply2 = create_post(topic: topic)
|
||||
PostAction.hide_post!(reply2, PostActionType.types[:off_topic])
|
||||
|
||||
freeze_time(now - 20.days)
|
||||
reply3 = create_post(topic: topic)
|
||||
PostAction.hide_post!(reply3, PostActionType.types[:off_topic])
|
||||
|
||||
freeze_time(now - 10.days)
|
||||
reply4 = create_post(topic: topic)
|
||||
|
||||
freeze_time(now)
|
||||
PostDestroyer.destroy_old_hidden_posts
|
||||
|
||||
reply1.reload
|
||||
reply2.reload
|
||||
reply3.reload
|
||||
reply4.reload
|
||||
|
||||
reply1.deleted_at.should == nil
|
||||
reply2.deleted_at.should_not == nil
|
||||
reply3.deleted_at.should == nil
|
||||
reply4.deleted_at.should == nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'destroy_old_stubs' do
|
||||
it 'destroys stubs for deleted by user posts' do
|
||||
SiteSetting.stubs(:delete_removed_posts_after).returns(24)
|
||||
@ -314,8 +352,8 @@ describe PostDestroyer do
|
||||
|
||||
PostDestroyer.new(moderator, second_post).destroy
|
||||
|
||||
expect(UserAction.find_by(id: bookmark.id)).should == nil
|
||||
expect(UserAction.find_by(id: like.id)).should == nil
|
||||
expect(UserAction.find_by(id: bookmark.id)).to be_nil
|
||||
expect(UserAction.find_by(id: like.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user