FEATURE: posts will be deleted immediately if delete_removed_posts_after is set to 0
This commit is contained in:
parent
76a9eca5b0
commit
ad387a1150
|
@ -233,8 +233,8 @@ Discourse.Post = Discourse.Model.extend({
|
|||
setDeletedState: function(deletedBy) {
|
||||
this.set('oldCooked', this.get('cooked'));
|
||||
|
||||
// Moderators can delete posts. Users can only trigger a deleted at message.
|
||||
if (deletedBy.get('staff')) {
|
||||
// Moderators can delete posts. Users can only trigger a deleted at message, unless delete_removed_posts_after is 0.
|
||||
if (deletedBy.get('staff') || Discourse.SiteSettings.delete_removed_posts_after === 0) {
|
||||
this.setProperties({
|
||||
deleted_at: new Date(),
|
||||
deleted_by: deletedBy,
|
||||
|
|
|
@ -661,7 +661,7 @@ en:
|
|||
ninja_edit_window: "For (n) seconds after posting, editing will not create a new version in the post history."
|
||||
post_edit_time_limit: "The author can edit or delete their post for (n) minutes after posting. Set to 0 for forever."
|
||||
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view."
|
||||
delete_removed_posts_after: "Posts removed by the author will be automatically deleted after (n) hours."
|
||||
delete_removed_posts_after: "Posts removed by the author will be automatically deleted after (n) hours. If set to 0, posts will be deleted immediately."
|
||||
max_image_width: "Maximum thumbnail width of images in a post"
|
||||
max_image_height: "Maximum thumbnail height of images in a post"
|
||||
category_featured_topics: "Number of topics displayed per category on the /categories page. After changing this value, it takes up to 15 minutes for the categories page to update."
|
||||
|
|
|
@ -339,6 +339,7 @@ posting:
|
|||
delete_removed_posts_after:
|
||||
client: true
|
||||
default: 24
|
||||
min: 0
|
||||
traditional_markdown_linebreaks:
|
||||
client: true
|
||||
default: false
|
||||
|
|
|
@ -41,10 +41,10 @@ class PostDestroyer
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @user.staff?
|
||||
staff_destroyed
|
||||
if @user.staff? || SiteSetting.delete_removed_posts_after < 1
|
||||
perform_delete
|
||||
elsif @user.id == @post.user_id
|
||||
user_destroyed
|
||||
mark_for_deletion
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ class PostDestroyer
|
|||
|
||||
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
||||
# show up in the topic
|
||||
def staff_destroyed
|
||||
def perform_delete
|
||||
Post.transaction do
|
||||
@post.trash!(@user)
|
||||
if @post.topic
|
||||
|
@ -81,9 +81,9 @@ class PostDestroyer
|
|||
remove_associated_replies
|
||||
remove_associated_notifications
|
||||
if @post.topic && @post.post_number == 1
|
||||
StaffActionLogger.new(@user).log_topic_deletion(@post.topic, @opts.slice(:context))
|
||||
StaffActionLogger.new(@user).log_topic_deletion(@post.topic, @opts.slice(:context)) if @user.id != @post.user_id
|
||||
@post.topic.trash!(@user)
|
||||
else
|
||||
elsif @user.id != @post.user_id
|
||||
StaffActionLogger.new(@user).log_post_deletion(@post, @opts.slice(:context))
|
||||
end
|
||||
update_associated_category_latest_topic
|
||||
|
@ -94,7 +94,7 @@ class PostDestroyer
|
|||
end
|
||||
|
||||
# When a user 'deletes' their own post. We just change the text.
|
||||
def user_destroyed
|
||||
def mark_for_deletion
|
||||
Post.transaction do
|
||||
@post.revise(@user, I18n.t('js.post.deleted_by_author', count: SiteSetting.delete_removed_posts_after), force_new_version: true)
|
||||
@post.update_column(:user_deleted, true)
|
||||
|
|
|
@ -128,6 +128,18 @@ describe PostDestroyer do
|
|||
|
||||
reply1.reload.deleted_at.should_not == nil
|
||||
end
|
||||
|
||||
it "deletes posts immediately if delete_removed_posts_after is 0" do
|
||||
Fabricate(:admin)
|
||||
topic = post.topic
|
||||
reply1 = create_post(topic: topic)
|
||||
|
||||
SiteSetting.stubs(:delete_removed_posts_after).returns(0)
|
||||
|
||||
PostDestroyer.new(reply1.user, reply1).destroy
|
||||
|
||||
reply1.reload.deleted_at.should_not == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'basic destroying' do
|
||||
|
|
Loading…
Reference in New Issue