Adds support for invisible approval queues, which we'll need for Akismet

This commit is contained in:
Robin Ward 2015-04-20 17:19:05 -04:00
parent 66be9147a0
commit 2cdd967188
4 changed files with 34 additions and 4 deletions

View File

@ -8,7 +8,7 @@ class QueuedPostsController < ApplicationController
state = QueuedPost.states[(params[:state] || 'new').to_sym] state = QueuedPost.states[(params[:state] || 'new').to_sym]
state ||= QueuedPost.states[:new] state ||= QueuedPost.states[:new]
@queued_posts = QueuedPost.where(state: state).includes(:topic, :user) @queued_posts = QueuedPost.visible.where(state: state).includes(:topic, :user)
render_serialized(@queued_posts, QueuedPostSerializer, root: :queued_posts, rest_serializer: true) render_serialized(@queued_posts, QueuedPostSerializer, root: :queued_posts, rest_serializer: true)
end end

View File

@ -11,8 +11,21 @@ class QueuedPost < ActiveRecord::Base
@states ||= Enum.new(:new, :approved, :rejected) @states ||= Enum.new(:new, :approved, :rejected)
end end
# By default queues are hidden from moderators
def self.visible_queues
@visible_queues ||= Set.new(['default'])
end
def self.visible
where(queue: visible_queues.to_a)
end
def self.new_count def self.new_count
where(state: states[:new]).count visible.where(state: states[:new]).count
end
def visible?
QueuedPost.visible_queues.include?(queue)
end end
def self.broadcast_new! def self.broadcast_new!
@ -63,7 +76,7 @@ class QueuedPost < ActiveRecord::Base
updates.each {|k, v| send("#{k}=", v) } updates.each {|k, v| send("#{k}=", v) }
changes_applied changes_applied
QueuedPost.broadcast_new! QueuedPost.broadcast_new! if visible?
end end
end end

View File

@ -68,7 +68,7 @@ describe NewPostManager do
result result
end end
@queue_handler = -> (manager) { manager.args[:raw] =~ /queue me/ ? manager.enqueue('new_topic') : nil } @queue_handler = -> (manager) { manager.args[:raw] =~ /queue me/ ? manager.enqueue('default') : nil }
NewPostManager.add_handler(&@counter_handler) NewPostManager.add_handler(&@counter_handler)
NewPostManager.add_handler(&@queue_handler) NewPostManager.add_handler(&@queue_handler)

View File

@ -109,4 +109,21 @@ describe QueuedPost do
end end
end end
context "visibility" do
it "works as expected in the invisible queue" do
qp = Fabricate(:queued_post, queue: 'invisible')
expect(qp).to_not be_visible
expect(QueuedPost.visible).to_not include(qp)
expect(QueuedPost.new_count).to eq(0)
end
it "works as expected in the visible queue" do
qp = Fabricate(:queued_post, queue: 'default')
expect(qp).to be_visible
expect(QueuedPost.visible).to include(qp)
expect(QueuedPost.new_count).to eq(1)
end
end
end end