Add sticky permission

This commit is contained in:
Toby Zerner 2015-05-15 17:06:50 +09:30
parent 5872e041df
commit 30d546383e
3 changed files with 8 additions and 2 deletions

View File

@ -19,6 +19,7 @@ app.initializers.add('sticky', function() {
app.notificationComponentRegistry['discussionStickied'] = NotificationDiscussionStickied;
Discussion.prototype.isSticky = Model.prop('isSticky');
Discussion.prototype.canSticky = Model.prop('canSticky');
// Add a sticky badge to discussions.
extend(Discussion.prototype, 'badges', function(badges) {
@ -42,7 +43,7 @@ app.initializers.add('sticky', function() {
// Add a sticky control to discussions.
extend(Discussion.prototype, 'controls', function(items) {
if (this.canEdit()) {
if (this.canSticky()) {
items.add('sticky', ActionButton.component({
label: this.isSticky() ? 'Unsticky' : 'Sticky',
icon: 'thumb-tack',

View File

@ -18,6 +18,8 @@ class StickySaver
$discussion = $event->discussion;
$user = $event->command->user;
$discussion->assertCan($user, 'sticky');
if ((bool) $discussion->is_sticky === $isSticky) {
return;
}

View File

@ -23,12 +23,15 @@ class StickyServiceProvider extends ServiceProvider
$this->postType('Flarum\Sticky\DiscussionStickiedPost');
$this->serializeAttributes('Flarum\Api\Serializers\DiscussionSerializer', function (&$attributes, $model) {
$this->serializeAttributes('Flarum\Api\Serializers\DiscussionSerializer', function (&$attributes, $model, $serializer) {
$attributes['isSticky'] = (bool) $model->is_sticky;
$attributes['canSticky'] = (bool) $model->can($serializer->actor->getUser(), 'sticky');
});
$this->discussionGambit('Flarum\Sticky\StickyGambit');
$this->notificationType('Flarum\Sticky\DiscussionStickiedNotification', ['alert' => true]);
$this->permission('discussion.sticky');
}
}