2015-04-10 16:00:50 -05:00
|
|
|
require_dependency 'queued_post_serializer'
|
|
|
|
|
|
|
|
class QueuedPostsController < ApplicationController
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
before_action :ensure_staff
|
2015-04-10 16:00:50 -05:00
|
|
|
|
|
|
|
def index
|
2019-01-03 11:03:01 -06:00
|
|
|
Discourse.deprecate("QueuedPostController#index is deprecated. Please use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
|
2015-04-10 16:00:50 -05:00
|
|
|
|
2019-01-03 11:03:01 -06: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-27 12:52:37 -05:00
|
|
|
QueuedPostSerializer,
|
|
|
|
root: :queued_posts,
|
|
|
|
rest_serializer: true,
|
|
|
|
refresh_queued_posts: "/queued_posts?status=new")
|
2015-04-10 16:00:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-01-03 11:03:01 -06: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 07:15:29 -06:00
|
|
|
|
2017-08-15 11:44:05 -05:00
|
|
|
update_params = params[:queued_post]
|
|
|
|
|
2019-01-03 11:03:01 -06: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-15 16:20:34 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 11:03:01 -06:00
|
|
|
reviewable.save(validate: false)
|
2017-08-15 11:44:05 -05:00
|
|
|
|
2019-01-03 11:03:01 -06:00
|
|
|
state = update_params[:state]
|
2016-06-24 03:36:27 -05:00
|
|
|
begin
|
|
|
|
if state == 'approved'
|
2019-01-03 11:03:01 -06:00
|
|
|
reviewable.perform(current_user, :approve)
|
2016-06-24 03:36:27 -05:00
|
|
|
elsif state == 'rejected'
|
2019-01-03 11:03:01 -06:00
|
|
|
reviewable.perform(current_user, :reject)
|
|
|
|
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 03:36:27 -05:00
|
|
|
end
|
2015-04-27 14:06:20 -05:00
|
|
|
end
|
2016-06-24 03:36:27 -05:00
|
|
|
rescue StandardError => e
|
|
|
|
return render_json_error e.message
|
2015-04-14 13:21:02 -05:00
|
|
|
end
|
|
|
|
|
2019-01-03 11:03:01 -06:00
|
|
|
render_serialized(reviewable, QueuedPostSerializer, root: :queued_posts)
|
2015-04-10 16:00:50 -05:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:06:20 -05:00
|
|
|
private
|
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
def user_deletion_opts
|
|
|
|
base = {
|
2018-12-04 03:48:16 -06:00
|
|
|
context: I18n.t('queue.delete_reason', performed_by: current_user.username),
|
|
|
|
delete_posts: true,
|
2018-06-07 00:28:18 -05:00
|
|
|
delete_as_spammer: true
|
|
|
|
}
|
|
|
|
|
|
|
|
if Rails.env.production? && ENV["Staging"].nil?
|
|
|
|
base.merge!(block_email: true, block_ip: true)
|
2015-04-27 14:06:20 -05:00
|
|
|
end
|
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
base
|
|
|
|
end
|
|
|
|
|
2015-04-10 16:00:50 -05:00
|
|
|
end
|