mirror of
https://github.com/flarum/framework.git
synced 2025-01-21 02:53:59 +08:00
Add sticky permission
This commit is contained in:
parent
5872e041df
commit
30d546383e
3
extensions/sticky/js/bootstrap.js
vendored
3
extensions/sticky/js/bootstrap.js
vendored
|
@ -19,6 +19,7 @@ app.initializers.add('sticky', function() {
|
||||||
app.notificationComponentRegistry['discussionStickied'] = NotificationDiscussionStickied;
|
app.notificationComponentRegistry['discussionStickied'] = NotificationDiscussionStickied;
|
||||||
|
|
||||||
Discussion.prototype.isSticky = Model.prop('isSticky');
|
Discussion.prototype.isSticky = Model.prop('isSticky');
|
||||||
|
Discussion.prototype.canSticky = Model.prop('canSticky');
|
||||||
|
|
||||||
// Add a sticky badge to discussions.
|
// Add a sticky badge to discussions.
|
||||||
extend(Discussion.prototype, 'badges', function(badges) {
|
extend(Discussion.prototype, 'badges', function(badges) {
|
||||||
|
@ -42,7 +43,7 @@ app.initializers.add('sticky', function() {
|
||||||
|
|
||||||
// Add a sticky control to discussions.
|
// Add a sticky control to discussions.
|
||||||
extend(Discussion.prototype, 'controls', function(items) {
|
extend(Discussion.prototype, 'controls', function(items) {
|
||||||
if (this.canEdit()) {
|
if (this.canSticky()) {
|
||||||
items.add('sticky', ActionButton.component({
|
items.add('sticky', ActionButton.component({
|
||||||
label: this.isSticky() ? 'Unsticky' : 'Sticky',
|
label: this.isSticky() ? 'Unsticky' : 'Sticky',
|
||||||
icon: 'thumb-tack',
|
icon: 'thumb-tack',
|
||||||
|
|
|
@ -18,6 +18,8 @@ class StickySaver
|
||||||
$discussion = $event->discussion;
|
$discussion = $event->discussion;
|
||||||
$user = $event->command->user;
|
$user = $event->command->user;
|
||||||
|
|
||||||
|
$discussion->assertCan($user, 'sticky');
|
||||||
|
|
||||||
if ((bool) $discussion->is_sticky === $isSticky) {
|
if ((bool) $discussion->is_sticky === $isSticky) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,15 @@ class StickyServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
$this->postType('Flarum\Sticky\DiscussionStickiedPost');
|
$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['isSticky'] = (bool) $model->is_sticky;
|
||||||
|
$attributes['canSticky'] = (bool) $model->can($serializer->actor->getUser(), 'sticky');
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->discussionGambit('Flarum\Sticky\StickyGambit');
|
$this->discussionGambit('Flarum\Sticky\StickyGambit');
|
||||||
|
|
||||||
$this->notificationType('Flarum\Sticky\DiscussionStickiedNotification', ['alert' => true]);
|
$this->notificationType('Flarum\Sticky\DiscussionStickiedNotification', ['alert' => true]);
|
||||||
|
|
||||||
|
$this->permission('discussion.sticky');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user