discourse/app/controllers/queued_posts_controller.rb

73 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-04-11 05:00:50 +08:00
require_dependency 'queued_post_serializer'
class QueuedPostsController < ApplicationController
before_action :ensure_staff
2015-04-11 05:00:50 +08:00
def index
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
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
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?
update_params = params[:queued_post]
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?
end
reviewable.save(validate: false)
state = update_params[:state]
begin
if state == 'approved'
reviewable.perform(current_user, :approve_post)
elsif state == 'rejected'
reviewable.perform(current_user, :reject_post)
if update_params[:delete_user] == 'true' && guardian.can_delete_user?(reviewable.created_by)
UserDestroyer.new(current_user).destroy(reviewable.created_by, user_deletion_opts)
end
end
rescue StandardError => e
return render_json_error e.message
end
render_serialized(reviewable, QueuedPostSerializer, root: :queued_posts)
2015-04-11 05:00:50 +08:00
end
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)
end
2018-06-07 13:28:18 +08:00
base
end
2015-04-11 05:00:50 +08:00
end