2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-19 19:14:26 +08:00
|
|
|
require 'flag_query'
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
class Admin::FlagsController < Admin::AdminController
|
2014-07-29 01:17:37 +08:00
|
|
|
|
2017-09-09 04:47:49 +08:00
|
|
|
def self.flags_per_page
|
|
|
|
10
|
|
|
|
end
|
|
|
|
|
2013-02-07 23:45:24 +08:00
|
|
|
def index
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("FlagsController#index has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
|
2017-09-09 04:47:49 +08:00
|
|
|
|
2017-09-13 01:04:53 +08: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-09 04:47:49 +08:00
|
|
|
current_user,
|
|
|
|
filter: params[:filter],
|
2018-01-18 02:03:14 +08:00
|
|
|
user_id: params[:user_id],
|
2017-09-13 01:04:53 +08:00
|
|
|
offset: offset,
|
2017-09-09 04:47:49 +08:00
|
|
|
topic_id: params[:topic_id],
|
2019-01-04 01:03:01 +08:00
|
|
|
per_page: per_page
|
2017-09-09 04:47:49 +08:00
|
|
|
)
|
2013-05-13 09:09:03 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
meta = {
|
|
|
|
types: {
|
|
|
|
disposed_by: 'user'
|
2017-09-13 01:04:53 +08:00
|
|
|
}
|
2019-01-04 01:03:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
next_segment = offset + per_page
|
|
|
|
if (total_rows || 0) > next_segment
|
|
|
|
meta[:total_rows_flagged_posts] = total_rows
|
|
|
|
meta[:load_more_flagged_posts] = admin_flags_filtered_path(
|
|
|
|
filter: params[:filter],
|
|
|
|
offset: next_segment,
|
|
|
|
topic_id: params[:topic_id]
|
2017-09-13 01:04:53 +08:00
|
|
|
)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2019-01-04 01:03:01 +08: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
|
|
|
|
)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
def agree
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("FlagsController#agree has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
|
|
|
|
|
2014-08-05 04:48:04 +08:00
|
|
|
params.permit(:id, :action_on_post)
|
2014-07-29 01:17:37 +08:00
|
|
|
post = Post.find(params[:id])
|
2017-09-23 22:39:58 +08:00
|
|
|
|
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'agree',
|
|
|
|
post: post,
|
|
|
|
action_on_post: params[:action_on_post],
|
|
|
|
user: current_user
|
|
|
|
)
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable = post.reviewable_flag
|
|
|
|
return render_json_error(I18n.t("flags.errors.already_handled"), status: 409) if reviewable.blank?
|
2018-09-12 11:16:45 +08:00
|
|
|
|
2018-03-15 02:39:20 +08:00
|
|
|
keep_post = ['silenced', 'suspended', 'keep'].include?(params[:action_on_post])
|
2014-08-05 04:48:04 +08:00
|
|
|
delete_post = params[:action_on_post] == "delete"
|
2014-09-10 02:26:40 +08:00
|
|
|
restore_post = params[:action_on_post] == "restore"
|
2014-08-05 04:48:04 +08:00
|
|
|
|
|
|
|
if delete_post
|
2019-01-04 01:03:01 +08:00
|
|
|
# PostDestroy automatically agrees with flags
|
2018-11-28 12:51:11 +08:00
|
|
|
destroy_post(post)
|
2014-09-10 02:26:40 +08:00
|
|
|
elsif restore_post
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.perform(current_user, :agree_and_restore)
|
2018-08-07 08:05:43 +08:00
|
|
|
else
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.perform(
|
|
|
|
current_user,
|
|
|
|
:agree_and_keep,
|
|
|
|
post_was_deleted: delete_post,
|
|
|
|
hide_post: !keep_post
|
|
|
|
)
|
2014-07-29 01:17:37 +08:00
|
|
|
end
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
render body: nil
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-06-20 15:42:15 +08:00
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
def disagree
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("FlagsController#disagree has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
|
2014-07-29 01:17:37 +08:00
|
|
|
params.permit(:id)
|
|
|
|
post = Post.find(params[:id])
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
if reviewable = post.reviewable_flag
|
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'disagree',
|
|
|
|
post: post,
|
|
|
|
user: current_user
|
|
|
|
)
|
2017-09-23 22:39:58 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
if post.hidden?
|
|
|
|
reviewable.perform(current_user, :disagree_and_restore)
|
|
|
|
else
|
|
|
|
reviewable.perform(current_user, :disagree)
|
|
|
|
end
|
|
|
|
end
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
render body: nil
|
2013-06-20 15:42:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def defer
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("FlagsController#defer has been deprecated, please use the Reviewable API instead", since: "2.3.0beta5", drop_from: "2.4")
|
|
|
|
|
2014-07-29 01:17:37 +08:00
|
|
|
params.permit(:id, :delete_post)
|
|
|
|
post = Post.find(params[:id])
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
if reviewable = post.reviewable_flag
|
|
|
|
DiscourseEvent.trigger(
|
|
|
|
:before_staff_flag_action,
|
|
|
|
type: 'defer',
|
|
|
|
post: post,
|
|
|
|
user: current_user
|
|
|
|
)
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.perform(current_user, :ignore, post_was_deleted: params[:delete_post])
|
|
|
|
destroy_post(post) if params[:delete_post]
|
|
|
|
end
|
2014-08-05 04:48:04 +08:00
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
render body: nil
|
2013-06-20 15:42:15 +08:00
|
|
|
end
|
2014-04-30 22:58:01 +08:00
|
|
|
|
2018-11-23 21:58:04 +08:00
|
|
|
private
|
|
|
|
|
2018-11-28 12:51:11 +08:00
|
|
|
def destroy_post(post)
|
2018-11-23 21:58:04 +08: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-28 12:51:11 +08:00
|
|
|
PostDestroyer.new(current_user, post).destroy
|
2018-11-23 21:58:04 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|