mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -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)
|
reason = guess_hide_reason(old_flags)
|
||||||
end
|
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)
|
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
|
# inform user
|
||||||
|
@ -639,6 +639,7 @@ en:
|
|||||||
description: "A message that will be displayed at the top of all notification emails."
|
description: "A message that will be displayed at the top of all notification emails."
|
||||||
|
|
||||||
site_settings:
|
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)"
|
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"
|
allow_user_locale: "Allow users to choose their own language interface preference"
|
||||||
min_post_length: "Minimum allowed post length in characters"
|
min_post_length: "Minimum allowed post length in characters"
|
||||||
|
@ -379,6 +379,7 @@ posting:
|
|||||||
autohighlight_all_code:
|
autohighlight_all_code:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
delete_old_hidden_posts: true
|
||||||
|
|
||||||
email:
|
email:
|
||||||
email_time_window_mins: 10
|
email_time_window_mins: 10
|
||||||
|
@ -4,6 +4,14 @@
|
|||||||
#
|
#
|
||||||
class PostDestroyer
|
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
|
def self.destroy_stubs
|
||||||
# exclude deleted topics and posts that are actively flagged
|
# exclude deleted topics and posts that are actively flagged
|
||||||
Post.where(deleted_at: nil, user_deleted: true)
|
Post.where(deleted_at: nil, user_deleted: true)
|
||||||
|
@ -11,6 +11,44 @@ describe PostDestroyer do
|
|||||||
let(:admin) { Fabricate(:admin) }
|
let(:admin) { Fabricate(:admin) }
|
||||||
let(:post) { create_post }
|
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
|
describe 'destroy_old_stubs' do
|
||||||
it 'destroys stubs for deleted by user posts' do
|
it 'destroys stubs for deleted by user posts' do
|
||||||
SiteSetting.stubs(:delete_removed_posts_after).returns(24)
|
SiteSetting.stubs(:delete_removed_posts_after).returns(24)
|
||||||
@ -314,8 +352,8 @@ describe PostDestroyer do
|
|||||||
|
|
||||||
PostDestroyer.new(moderator, second_post).destroy
|
PostDestroyer.new(moderator, second_post).destroy
|
||||||
|
|
||||||
expect(UserAction.find_by(id: bookmark.id)).should == nil
|
expect(UserAction.find_by(id: bookmark.id)).to be_nil
|
||||||
expect(UserAction.find_by(id: like.id)).should == nil
|
expect(UserAction.find_by(id: like.id)).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user