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
|
|
|
|
state = QueuedPost.states[(params[:state] || 'new').to_sym]
|
|
|
|
state ||= QueuedPost.states[:new]
|
|
|
|
|
2015-09-19 01:11:42 +08:00
|
|
|
@queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user).order(:created_at)
|
2015-04-28 01:52:37 +08:00
|
|
|
render_serialized(@queued_posts,
|
|
|
|
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
|
|
|
|
qp = QueuedPost.where(id: params[:id]).first
|
2015-04-15 02:21:02 +08:00
|
|
|
|
2017-11-27 21:15:29 +08:00
|
|
|
return render_json_error I18n.t('queue.not_found') if qp.blank?
|
|
|
|
|
2017-08-16 00:44:05 +08:00
|
|
|
update_params = params[:queued_post]
|
|
|
|
|
|
|
|
qp.raw = update_params[:raw] if update_params[:raw].present?
|
2018-06-26 19:29:33 +08:00
|
|
|
if qp.topic_id.blank? && params[:queued_post][:state].blank?
|
2017-08-16 00:44:05 +08:00
|
|
|
qp.post_options['title'] = update_params[:title] if update_params[:title].present?
|
|
|
|
qp.post_options['category'] = update_params[:category_id].to_i if update_params[:category_id].present?
|
2018-06-26 19:29:33 +08:00
|
|
|
qp.post_options['tags'] = update_params[:tags]
|
2015-04-16 05:20:34 +08:00
|
|
|
end
|
|
|
|
|
2017-08-16 00:44:05 +08:00
|
|
|
qp.save(validate: false)
|
|
|
|
|
2015-04-15 02:21:02 +08:00
|
|
|
state = params[:queued_post][:state]
|
2016-06-24 16:36:27 +08:00
|
|
|
begin
|
|
|
|
if state == 'approved'
|
|
|
|
qp.approve!(current_user)
|
|
|
|
elsif state == 'rejected'
|
|
|
|
qp.reject!(current_user)
|
|
|
|
if params[:queued_post][:delete_user] == 'true' && guardian.can_delete_user?(qp.user)
|
|
|
|
UserDestroyer.new(current_user).destroy(qp.user, user_deletion_opts)
|
|
|
|
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
|
|
|
|
|
2015-04-11 05:00:50 +08:00
|
|
|
render_serialized(qp, QueuedPostSerializer, root: :queued_posts)
|
|
|
|
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
|