Add the posts that need to be reviewed to the hamburger

This commit is contained in:
Robin Ward 2015-04-10 16:29:13 -04:00
parent 7f501a0c41
commit f1ede42569
8 changed files with 44 additions and 5 deletions

View File

@ -99,6 +99,7 @@ HeaderController.reopenClass({
}); });
addFlagProperty('currentUser.site_flagged_posts_count'); addFlagProperty('currentUser.site_flagged_posts_count');
addFlagProperty('currentUser.post_queue_new_count');
export { addFlagProperty }; export { addFlagProperty };
export default HeaderController; export default HeaderController;

View File

@ -27,10 +27,13 @@ export default {
bus.callbackInterval = siteSettings.polling_interval; bus.callbackInterval = siteSettings.polling_interval;
bus.enableLongPolling = true; bus.enableLongPolling = true;
if (user.admin || user.moderator) { if (user.get('staff')) {
bus.subscribe('/flagged_counts', function(data) { bus.subscribe('/flagged_counts', (data) => {
user.set('site_flagged_posts_count', data.total); 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) { bus.subscribe("/notification/" + user.get('id'), (function(data) {
const oldUnread = user.get('unread_notifications'); const oldUnread = user.get('unread_notifications');

View File

@ -26,6 +26,17 @@
<li>{{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}</li> <li>{{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}</li>
{{/if}} {{/if}}
{{#if currentUser.staff}}
<li>
<a href="/queued-posts">
{{i18n "queue.title"}}
{{#if currentUser.post_queue_new_count}}
<span class='badge-notification flagged-posts'>{{currentUser.post_queue_new_count}}</span>
{{/if}}
</a>
</li>
{{/if}}
{{plugin-outlet "site-map-links"}} {{plugin-outlet "site-map-links"}}
{{#if showKeyboardShortcuts}} {{#if showKeyboardShortcuts}}

View File

@ -26,6 +26,15 @@ class QueuedPost < ActiveRecord::Base
@states ||= Enum.new(:new, :approved, :rejected) @states ||= Enum.new(:new, :approved, :rejected)
end 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) def reject!(rejected_by)
change_to!(:rejected, rejected_by) change_to!(:rejected, rejected_by)
end end
@ -73,6 +82,8 @@ class QueuedPost < ActiveRecord::Base
# Update the record in memory too, and clear the dirty flag # Update the record in memory too, and clear the dirty flag
updates.each {|k, v| send("#{k}=", v) } updates.each {|k, v| send("#{k}=", v) }
changes_applied changes_applied
QueuedPost.publish_new!
end end
end end

View File

@ -26,7 +26,8 @@ class CurrentUserSerializer < BasicUserSerializer
:custom_fields, :custom_fields,
:muted_category_ids, :muted_category_ids,
:dismissed_banner_key, :dismissed_banner_key,
:is_anonymous :is_anonymous,
:post_queue_new_count
def include_site_flagged_posts_count? def include_site_flagged_posts_count?
object.staff? object.staff?
@ -107,4 +108,12 @@ class CurrentUserSerializer < BasicUserSerializer
object.anonymous? object.anonymous?
end end
def post_queue_new_count
QueuedPost.new_count
end
def include_post_queue_new_count?
object.staff?
end
end end

View File

@ -226,6 +226,8 @@ en:
placeholder: "type the topic title here" placeholder: "type the topic title here"
queue: queue:
title: "Needs Approval"
approval: approval:
title: "Post Needs 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." description: "We've received your new post but it needs to be approved by a moderator before it will appear. Please be patient."

View File

@ -43,6 +43,8 @@ class NewPostManager
enqueuer = PostEnqueuer.new(@user, queue) enqueuer = PostEnqueuer.new(@user, queue)
post = enqueuer.enqueue(@args) post = enqueuer.enqueue(@args)
QueuedPost.publish_new! if post && post.errors.empty?
result.check_errors_from(enqueuer) result.check_errors_from(enqueuer)
result result
end end

View File

@ -52,7 +52,7 @@ describe NewPostManager do
expect(result).to be_success expect(result).to be_success
expect(result.post).to be_blank expect(result.post).to be_blank
expect(@counter).to be(1) expect(@counter).to be(1)
expect(QueuedPost.count).to be(0) expect(QueuedPost.new_count).to be(0)
end end
it "calls custom enqueuing handlers" do it "calls custom enqueuing handlers" do
@ -63,7 +63,7 @@ describe NewPostManager do
expect(result.action).to eq(:enqueued) expect(result.action).to eq(:enqueued)
expect(result).to be_success expect(result).to be_success
expect(result.post).to be_blank expect(result.post).to be_blank
expect(QueuedPost.count).to be(1) expect(QueuedPost.new_count).to be(1)
expect(@counter).to be(0) expect(@counter).to be(0)
end end