2013-08-19 07:14:26 -04:00
|
|
|
require 'flag_query'
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
class Admin::FlagsController < Admin::AdminController
|
2014-07-28 13:17:37 -04:00
|
|
|
|
2017-09-08 16:47:49 -04:00
|
|
|
def self.flags_per_page
|
|
|
|
10
|
|
|
|
end
|
|
|
|
|
2013-02-07 10:45:24 -05:00
|
|
|
def index
|
2013-05-12 21:09:03 -04:00
|
|
|
# we may get out of sync, fix it here
|
|
|
|
PostAction.update_flagged_posts_count
|
2017-09-08 16:47:49 -04:00
|
|
|
|
2017-09-12 13:04:53 -04:00
|
|
|
offset = params[:offset].to_i
|
|
|
|
per_page = Admin::FlagsController.flags_per_page
|
|
|
|
|
|
|
|
posts, topics, users, post_actions, total_rows = FlagQuery.flagged_posts_report(
|
2017-09-08 16:47:49 -04:00
|
|
|
current_user,
|
|
|
|
filter: params[:filter],
|
2018-01-17 13:03:14 -05:00
|
|
|
user_id: params[:user_id],
|
2017-09-12 13:04:53 -04:00
|
|
|
offset: offset,
|
2017-09-08 16:47:49 -04:00
|
|
|
topic_id: params[:topic_id],
|
2017-09-12 13:04:53 -04:00
|
|
|
per_page: per_page,
|
2017-09-11 16:44:20 -04:00
|
|
|
rest_api: params[:rest_api].present?
|
2017-09-08 16:47:49 -04:00
|
|
|
)
|
2013-05-12 21:09:03 -04:00
|
|
|
|
2017-09-12 13:04:53 -04:00
|
|
|
if params[:rest_api]
|
|
|
|
meta = {
|
|
|
|
types: {
|
|
|
|
disposed_by: 'user'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total_rows || 0) > (offset + per_page)
|
|
|
|
meta[:total_rows_flagged_posts] = total_rows
|
|
|
|
meta[:load_more_flagged_posts] = admin_flags_filtered_path(
|
|
|
|
filter: params[:filter],
|
|
|
|
offset: offset + per_page,
|
|
|
|
rest_api: params[:rest_api],
|
|
|
|
topic_id: params[:topic_id]
|
2017-09-11 16:44:20 -04:00
|
|
|
)
|
|
|
|
end
|
2017-09-12 13:04:53 -04:00
|
|
|
|
|
|
|
render_json_dump(
|
|
|
|
{
|
|
|
|
flagged_posts: posts,
|
|
|
|
topics: serialize_data(topics, FlaggedTopicSerializer),
|
|
|
|
users: serialize_data(users, FlaggedUserSerializer),
|
|
|
|
post_actions: post_actions
|
|
|
|
},
|
|
|
|
rest_serializer: true,
|
|
|
|
meta: meta
|
|
|
|
)
|
|
|
|
else
|
|
|
|
render_json_dump(
|
|
|
|
posts: posts,
|
|
|
|
topics: serialize_data(topics, FlaggedTopicSerializer),
|
|
|
|
users: serialize_data(users, FlaggedUserSerializer)
|
|
|
|
)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-28 13:17:37 -04:00
|
|
|
def agree
|
2014-08-04 16:48:04 -04:00
|
|
|
params.permit(:id, :action_on_post)
|
2014-07-28 13:17:37 -04:00
|
|
|
post = Post.find(params[:id])
|
2017-09-23 10:39:58 -04:00
|
|
|
|
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'agree',
|
|
|
|
post: post,
|
|
|
|
action_on_post: params[:action_on_post],
|
|
|
|
user: current_user
|
|
|
|
)
|
|
|
|
|
2014-07-28 13:17:37 -04:00
|
|
|
post_action_type = PostAction.post_action_type_for_post(post.id)
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2018-09-11 23:16:45 -04:00
|
|
|
if !post_action_type
|
|
|
|
render_json_error(
|
|
|
|
I18n.t("flags.errors.already_handled"),
|
|
|
|
status: 409
|
|
|
|
)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-03-14 14:39:20 -04:00
|
|
|
keep_post = ['silenced', 'suspended', 'keep'].include?(params[:action_on_post])
|
2014-08-04 16:48:04 -04:00
|
|
|
delete_post = params[:action_on_post] == "delete"
|
2014-09-09 14:26:40 -04:00
|
|
|
restore_post = params[:action_on_post] == "restore"
|
2014-08-04 16:48:04 -04:00
|
|
|
|
|
|
|
if delete_post
|
2018-11-27 23:51:11 -05:00
|
|
|
# PostDestroy calls PostAction.agree_flags!
|
|
|
|
destroy_post(post)
|
2014-09-09 14:26:40 -04:00
|
|
|
elsif restore_post
|
2018-07-30 16:44:52 -04:00
|
|
|
PostAction.agree_flags!(post, current_user, delete_post)
|
2014-09-09 14:26:40 -04:00
|
|
|
PostDestroyer.new(current_user, post).recover
|
2018-08-06 20:05:43 -04:00
|
|
|
else
|
2018-07-30 16:44:52 -04:00
|
|
|
PostAction.agree_flags!(post, current_user, delete_post)
|
2018-08-06 20:05:43 -04:00
|
|
|
if !keep_post
|
|
|
|
PostAction.hide_post!(post, post_action_type)
|
|
|
|
end
|
2014-07-28 13:17:37 -04:00
|
|
|
end
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
render body: nil
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
2013-06-20 03:42:15 -04:00
|
|
|
|
2014-07-28 13:17:37 -04:00
|
|
|
def disagree
|
|
|
|
params.permit(:id)
|
|
|
|
post = Post.find(params[:id])
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-09-23 10:39:58 -04:00
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'disagree',
|
|
|
|
post: post,
|
|
|
|
user: current_user
|
|
|
|
)
|
|
|
|
|
2014-07-28 13:17:37 -04:00
|
|
|
PostAction.clear_flags!(post, current_user)
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
render body: nil
|
2013-06-20 03:42:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def defer
|
2014-07-28 13:17:37 -04:00
|
|
|
params.permit(:id, :delete_post)
|
|
|
|
post = Post.find(params[:id])
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-09-23 10:39:58 -04:00
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'defer',
|
|
|
|
post: post,
|
|
|
|
user: current_user
|
|
|
|
)
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-09-23 10:39:58 -04:00
|
|
|
PostAction.defer_flags!(post, current_user, params[:delete_post])
|
2018-11-23 08:58:04 -05:00
|
|
|
destroy_post(post) if params[:delete_post]
|
2014-08-04 16:48:04 -04:00
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
render body: nil
|
2013-06-20 03:42:15 -04:00
|
|
|
end
|
2014-04-30 10:58:01 -04:00
|
|
|
|
2018-11-23 08:58:04 -05:00
|
|
|
private
|
|
|
|
|
2018-11-27 23:51:11 -05:00
|
|
|
def destroy_post(post)
|
2018-11-23 08:58:04 -05:00
|
|
|
if post.is_first_post?
|
|
|
|
topic = Topic.find_by(id: post.topic_id)
|
|
|
|
guardian.ensure_can_delete!(topic) if topic.present?
|
|
|
|
end
|
|
|
|
|
2018-11-27 23:51:11 -05:00
|
|
|
PostDestroyer.new(current_user, post).destroy
|
2018-11-23 08:58:04 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|