From c2f76763701cda351288e0d9ebd2826fb2951102 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 28 Apr 2015 15:06:27 -0400 Subject: [PATCH] Support for custom reasons for things being queued for approval --- .../javascripts/discourse/controllers/composer.js.es6 | 2 +- .../discourse/controllers/post-enqueued.js.es6 | 7 ++++++- .../javascripts/discourse/routes/application.js.es6 | 3 ++- .../discourse/templates/modal/post-enqueued.hbs | 2 +- app/serializers/new_post_result_serializer.rb | 11 ++++++++++- lib/new_post_manager.rb | 3 ++- lib/new_post_result.rb | 2 ++ 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index bdbe52b9c..6f1ec69eb 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -228,7 +228,7 @@ export default DiscourseController.extend({ }).then(function(result) { if (result.responseJson.action === "enqueued") { - self.send('postWasEnqueued', {pending_count: result.responseJson.pending_count }); + self.send('postWasEnqueued', result.responseJson); self.destroyDraft(); self.close(); return result; diff --git a/app/assets/javascripts/discourse/controllers/post-enqueued.js.es6 b/app/assets/javascripts/discourse/controllers/post-enqueued.js.es6 index 77c79b724..5cb644f22 100644 --- a/app/assets/javascripts/discourse/controllers/post-enqueued.js.es6 +++ b/app/assets/javascripts/discourse/controllers/post-enqueued.js.es6 @@ -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'); + }) +}); diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index 55967c0db..03e1c453c 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -38,7 +38,8 @@ const ApplicationRoute = Discourse.Route.extend({ }, 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) { diff --git a/app/assets/javascripts/discourse/templates/modal/post-enqueued.hbs b/app/assets/javascripts/discourse/templates/modal/post-enqueued.hbs index ad547994a..1ebdd0c4c 100644 --- a/app/assets/javascripts/discourse/templates/modal/post-enqueued.hbs +++ b/app/assets/javascripts/discourse/templates/modal/post-enqueued.hbs @@ -1,5 +1,5 @@ diff --git a/app/serializers/new_post_result_serializer.rb b/app/serializers/new_post_result_serializer.rb index da3b7285e..068f3a9c9 100644 --- a/app/serializers/new_post_result_serializer.rb +++ b/app/serializers/new_post_result_serializer.rb @@ -5,7 +5,8 @@ class NewPostResultSerializer < ApplicationSerializer :post, :errors, :success, - :pending_count + :pending_count, + :reason def post post_serializer = PostSerializer.new(object.post, scope: scope, root: false) @@ -33,6 +34,14 @@ class NewPostResultSerializer < ApplicationSerializer !object.errors.empty? end + def reason + object.reason + end + + def include_reason? + reason.present? + end + def action object.action end diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 9ada9820a..03fc09e9b 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -60,7 +60,7 @@ class NewPostManager end # Enqueue this post in a queue - def enqueue(queue) + def enqueue(queue, reason=nil) result = NewPostResult.new(:enqueued) enqueuer = PostEnqueuer.new(@user, queue) @@ -73,6 +73,7 @@ class NewPostManager QueuedPost.broadcast_new! if post && post.errors.empty? result.queued_post = post + result.reason = reason if reason result.check_errors_from(enqueuer) result.pending_count = QueuedPost.new_posts.where(user_id: @user.id).count result diff --git a/lib/new_post_result.rb b/lib/new_post_result.rb index 938513078..63acab0b0 100644 --- a/lib/new_post_result.rb +++ b/lib/new_post_result.rb @@ -4,6 +4,8 @@ class NewPostResult include HasErrors attr_reader :action + + attr_accessor :reason attr_accessor :post attr_accessor :queued_post attr_accessor :pending_count