FIX: display a correct error when attempting to agree on a deferred flag
Previously we would raise a 500 error if a moderator tried to agree on a flag another moderator deferred. This can happen cause the UX for flags does not live refresh as flags are handled
This commit is contained in:
parent
71185c13b5
commit
d1984a0b4d
|
@ -73,6 +73,14 @@ class Admin::FlagsController < Admin::AdminController
|
|||
|
||||
post_action_type = PostAction.post_action_type_for_post(post.id)
|
||||
|
||||
if !post_action_type
|
||||
render_json_error(
|
||||
I18n.t("flags.errors.already_handled"),
|
||||
status: 409
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
keep_post = ['silenced', 'suspended', 'keep'].include?(params[:action_on_post])
|
||||
delete_post = params[:action_on_post] == "delete"
|
||||
restore_post = params[:action_on_post] == "restore"
|
||||
|
|
|
@ -633,7 +633,7 @@ class PostAction < ActiveRecord::Base
|
|||
|
||||
def self.post_action_type_for_post(post_id)
|
||||
post_action = PostAction.find_by(deferred_at: nil, post_id: post_id, post_action_type_id: PostActionType.notify_flag_types.values, deleted_at: nil)
|
||||
PostActionType.types[post_action.post_action_type_id]
|
||||
PostActionType.types[post_action.post_action_type_id] if post_action
|
||||
end
|
||||
|
||||
def self.target_moderators
|
||||
|
|
|
@ -864,6 +864,9 @@ en:
|
|||
read: "Read all"
|
||||
write: "Write all"
|
||||
|
||||
flags:
|
||||
errors:
|
||||
already_handled: "Flag was already handled"
|
||||
reports:
|
||||
default:
|
||||
labels:
|
||||
|
|
|
@ -34,6 +34,21 @@ RSpec.describe Admin::FlagsController do
|
|||
end
|
||||
|
||||
context '#agree' do
|
||||
it 'should raise a reasonable error if a flag was deferred and then someone else agreed' do
|
||||
SiteSetting.queue_jobs = false
|
||||
|
||||
_post_action = PostAction.act(user, post_1, PostActionType.types[:spam], message: 'bad')
|
||||
|
||||
post "/admin/flags/defer/#{post_1.id}.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
post "/admin/flags/agree/#{post_1.id}.json", params: { action_on_post: 'keep' }
|
||||
# 409 means conflict which is what is happening here
|
||||
expect(response.status).to eq(409)
|
||||
error = JSON.parse(response.body)["errors"].first
|
||||
expect(error).to eq(I18n.t("flags.errors.already_handled"))
|
||||
end
|
||||
|
||||
it 'should be able to agree and keep content' do
|
||||
SiteSetting.queue_jobs = false
|
||||
|
||||
|
|
Loading…
Reference in New Issue