2015-04-10 17:00:50 -04:00
|
|
|
require_dependency 'queued_post_serializer'
|
|
|
|
|
|
|
|
class QueuedPostsController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :ensure_staff
|
|
|
|
|
|
|
|
def index
|
|
|
|
state = QueuedPost.states[(params[:state] || 'new').to_sym]
|
|
|
|
state ||= QueuedPost.states[:new]
|
|
|
|
|
2015-09-18 13:11:42 -04:00
|
|
|
@queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user).order(:created_at)
|
2015-04-27 13:52:37 -04:00
|
|
|
render_serialized(@queued_posts,
|
|
|
|
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
|
|
|
|
qp = QueuedPost.where(id: params[:id]).first
|
2015-04-14 14:21:02 -04:00
|
|
|
|
2015-04-15 17:20:34 -04:00
|
|
|
if params[:queued_post][:raw].present?
|
|
|
|
qp.update_column(:raw, params[:queued_post][:raw])
|
|
|
|
end
|
|
|
|
|
2015-04-14 14:21:02 -04:00
|
|
|
state = params[:queued_post][:state]
|
2016-06-24 04:36:27 -04: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-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
|
|
|
|
|
2015-04-10 17:00:50 -04:00
|
|
|
render_serialized(qp, QueuedPostSerializer, root: :queued_posts)
|
|
|
|
end
|
|
|
|
|
2015-04-27 15:06:20 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_deletion_opts
|
|
|
|
base = {
|
|
|
|
context: I18n.t('queue.delete_reason', {performed_by: current_user.username}),
|
|
|
|
delete_posts: true,
|
|
|
|
delete_as_spammer: true
|
|
|
|
}
|
|
|
|
|
|
|
|
if Rails.env.production? && ENV["Staging"].nil?
|
|
|
|
base.merge!({block_email: true, block_ip: true})
|
|
|
|
end
|
|
|
|
|
|
|
|
base
|
|
|
|
end
|
|
|
|
|
2015-04-10 17:00:50 -04:00
|
|
|
end
|