mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
Adds support for invisible approval queues, which we'll need for Akismet
This commit is contained in:
parent
66be9147a0
commit
2cdd967188
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user