-
-
Notifications
You must be signed in to change notification settings - Fork 866
Expand file tree
/
Copy pathUserResourceFields.php
More file actions
35 lines (31 loc) · 1.13 KB
/
UserResourceFields.php
File metadata and controls
35 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Suspend\Api;
use Flarum\Api\Context;
use Flarum\Api\Schema;
use Flarum\User\User;
class UserResourceFields
{
public function __invoke(): array
{
return [
Schema\Boolean::make('canSuspend')
->get($canSuspend = fn (User $user, Context $context) => $context->getActor()->can('suspend', $user)),
Schema\Str::make('suspendReason')
->writable($canSuspend)
->visible($canSuspend),
Schema\Str::make('suspendMessage')
->writable($canSuspend)
->visible(fn (User $user, Context $context) => $context->getActor()->id === $user->id || $canSuspend($user, $context)),
Schema\DateTime::make('suspendedUntil')
->writable($canSuspend)
->visible(fn (User $user, Context $context) => $context->getActor()->id === $user->id || $canSuspend($user, $context))
->nullable(),
];
}
}