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