When deleting a post as staff, ask if you want to delete direct replies too
This commit is contained in:
parent
f157ec1f91
commit
71c1b8b9b9
|
@ -104,7 +104,6 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
postSelected: function(post) {
|
||||
if (this.get('allPostsSelected')) { return true; }
|
||||
if (this.get('selectedPosts').contains(post)) { return true; }
|
||||
|
||||
if (this.get('selectedReplies').findProperty('post_number', post.get('reply_to_post_number'))) { return true; }
|
||||
|
||||
return false;
|
||||
|
@ -458,7 +457,33 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
},
|
||||
|
||||
deletePost: function(post) {
|
||||
post.destroy(Discourse.User.current());
|
||||
var user = Discourse.User.current(),
|
||||
replyCount = post.get('reply_count'),
|
||||
self = this;
|
||||
|
||||
// If the user is staff and the post has replies, ask if they want to delete replies too.
|
||||
if (user.get('staff') && replyCount > 0) {
|
||||
bootbox.confirm(I18n.t("post.controls.delete_replies.confirm", {count: replyCount}),
|
||||
I18n.t("post.controls.delete_replies.no_value"),
|
||||
I18n.t("post.controls.delete_replies.yes_value"),
|
||||
function(result) {
|
||||
|
||||
// If the user wants to delete replies, do that, otherwise delete the post as normal.
|
||||
if (result) {
|
||||
Discourse.Post.deleteMany([post], [post]);
|
||||
self.get('postStream.posts').forEach(function (p) {
|
||||
if (p === post || p.get('reply_to_post_number') === post.get('post_number')) {
|
||||
p.setDeletedState(user);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
post.destroy(user);
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
post.destroy(user);
|
||||
}
|
||||
},
|
||||
|
||||
removeAllowedUser: function(username) {
|
||||
|
|
|
@ -225,17 +225,18 @@ Discourse.Post = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
/**
|
||||
Deletes a post
|
||||
Changes the state of the post to be deleted. Does not call the server, that should be
|
||||
done elsewhere.
|
||||
|
||||
@method destroy
|
||||
@param {Discourse.User} deleted_by The user deleting the post
|
||||
@method setDeletedState
|
||||
@param {Discourse.User} deletedBy The user deleting the post
|
||||
**/
|
||||
destroy: function(deleted_by) {
|
||||
setDeletedState: function(deletedBy) {
|
||||
// Moderators can delete posts. Regular users can only trigger a deleted at message.
|
||||
if (deleted_by.get('staff')) {
|
||||
if (deletedBy.get('staff')) {
|
||||
this.setProperties({
|
||||
deleted_at: new Date(),
|
||||
deleted_by: deleted_by,
|
||||
deleted_by: deletedBy,
|
||||
can_delete: false
|
||||
});
|
||||
} else {
|
||||
|
@ -248,7 +249,16 @@ Discourse.Post = Discourse.Model.extend({
|
|||
user_deleted: true
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Deletes a post
|
||||
|
||||
@method destroy
|
||||
@param {Discourse.User} deletedBy The user deleting the post
|
||||
**/
|
||||
destroy: function(deletedBy) {
|
||||
this.setDeletedState(deletedBy);
|
||||
return Discourse.ajax("/posts/" + (this.get('id')), { type: 'DELETE' });
|
||||
},
|
||||
|
||||
|
|
|
@ -159,8 +159,7 @@ class PostsController < ApplicationController
|
|||
|
||||
Post.transaction do
|
||||
topic_id = posts.first.topic_id
|
||||
posts.each {|p| p.destroy }
|
||||
Topic.reset_highest(topic_id)
|
||||
posts.each {|p| PostDestroyer.new(current_user, p).destroy }
|
||||
end
|
||||
|
||||
render nothing: true
|
||||
|
|
|
@ -816,6 +816,12 @@ en:
|
|||
undelete: "undelete this post"
|
||||
share: "share a link to this post"
|
||||
more: "More"
|
||||
delete_replies:
|
||||
confirm:
|
||||
one: "Do you also want to delete the direct reply to this post?"
|
||||
other: "Do you also want to delete the {{count}} direct replies to this post?"
|
||||
yes_value: "Yes, delete the replies too"
|
||||
no_value: "No, just this post"
|
||||
|
||||
actions:
|
||||
flag: 'Flag'
|
||||
|
|
|
@ -180,12 +180,12 @@ describe PostsController do
|
|||
end
|
||||
|
||||
it "deletes the post" do
|
||||
Post.any_instance.expects(:destroy).twice
|
||||
PostDestroyer.any_instance.expects(:destroy).twice
|
||||
xhr :delete, :destroy_many, post_ids: [post1.id, post2.id]
|
||||
end
|
||||
|
||||
it "updates the highest read data for the forum" do
|
||||
Topic.expects(:reset_highest)
|
||||
Topic.expects(:reset_highest).twice
|
||||
xhr :delete, :destroy_many, post_ids: [post1.id, post2.id]
|
||||
end
|
||||
|
||||
|
@ -196,7 +196,7 @@ describe PostsController do
|
|||
end
|
||||
|
||||
it "deletes the post and the reply to it" do
|
||||
Post.any_instance.expects(:destroy).twice
|
||||
PostDestroyer.any_instance.expects(:destroy).twice
|
||||
xhr :delete, :destroy_many, post_ids: [post1.id], reply_post_ids: [post1.id]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue