From 6138825db6b1f2481413e7643c09c08748481934 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 12 Feb 2015 15:17:20 +1030 Subject: [PATCH] Only show reply button if user has permission --- ember/app/views/discussion.js | 5 ++++- .../Api/Serializers/DiscussionSerializer.php | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ember/app/views/discussion.js b/ember/app/views/discussion.js index a6bb21e642..446e228663 100644 --- a/ember/app/views/discussion.js +++ b/ember/app/views/discussion.js @@ -9,6 +9,8 @@ var $ = Ember.$; export default Ember.View.extend(HasItemLists, { itemLists: ['sidebar'], + discussion: Ember.computed.alias('controller.model'), + didInsertElement: function() { this.get('controller').on('loaded', this, this.loaded); this.get('controller').on('startWasChanged', this, this.startWasChanged); @@ -59,7 +61,8 @@ export default Ember.View.extend(HasItemLists, { populateControls: function(items) { var view = this; - this.addActionItem(items, 'reply', 'Reply').set('action', function() { + + this.addActionItem(items, 'reply', 'Reply', 'reply', 'discussion.canReply', function() { view.get('streamContent').send('goToLast'); view.get('controller').send('reply'); }); diff --git a/src/Flarum/Api/Serializers/DiscussionSerializer.php b/src/Flarum/Api/Serializers/DiscussionSerializer.php index 448a790973..0d8ce84b2f 100644 --- a/src/Flarum/Api/Serializers/DiscussionSerializer.php +++ b/src/Flarum/Api/Serializers/DiscussionSerializer.php @@ -19,7 +19,7 @@ class DiscussionSerializer extends DiscussionBasicSerializer /** * Serialize attributes of a Discussion model for JSON output. - * + * * @param Discussion $discussion The Discussion model to serialize. * @return array */ @@ -34,6 +34,7 @@ protected function attributes(Discussion $discussion) 'startTime' => $discussion->start_time->toRFC3339String(), 'lastTime' => $discussion->last_time ? $discussion->last_time->toRFC3339String() : null, 'lastPostNumber' => $discussion->last_post_number, + 'canReply' => $discussion->permission('reply'), 'canEdit' => $discussion->permission('edit'), 'canDelete' => $discussion->permission('delete'), @@ -46,7 +47,7 @@ protected function attributes(Discussion $discussion) /** * Get a collection containing a discussion's viewable post IDs. - * + * * @param Discussion $discussion * @return Tobscure\JsonApi\Collection */ @@ -58,7 +59,7 @@ public function linkPosts(Discussion $discussion) /** * Get a collection containing a discussion's viewable posts. Assumes that * the discussion model's posts attributes has been filled. - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Collection @@ -72,7 +73,7 @@ public function includePosts(Discussion $discussion, $relations) * Get a collection containing a discussion's relevant posts. Assumes that * the discussion model's relevantPosts attributes has been filled (this * happens in the DiscussionFinder.) - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Collection @@ -84,7 +85,7 @@ public function includeRelevantPosts(Discussion $discussion, $relations) /** * Get a resource containing a discussion's start user. - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Resource @@ -96,7 +97,7 @@ public function includeStartUser(Discussion $discussion, $relations) /** * Get a resource containing a discussion's starting post. - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Resource @@ -108,7 +109,7 @@ public function includeStartPost(Discussion $discussion, $relations) /** * Get a resource containing a discussion's last user. - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Resource @@ -120,7 +121,7 @@ public function includeLastUser(Discussion $discussion, $relations) /** * Get a resource containing a discussion's last post. - * + * * @param Discussion $discussion * @param array $relations * @return Tobscure\JsonApi\Resource