mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: posts will be deleted immediately if delete_removed_posts_after is set to 0
This commit is contained in:
parent
76a9eca5b0
commit
ad387a1150
5 changed files with 23 additions and 10 deletions
|
@ -233,8 +233,8 @@ Discourse.Post = Discourse.Model.extend({
|
||||||
setDeletedState: function(deletedBy) {
|
setDeletedState: function(deletedBy) {
|
||||||
this.set('oldCooked', this.get('cooked'));
|
this.set('oldCooked', this.get('cooked'));
|
||||||
|
|
||||||
// Moderators can delete posts. Users can only trigger a deleted at message.
|
// Moderators can delete posts. Users can only trigger a deleted at message, unless delete_removed_posts_after is 0.
|
||||||
if (deletedBy.get('staff')) {
|
if (deletedBy.get('staff') || Discourse.SiteSettings.delete_removed_posts_after === 0) {
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
deleted_at: new Date(),
|
deleted_at: new Date(),
|
||||||
deleted_by: deletedBy,
|
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."
|
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."
|
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."
|
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_width: "Maximum thumbnail width of images in a post"
|
||||||
max_image_height: "Maximum thumbnail height 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."
|
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:
|
delete_removed_posts_after:
|
||||||
client: true
|
client: true
|
||||||
default: 24
|
default: 24
|
||||||
|
min: 0
|
||||||
traditional_markdown_linebreaks:
|
traditional_markdown_linebreaks:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -41,10 +41,10 @@ class PostDestroyer
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @user.staff?
|
if @user.staff? || SiteSetting.delete_removed_posts_after < 1
|
||||||
staff_destroyed
|
perform_delete
|
||||||
elsif @user.id == @post.user_id
|
elsif @user.id == @post.user_id
|
||||||
user_destroyed
|
mark_for_deletion
|
||||||
end
|
end
|
||||||
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
|
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
||||||
# show up in the topic
|
# show up in the topic
|
||||||
def staff_destroyed
|
def perform_delete
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
@post.trash!(@user)
|
@post.trash!(@user)
|
||||||
if @post.topic
|
if @post.topic
|
||||||
|
@ -81,9 +81,9 @@ class PostDestroyer
|
||||||
remove_associated_replies
|
remove_associated_replies
|
||||||
remove_associated_notifications
|
remove_associated_notifications
|
||||||
if @post.topic && @post.post_number == 1
|
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)
|
@post.topic.trash!(@user)
|
||||||
else
|
elsif @user.id != @post.user_id
|
||||||
StaffActionLogger.new(@user).log_post_deletion(@post, @opts.slice(:context))
|
StaffActionLogger.new(@user).log_post_deletion(@post, @opts.slice(:context))
|
||||||
end
|
end
|
||||||
update_associated_category_latest_topic
|
update_associated_category_latest_topic
|
||||||
|
@ -94,7 +94,7 @@ class PostDestroyer
|
||||||
end
|
end
|
||||||
|
|
||||||
# When a user 'deletes' their own post. We just change the text.
|
# When a user 'deletes' their own post. We just change the text.
|
||||||
def user_destroyed
|
def mark_for_deletion
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
@post.revise(@user, I18n.t('js.post.deleted_by_author', count: SiteSetting.delete_removed_posts_after), force_new_version: true)
|
@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)
|
@post.update_column(:user_deleted, true)
|
||||||
|
|
|
@ -128,6 +128,18 @@ describe PostDestroyer do
|
||||||
|
|
||||||
reply1.reload.deleted_at.should_not == nil
|
reply1.reload.deleted_at.should_not == nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'basic destroying' do
|
describe 'basic destroying' do
|
||||||
|
|
Loading…
Reference in a new issue