mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
The ability to display errors on flagging actions.
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
import Post from 'discourse/models/post';
|
import Post from 'discourse/models/post';
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
export default Post.extend({
|
export default Post.extend({
|
||||||
|
|
||||||
@ -52,15 +53,15 @@ export default Post.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
disagreeFlags() {
|
disagreeFlags() {
|
||||||
return ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
return ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false }).catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
deferFlags(deletePost) {
|
deferFlags(deletePost) {
|
||||||
return ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } });
|
return ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false, data: { delete_post: deletePost } }).catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
agreeFlags(actionOnPost) {
|
agreeFlags(actionOnPost) {
|
||||||
return ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } });
|
return ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false, data: { action_on_post: actionOnPost } }).catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
postHidden: Ember.computed.alias('hidden'),
|
postHidden: Ember.computed.alias('hidden'),
|
||||||
|
@ -153,5 +153,9 @@
|
|||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{plugin-outlet
|
||||||
|
name="flagged-post-below-controls"
|
||||||
|
tagName=""
|
||||||
|
args=(hash flaggedPost=flaggedPost canAct=canAct)}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.flagged-post-contents {
|
.flagged-post-contents {
|
||||||
|
width: 100%;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
.d-icon {
|
.d-icon {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -60,8 +60,16 @@ class Admin::FlagsController < Admin::AdminController
|
|||||||
|
|
||||||
def agree
|
def agree
|
||||||
params.permit(:id, :action_on_post)
|
params.permit(:id, :action_on_post)
|
||||||
|
|
||||||
post = Post.find(params[:id])
|
post = Post.find(params[:id])
|
||||||
|
|
||||||
|
DiscourseEvent.trigger(
|
||||||
|
:before_staff_flag_action,
|
||||||
|
type: 'agree',
|
||||||
|
post: post,
|
||||||
|
action_on_post: params[:action_on_post],
|
||||||
|
user: current_user
|
||||||
|
)
|
||||||
|
|
||||||
post_action_type = PostAction.post_action_type_for_post(post.id)
|
post_action_type = PostAction.post_action_type_for_post(post.id)
|
||||||
|
|
||||||
keep_post = params[:action_on_post] == "keep"
|
keep_post = params[:action_on_post] == "keep"
|
||||||
@ -85,6 +93,13 @@ class Admin::FlagsController < Admin::AdminController
|
|||||||
params.permit(:id)
|
params.permit(:id)
|
||||||
post = Post.find(params[:id])
|
post = Post.find(params[:id])
|
||||||
|
|
||||||
|
DiscourseEvent.trigger(
|
||||||
|
:before_staff_flag_action,
|
||||||
|
type: 'disagree',
|
||||||
|
post: post,
|
||||||
|
user: current_user
|
||||||
|
)
|
||||||
|
|
||||||
PostAction.clear_flags!(post, current_user)
|
PostAction.clear_flags!(post, current_user)
|
||||||
|
|
||||||
post.unhide!
|
post.unhide!
|
||||||
@ -96,8 +111,14 @@ class Admin::FlagsController < Admin::AdminController
|
|||||||
params.permit(:id, :delete_post)
|
params.permit(:id, :delete_post)
|
||||||
post = Post.find(params[:id])
|
post = Post.find(params[:id])
|
||||||
|
|
||||||
PostAction.defer_flags!(post, current_user, params[:delete_post])
|
DiscourseEvent.trigger(
|
||||||
|
:before_staff_flag_action,
|
||||||
|
type: 'defer',
|
||||||
|
post: post,
|
||||||
|
user: current_user
|
||||||
|
)
|
||||||
|
|
||||||
|
PostAction.defer_flags!(post, current_user, params[:delete_post])
|
||||||
PostDestroyer.new(current_user, post).destroy if params[:delete_post]
|
PostDestroyer.new(current_user, post).destroy if params[:delete_post]
|
||||||
|
|
||||||
render body: nil
|
render body: nil
|
||||||
|
@ -114,7 +114,7 @@ class ApplicationController < ActionController::Base
|
|||||||
rescue_from Discourse::NotLoggedIn do |e|
|
rescue_from Discourse::NotLoggedIn do |e|
|
||||||
raise e if Rails.env.test?
|
raise e if Rails.env.test?
|
||||||
if (request.format && request.format.json?) || request.xhr? || !request.get?
|
if (request.format && request.format.json?) || request.xhr? || !request.get?
|
||||||
rescue_discourse_actions(:not_logged_in, 403, true)
|
rescue_discourse_actions(:not_logged_in, 403, include_ember: true)
|
||||||
else
|
else
|
||||||
rescue_discourse_actions(:not_found, 404)
|
rescue_discourse_actions(:not_found, 404)
|
||||||
end
|
end
|
||||||
@ -140,16 +140,21 @@ class ApplicationController < ActionController::Base
|
|||||||
rescue_discourse_actions(:not_found, 404)
|
rescue_discourse_actions(:not_found, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::InvalidAccess do
|
rescue_from Discourse::InvalidAccess do |e|
|
||||||
rescue_discourse_actions(:invalid_access, 403, true)
|
rescue_discourse_actions(
|
||||||
|
:invalid_access,
|
||||||
|
403,
|
||||||
|
include_ember: true,
|
||||||
|
custom_message: e.custom_message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::ReadOnly do
|
rescue_from Discourse::ReadOnly do
|
||||||
render_json_error I18n.t('read_only_mode_enabled'), type: :read_only, status: 503
|
render_json_error I18n.t('read_only_mode_enabled'), type: :read_only, status: 503
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue_discourse_actions(type, status_code, include_ember = false)
|
def rescue_discourse_actions(type, status_code, opts = nil)
|
||||||
|
opts ||= {}
|
||||||
show_json_errors = (request.format && request.format.json?) ||
|
show_json_errors = (request.format && request.format.json?) ||
|
||||||
(request.xhr?) ||
|
(request.xhr?) ||
|
||||||
((params[:external_id] || '').ends_with? '.json')
|
((params[:external_id] || '').ends_with? '.json')
|
||||||
@ -160,9 +165,9 @@ class ApplicationController < ActionController::Base
|
|||||||
return render status: status_code, layout: false, text: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
|
return render status: status_code, layout: false, text: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
render_json_error I18n.t(type), type: type, status: status_code
|
render_json_error I18n.t(opts[:custom_message] || type), type: type, status: status_code
|
||||||
else
|
else
|
||||||
render html: build_not_found_page(status_code, include_ember ? 'application' : 'no_ember')
|
render html: build_not_found_page(status_code, opts[:include_ember] ? 'application' : 'no_ember')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ module Jobs
|
|||||||
guardian = Guardian.new(Discourse.system_user)
|
guardian = Guardian.new(Discourse.system_user)
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
flags = FlagQuery.flagged_post_actions('active')
|
flags = FlagQuery.flagged_post_actions(filter: 'active')
|
||||||
.where('post_actions.created_at < ?', SiteSetting.auto_handle_queued_age.to_i.days.ago)
|
.where('post_actions.created_at < ?', SiteSetting.auto_handle_queued_age.to_i.days.ago)
|
||||||
|
|
||||||
Post.where(id: flags.pluck(:post_id).uniq).each do |post|
|
Post.where(id: flags.pluck(:post_id).uniq).each do |post|
|
||||||
|
@ -63,9 +63,12 @@ module Discourse
|
|||||||
|
|
||||||
# When they don't have permission to do something
|
# When they don't have permission to do something
|
||||||
class InvalidAccess < StandardError
|
class InvalidAccess < StandardError
|
||||||
attr_reader :obj
|
attr_reader :obj, :custom_message
|
||||||
def initialize(msg = nil, obj = nil)
|
def initialize(msg = nil, obj = nil, opts = nil)
|
||||||
super(msg)
|
super(msg)
|
||||||
|
|
||||||
|
opts ||= {}
|
||||||
|
@custom_message = opts[:custom_message] if opts[:custom_message]
|
||||||
@obj = obj
|
@obj = obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user