2015-04-11 05:00:50 +08: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-04-21 05:19:05 +08:00
|
|
|
@queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user)
|
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
|
|
|
|
2015-04-16 05:20:34 +08:00
|
|
|
if params[:queued_post][:raw].present?
|
|
|
|
qp.update_column(:raw, params[:queued_post][:raw])
|
|
|
|
end
|
|
|
|
|
2015-04-15 02:21:02 +08:00
|
|
|
state = params[:queued_post][:state]
|
|
|
|
if state == 'approved'
|
|
|
|
qp.approve!(current_user)
|
|
|
|
elsif state == 'rejected'
|
|
|
|
qp.reject!(current_user)
|
|
|
|
end
|
|
|
|
|
2015-04-11 05:00:50 +08:00
|
|
|
render_serialized(qp, QueuedPostSerializer, root: :queued_posts)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|