mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
When deleting a post as staff, ask if you want to delete direct replies too
This commit is contained in:
@ -104,7 +104,6 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||||||
postSelected: function(post) {
|
postSelected: function(post) {
|
||||||
if (this.get('allPostsSelected')) { return true; }
|
if (this.get('allPostsSelected')) { return true; }
|
||||||
if (this.get('selectedPosts').contains(post)) { 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; }
|
if (this.get('selectedReplies').findProperty('post_number', post.get('reply_to_post_number'))) { return true; }
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -458,7 +457,33 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||||||
},
|
},
|
||||||
|
|
||||||
deletePost: function(post) {
|
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) {
|
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
|
@method setDeletedState
|
||||||
@param {Discourse.User} deleted_by The user deleting the post
|
@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.
|
// Moderators can delete posts. Regular users can only trigger a deleted at message.
|
||||||
if (deleted_by.get('staff')) {
|
if (deletedBy.get('staff')) {
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
deleted_at: new Date(),
|
deleted_at: new Date(),
|
||||||
deleted_by: deleted_by,
|
deleted_by: deletedBy,
|
||||||
can_delete: false
|
can_delete: false
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -248,7 +249,16 @@ Discourse.Post = Discourse.Model.extend({
|
|||||||
user_deleted: true
|
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' });
|
return Discourse.ajax("/posts/" + (this.get('id')), { type: 'DELETE' });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -159,8 +159,7 @@ class PostsController < ApplicationController
|
|||||||
|
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
topic_id = posts.first.topic_id
|
topic_id = posts.first.topic_id
|
||||||
posts.each {|p| p.destroy }
|
posts.each {|p| PostDestroyer.new(current_user, p).destroy }
|
||||||
Topic.reset_highest(topic_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
|
@ -816,6 +816,12 @@ en:
|
|||||||
undelete: "undelete this post"
|
undelete: "undelete this post"
|
||||||
share: "share a link to this post"
|
share: "share a link to this post"
|
||||||
more: "More"
|
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:
|
actions:
|
||||||
flag: 'Flag'
|
flag: 'Flag'
|
||||||
|
@ -180,12 +180,12 @@ describe PostsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the post" do
|
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]
|
xhr :delete, :destroy_many, post_ids: [post1.id, post2.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates the highest read data for the forum" do
|
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]
|
xhr :delete, :destroy_many, post_ids: [post1.id, post2.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ describe PostsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the post and the reply to it" do
|
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]
|
xhr :delete, :destroy_many, post_ids: [post1.id], reply_post_ids: [post1.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user