mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Add suspend permission; don't let admins be suspended
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
import PermissionGrid from 'flarum/components/PermissionGrid';
|
||||
|
||||
app.initializers.add('suspend', () => {
|
||||
// TODO
|
||||
extend(PermissionGrid.prototype, 'moderateItems', items => {
|
||||
items.add('suspendUsers', {
|
||||
label: 'Suspend users',
|
||||
permission: 'user.suspend'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,9 @@
|
||||
<?php namespace Flarum\Suspend\Listeners;
|
||||
|
||||
use Flarum\Events\UserWillBeSaved;
|
||||
use Flarum\Events\ModelAllow;
|
||||
use Flarum\Events\GetUserGroups;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Groups\Group;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@@ -10,6 +12,7 @@ class PersistData
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen(UserWillBeSaved::class, [$this, 'whenUserWillBeSaved']);
|
||||
$events->listen(ModelAllow::class, [$this, 'disallowAdminSuspension']);
|
||||
$events->listen(GetUserGroups::class, [$this, 'revokePermissions']);
|
||||
}
|
||||
|
||||
@@ -28,6 +31,15 @@ class PersistData
|
||||
}
|
||||
}
|
||||
|
||||
public function disallowAdminSuspension(ModelAllow $event)
|
||||
{
|
||||
if ($event->model instanceof User && $event->action === 'suspend') {
|
||||
if ($event->model->isAdmin() || $event->model->id === $event->actor->id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function revokePermissions(GetUserGroups $event)
|
||||
{
|
||||
$suspendUntil = $event->user->suspend_until;
|
||||
|
Reference in New Issue
Block a user