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"),
|
label: I18n.t("yes_value"),
|
||||||
class: "btn-danger",
|
class: "btn-danger",
|
||||||
callback() {
|
callback() {
|
||||||
Post.deleteMany(replies.map(r => r.id), { deferFlags: true })
|
Post.deleteMany(replies.map(r => r.id), {
|
||||||
|
agreeWithFirstReplyFlag: false
|
||||||
|
})
|
||||||
.then(action)
|
.then(action)
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -378,10 +378,10 @@ Post.reopenClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteMany(post_ids, { deferFlags = false } = {}) {
|
deleteMany(post_ids, { agreeWithFirstReplyFlag = true } = {}) {
|
||||||
return ajax("/posts/destroy_many", {
|
return ajax("/posts/destroy_many", {
|
||||||
type: "DELETE",
|
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
|
def destroy_many
|
||||||
params.require(:post_ids)
|
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)
|
posts = Post.where(id: post_ids_including_replies)
|
||||||
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
||||||
|
@ -345,7 +345,9 @@ class PostsController < ApplicationController
|
||||||
posts.each { |p| guardian.ensure_can_delete!(p) }
|
posts.each { |p| guardian.ensure_can_delete!(p) }
|
||||||
|
|
||||||
Post.transaction do
|
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
|
end
|
||||||
|
|
||||||
render body: nil
|
render body: nil
|
||||||
|
|
|
@ -147,7 +147,7 @@ class PostDestroyer
|
||||||
update_user_counts
|
update_user_counts
|
||||||
TopicUser.update_post_action_cache(post_id: @post.id)
|
TopicUser.update_post_action_cache(post_id: @post.id)
|
||||||
DB.after_commit do
|
DB.after_commit do
|
||||||
if @opts[:defer_flags].to_s == "true"
|
if @opts[:defer_flags]
|
||||||
defer_flags
|
defer_flags
|
||||||
else
|
else
|
||||||
agree_with_flags
|
agree_with_flags
|
||||||
|
|
|
@ -248,15 +248,22 @@ describe PostsController do
|
||||||
let(:moderator) { Fabricate(:moderator) }
|
let(:moderator) { Fabricate(:moderator) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
sign_in(moderator)
|
||||||
PostAction.act(moderator, post1, PostActionType.types[:off_topic])
|
PostAction.act(moderator, post1, PostActionType.types[:off_topic])
|
||||||
PostAction.act(moderator, post2, PostActionType.types[:off_topic])
|
PostAction.act(moderator, post2, PostActionType.types[:off_topic])
|
||||||
Jobs::SendSystemMessage.clear
|
Jobs::SendSystemMessage.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defers the posts" do
|
it "defers the child posts by default" do
|
||||||
sign_in(moderator)
|
|
||||||
expect(PostAction.flagged_posts_count).to eq(2)
|
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(Jobs::SendSystemMessage.jobs.size).to eq(0)
|
||||||
expect(PostAction.flagged_posts_count).to eq(0)
|
expect(PostAction.flagged_posts_count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue