diff --git a/app/assets/javascripts/discourse/controllers/header.js.es6 b/app/assets/javascripts/discourse/controllers/header.js.es6 index 74e2e133ce5..c0c4cb17dd5 100644 --- a/app/assets/javascripts/discourse/controllers/header.js.es6 +++ b/app/assets/javascripts/discourse/controllers/header.js.es6 @@ -99,6 +99,7 @@ HeaderController.reopenClass({ }); addFlagProperty('currentUser.site_flagged_posts_count'); +addFlagProperty('currentUser.post_queue_new_count'); export { addFlagProperty }; export default HeaderController; diff --git a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 index 9689614dde8..bb808e5c287 100644 --- a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 +++ b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 @@ -27,10 +27,13 @@ export default { bus.callbackInterval = siteSettings.polling_interval; bus.enableLongPolling = true; - if (user.admin || user.moderator) { - bus.subscribe('/flagged_counts', function(data) { + if (user.get('staff')) { + bus.subscribe('/flagged_counts', (data) => { user.set('site_flagged_posts_count', data.total); }); + bus.subscribe('/queue_counts', (data) => { + user.set('post_queue_new_count', data.post_queue_new_count); + }); } bus.subscribe("/notification/" + user.get('id'), (function(data) { const oldUnread = user.get('unread_notifications'); diff --git a/app/assets/javascripts/discourse/templates/site-map.hbs b/app/assets/javascripts/discourse/templates/site-map.hbs index c781c3a91d9..0bbe1dd96d6 100644 --- a/app/assets/javascripts/discourse/templates/site-map.hbs +++ b/app/assets/javascripts/discourse/templates/site-map.hbs @@ -26,6 +26,17 @@
  • {{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}
  • {{/if}} + {{#if currentUser.staff}} +
  • + + {{i18n "queue.title"}} + {{#if currentUser.post_queue_new_count}} + {{currentUser.post_queue_new_count}} + {{/if}} + +
  • + {{/if}} + {{plugin-outlet "site-map-links"}} {{#if showKeyboardShortcuts}} diff --git a/app/models/queued_post.rb b/app/models/queued_post.rb index 2b1cdacaf25..03d5e352a68 100644 --- a/app/models/queued_post.rb +++ b/app/models/queued_post.rb @@ -26,6 +26,15 @@ class QueuedPost < ActiveRecord::Base @states ||= Enum.new(:new, :approved, :rejected) end + def self.new_count + where(state: states[:new]).count + end + + def self.publish_new! + msg = { post_queue_new_count: QueuedPost.new_count } + MessageBus.publish('/queue_counts', msg, user_ids: User.staff.pluck(:id)) + end + def reject!(rejected_by) change_to!(:rejected, rejected_by) end @@ -73,6 +82,8 @@ class QueuedPost < ActiveRecord::Base # Update the record in memory too, and clear the dirty flag updates.each {|k, v| send("#{k}=", v) } changes_applied + + QueuedPost.publish_new! end end diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index e8b3e717a2d..7784d3545b7 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -26,7 +26,8 @@ class CurrentUserSerializer < BasicUserSerializer :custom_fields, :muted_category_ids, :dismissed_banner_key, - :is_anonymous + :is_anonymous, + :post_queue_new_count def include_site_flagged_posts_count? object.staff? @@ -107,4 +108,12 @@ class CurrentUserSerializer < BasicUserSerializer object.anonymous? end + def post_queue_new_count + QueuedPost.new_count + end + + def include_post_queue_new_count? + object.staff? + end + end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 6e2a443695e..cbfa19f3a5d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -226,6 +226,8 @@ en: placeholder: "type the topic title here" queue: + title: "Needs Approval" + approval: title: "Post Needs Approval" description: "We've received your new post but it needs to be approved by a moderator before it will appear. Please be patient." diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 323acaa7ed8..f892dcbb6b0 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -43,6 +43,8 @@ class NewPostManager enqueuer = PostEnqueuer.new(@user, queue) post = enqueuer.enqueue(@args) + QueuedPost.publish_new! if post && post.errors.empty? + result.check_errors_from(enqueuer) result end diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index 523d8652a03..78bc1250603 100644 --- a/spec/components/new_post_manager_spec.rb +++ b/spec/components/new_post_manager_spec.rb @@ -52,7 +52,7 @@ describe NewPostManager do expect(result).to be_success expect(result.post).to be_blank expect(@counter).to be(1) - expect(QueuedPost.count).to be(0) + expect(QueuedPost.new_count).to be(0) end it "calls custom enqueuing handlers" do @@ -63,7 +63,7 @@ describe NewPostManager do expect(result.action).to eq(:enqueued) expect(result).to be_success expect(result.post).to be_blank - expect(QueuedPost.count).to be(1) + expect(QueuedPost.new_count).to be(1) expect(@counter).to be(0) end