diff --git a/app/assets/javascripts/discourse/models/_post.js b/app/assets/javascripts/discourse/models/_post.js index 1027ca98b..ccc3a93a6 100644 --- a/app/assets/javascripts/discourse/models/_post.js +++ b/app/assets/javascripts/discourse/models/_post.js @@ -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, diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c3550728f..e34493ea6 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/config/site_settings.yml b/config/site_settings.yml index a4ff071e4..cf291118c 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -339,6 +339,7 @@ posting: delete_removed_posts_after: client: true default: 24 + min: 0 traditional_markdown_linebreaks: client: true default: false diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 698b587e7..bdcf6058e 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -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) diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 3ffa058bb..b06765339 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -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