From 26693c16ac1f3362a8305bba7db72beb9db4d45a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 21 Apr 2015 13:59:57 -0400 Subject: [PATCH] Don't show the link to "Needs Approval" unless approval is enabled. Note that any plugin that extends the NewPostMananger to support enqueuing will enable it. --- .../javascripts/discourse/templates/site-map.hbs | 4 ++-- app/serializers/current_user_serializer.rb | 13 ++++++++++++- lib/new_post_manager.rb | 6 ++++++ spec/components/new_post_manager_spec.rb | 7 +++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/site-map.hbs b/app/assets/javascripts/discourse/templates/site-map.hbs index 5efeea4c9..c4e4b4577 100644 --- a/app/assets/javascripts/discourse/templates/site-map.hbs +++ b/app/assets/javascripts/discourse/templates/site-map.hbs @@ -30,12 +30,12 @@
  • {{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}
  • {{/if}} - {{#if currentUser.staff}} + {{#if currentUser.show_queued_posts}}
  • {{#link-to 'queued-posts'}} {{i18n "queue.title"}} {{#if currentUser.post_queue_new_count}} - {{currentUser.post_queue_new_count}} + {{currentUser.post_queue_new_count}} {{/if}} {{/link-to}}
  • diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index 7784d3545..2a310295e 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -1,3 +1,5 @@ +require_dependency 'new_post_manager' + class CurrentUserSerializer < BasicUserSerializer attributes :name, @@ -27,7 +29,8 @@ class CurrentUserSerializer < BasicUserSerializer :muted_category_ids, :dismissed_banner_key, :is_anonymous, - :post_queue_new_count + :post_queue_new_count, + :show_queued_posts def include_site_flagged_posts_count? object.staff? @@ -116,4 +119,12 @@ class CurrentUserSerializer < BasicUserSerializer object.staff? end + def show_queued_posts + true + end + + def include_show_queued_posts? + object.staff? && NewPostManager.queue_enabled? + end + end diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index a8c4554fd..cc3e7c01f 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -26,6 +26,12 @@ class NewPostManager end end + def self.queue_enabled? + SiteSetting.approve_post_count > 0 || + SiteSetting.approve_unless_trust_level.to_i > 0 || + handlers.size > 1 + end + add_handler {|manager| default_handler(manager) } def initialize(user, args) diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index 5d0dfb747..ebc8ae5ec 100644 --- a/spec/components/new_post_manager_spec.rb +++ b/spec/components/new_post_manager_spec.rb @@ -28,6 +28,7 @@ describe NewPostManager do it "doesn't return a result action" do result = NewPostManager.default_handler(manager) + expect(NewPostManager.queue_enabled?).to eq(false) expect(result).to eq(nil) end end @@ -38,6 +39,7 @@ describe NewPostManager do end it "will return an enqueue result" do result = NewPostManager.default_handler(manager) + expect(NewPostManager.queue_enabled?).to eq(true) expect(result.action).to eq(:enqueued) end end @@ -48,6 +50,7 @@ describe NewPostManager do end it "will return an enqueue result" do result = NewPostManager.default_handler(manager) + expect(NewPostManager.queue_enabled?).to eq(true) expect(result.action).to eq(:enqueued) end end @@ -79,6 +82,10 @@ describe NewPostManager do NewPostManager.handlers.delete(@queue_handler) end + it "has a queue enabled" do + expect(NewPostManager.queue_enabled?).to eq(true) + end + it "calls custom handlers" do manager = NewPostManager.new(topic.user, raw: 'this post increases counter', topic_id: topic.id)