Skip to content

Commit

Permalink
Only show reply button if user has permission
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Feb 12, 2015
1 parent 1a11194 commit 6138825
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 4 additions & 1 deletion ember/app/views/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
});
Expand Down
17 changes: 9 additions & 8 deletions src/Flarum/Api/Serializers/DiscussionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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'),

Expand All @@ -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
*/
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6138825

Please sign in to comment.