Support for custom reasons for things being queued for approval

This commit is contained in:
Robin Ward 2015-04-28 15:06:27 -04:00
parent cf0c2d09d4
commit c2f7676370
7 changed files with 24 additions and 6 deletions

View File

@ -228,7 +228,7 @@ export default DiscourseController.extend({
}).then(function(result) { }).then(function(result) {
if (result.responseJson.action === "enqueued") { if (result.responseJson.action === "enqueued") {
self.send('postWasEnqueued', {pending_count: result.responseJson.pending_count }); self.send('postWasEnqueued', result.responseJson);
self.destroyDraft(); self.destroyDraft();
self.close(); self.close();
return result; return result;

View File

@ -1 +1,6 @@
export default Ember.Controller.extend(); export default Ember.Controller.extend({
description: Ember.computed('model.reason', function() {
const reason = this.get('model.reason');
return reason ? I18n.t('queue_reason.' + reason + '.description') : I18n.t('queue.approval.description');
})
});

View File

@ -38,7 +38,8 @@ const ApplicationRoute = Discourse.Route.extend({
}, },
postWasEnqueued(details) { postWasEnqueued(details) {
showModal('post-enqueued', {model: details, title: 'queue.approval.title' }); const title = details.reason ? 'queue_reason.' + details.reason + '.title' : 'queue.approval.title';
showModal('post-enqueued', {model: details, title });
}, },
composePrivateMessage(user, post) { composePrivateMessage(user, post) {

View File

@ -1,5 +1,5 @@
<div class="modal-body"> <div class="modal-body">
<p>{{i18n "queue.approval.description"}}</p> <p>{{{description}}}</p>
<p>{{{i18n "queue.approval.pending_posts" count=model.pending_count}}} <p>{{{i18n "queue.approval.pending_posts" count=model.pending_count}}}
</div> </div>

View File

@ -5,7 +5,8 @@ class NewPostResultSerializer < ApplicationSerializer
:post, :post,
:errors, :errors,
:success, :success,
:pending_count :pending_count,
:reason
def post def post
post_serializer = PostSerializer.new(object.post, scope: scope, root: false) post_serializer = PostSerializer.new(object.post, scope: scope, root: false)
@ -33,6 +34,14 @@ class NewPostResultSerializer < ApplicationSerializer
!object.errors.empty? !object.errors.empty?
end end
def reason
object.reason
end
def include_reason?
reason.present?
end
def action def action
object.action object.action
end end

View File

@ -60,7 +60,7 @@ class NewPostManager
end end
# Enqueue this post in a queue # Enqueue this post in a queue
def enqueue(queue) def enqueue(queue, reason=nil)
result = NewPostResult.new(:enqueued) result = NewPostResult.new(:enqueued)
enqueuer = PostEnqueuer.new(@user, queue) enqueuer = PostEnqueuer.new(@user, queue)
@ -73,6 +73,7 @@ class NewPostManager
QueuedPost.broadcast_new! if post && post.errors.empty? QueuedPost.broadcast_new! if post && post.errors.empty?
result.queued_post = post result.queued_post = post
result.reason = reason if reason
result.check_errors_from(enqueuer) result.check_errors_from(enqueuer)
result.pending_count = QueuedPost.new_posts.where(user_id: @user.id).count result.pending_count = QueuedPost.new_posts.where(user_id: @user.id).count
result result

View File

@ -4,6 +4,8 @@ class NewPostResult
include HasErrors include HasErrors
attr_reader :action attr_reader :action
attr_accessor :reason
attr_accessor :post attr_accessor :post
attr_accessor :queued_post attr_accessor :queued_post
attr_accessor :pending_count attr_accessor :pending_count