2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-11 05:00:50 +08:00
|
|
|
require_dependency 'queued_post_serializer'
|
|
|
|
|
|
|
|
class QueuedPostsController < ApplicationController
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
before_action :ensure_staff
|
2015-04-11 05:00:50 +08:00
|
|
|
|
|
|
|
def index
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("QueuedPostController#index is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
|
2015-04-11 05:00:50 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
status = params[:state] || 'pending'
|
|
|
|
status = 'pending' if status == 'new'
|
|
|
|
|
|
|
|
reviewables = Reviewable.list_for(current_user, status: status.to_sym, type: ReviewableQueuedPost.name)
|
|
|
|
render_serialized(reviewables,
|
2015-04-28 01:52:37 +08:00
|
|
|
QueuedPostSerializer,
|
|
|
|
root: :queued_posts,
|
|
|
|
rest_serializer: true,
|
|
|
|
refresh_queued_posts: "/queued_posts?status=new")
|
2015-04-11 05:00:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-01-04 01:03:01 +08:00
|
|
|
Discourse.deprecate("QueuedPostController#update is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
|
|
|
|
reviewable = Reviewable.find_by(id: params[:id])
|
|
|
|
raise Discourse::NotFound if reviewable.blank?
|
2017-11-27 21:15:29 +08:00
|
|
|
|
2017-08-16 00:44:05 +08:00
|
|
|
update_params = params[:queued_post]
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.payload['raw'] = update_params[:raw] if update_params[:raw].present?
|
|
|
|
if reviewable.topic_id.blank? && update_params[:state].blank?
|
|
|
|
reviewable.payload['title'] = update_params[:title] if update_params[:title].present?
|
|
|
|
reviewable.payload['tags'] = update_params[:tags]
|
|
|
|
reviewable.category_id = update_params[:category_id].to_i if update_params[:category_id].present?
|
2015-04-16 05:20:34 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.save(validate: false)
|
2017-08-16 00:44:05 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
state = update_params[:state]
|
2016-06-24 16:36:27 +08:00
|
|
|
begin
|
|
|
|
if state == 'approved'
|
2019-04-24 00:18:39 +08:00
|
|
|
reviewable.perform(current_user, :approve_post)
|
2016-06-24 16:36:27 +08:00
|
|
|
elsif state == 'rejected'
|
2019-04-24 00:18:39 +08:00
|
|
|
reviewable.perform(current_user, :reject_post)
|
2019-01-04 01:03:01 +08:00
|
|
|
if update_params[:delete_user] == 'true' && guardian.can_delete_user?(reviewable.created_by)
|
|
|
|
UserDestroyer.new(current_user).destroy(reviewable.created_by, user_deletion_opts)
|
2016-06-24 16:36:27 +08:00
|
|
|
end
|
2015-04-28 03:06:20 +08:00
|
|
|
end
|
2016-06-24 16:36:27 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
return render_json_error e.message
|
2015-04-15 02:21:02 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
render_serialized(reviewable, QueuedPostSerializer, root: :queued_posts)
|
2015-04-11 05:00:50 +08:00
|
|
|
end
|
|
|
|
|
2015-04-28 03:06:20 +08:00
|
|
|
private
|
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
def user_deletion_opts
|
|
|
|
base = {
|
2018-12-04 17:48:16 +08:00
|
|
|
context: I18n.t('queue.delete_reason', performed_by: current_user.username),
|
|
|
|
delete_posts: true,
|
2018-06-07 13:28:18 +08:00
|
|
|
delete_as_spammer: true
|
|
|
|
}
|
|
|
|
|
|
|
|
if Rails.env.production? && ENV["Staging"].nil?
|
|
|
|
base.merge!(block_email: true, block_ip: true)
|
2015-04-28 03:06:20 +08:00
|
|
|
end
|
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
base
|
|
|
|
end
|
|
|
|
|
2015-04-11 05:00:50 +08:00
|
|
|
end
|