FEATURE: defer flags when deleting child replies (#7111)
This commit is contained in:
parent
b2187301fd
commit
05ebb52ec4
|
@ -136,7 +136,9 @@ export default Post.extend({
|
|||
label: I18n.t("yes_value"),
|
||||
class: "btn-danger",
|
||||
callback() {
|
||||
Post.deleteMany(replies.map(r => r.id), { deferFlags: true })
|
||||
Post.deleteMany(replies.map(r => r.id), {
|
||||
agreeWithFirstReplyFlag: false
|
||||
})
|
||||
.then(action)
|
||||
.then(resolve)
|
||||
.catch(error => {
|
||||
|
|
|
@ -378,10 +378,10 @@ Post.reopenClass({
|
|||
});
|
||||
},
|
||||
|
||||
deleteMany(post_ids, { deferFlags = false } = {}) {
|
||||
deleteMany(post_ids, { agreeWithFirstReplyFlag = true } = {}) {
|
||||
return ajax("/posts/destroy_many", {
|
||||
type: "DELETE",
|
||||
data: { post_ids, defer_flags: deferFlags }
|
||||
data: { post_ids, agree_with_first_reply_flag: agreeWithFirstReplyFlag }
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ class PostsController < ApplicationController
|
|||
|
||||
def destroy_many
|
||||
params.require(:post_ids)
|
||||
defer_flags = params[:defer_flags] || false
|
||||
agree_with_first_reply_flag = (params[:agree_with_first_reply_flag] || true).to_s == "true"
|
||||
|
||||
posts = Post.where(id: post_ids_including_replies)
|
||||
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
||||
|
@ -345,7 +345,9 @@ class PostsController < ApplicationController
|
|||
posts.each { |p| guardian.ensure_can_delete!(p) }
|
||||
|
||||
Post.transaction do
|
||||
posts.each { |p| PostDestroyer.new(current_user, p, defer_flags: defer_flags).destroy }
|
||||
posts.each_with_index do |p, i|
|
||||
PostDestroyer.new(current_user, p, defer_flags: !(agree_with_first_reply_flag && i == 0)).destroy
|
||||
end
|
||||
end
|
||||
|
||||
render body: nil
|
||||
|
|
|
@ -147,7 +147,7 @@ class PostDestroyer
|
|||
update_user_counts
|
||||
TopicUser.update_post_action_cache(post_id: @post.id)
|
||||
DB.after_commit do
|
||||
if @opts[:defer_flags].to_s == "true"
|
||||
if @opts[:defer_flags]
|
||||
defer_flags
|
||||
else
|
||||
agree_with_flags
|
||||
|
|
|
@ -248,15 +248,22 @@ describe PostsController do
|
|||
let(:moderator) { Fabricate(:moderator) }
|
||||
|
||||
before do
|
||||
sign_in(moderator)
|
||||
PostAction.act(moderator, post1, PostActionType.types[:off_topic])
|
||||
PostAction.act(moderator, post2, PostActionType.types[:off_topic])
|
||||
Jobs::SendSystemMessage.clear
|
||||
end
|
||||
|
||||
it "defers the posts" do
|
||||
sign_in(moderator)
|
||||
it "defers the child posts by default" do
|
||||
expect(PostAction.flagged_posts_count).to eq(2)
|
||||
delete "/posts/destroy_many.json", params: { post_ids: [post1.id, post2.id], defer_flags: true }
|
||||
delete "/posts/destroy_many.json", params: { post_ids: [post1.id, post2.id] }
|
||||
expect(Jobs::SendSystemMessage.jobs.size).to eq(1)
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
end
|
||||
|
||||
it "can defer all posts based on `agree_with_first_reply_flag` param" do
|
||||
expect(PostAction.flagged_posts_count).to eq(2)
|
||||
delete "/posts/destroy_many.json", params: { post_ids: [post1.id, post2.id], agree_with_first_reply_flag: false }
|
||||
expect(Jobs::SendSystemMessage.jobs.size).to eq(0)
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue