|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Gameap\Helpers\PermissionHelper; |
|
6
|
|
|
use Gameap\Models\User; |
|
7
|
|
|
|
|
8
|
|
|
class PersonalAccessTokenService |
|
9
|
|
|
{ |
|
10
|
|
|
// Admin abilities |
|
11
|
|
|
public const SERVER_CREATE_ABILITY = 'admin:server:create'; |
|
12
|
|
|
public const GDAEMON_TASK_READ_ABILITY = 'admin:gdaemon-task:read'; |
|
13
|
|
|
|
|
14
|
|
|
// User abilities |
|
15
|
|
|
public const SERVER_START_ABILITY = 'server:start'; |
|
16
|
|
|
public const SERVER_STOP_ABILITY = 'server:stop'; |
|
17
|
|
|
public const SERVER_RESTART_ABILITY = 'server:restart'; |
|
18
|
|
|
public const SERVER_UPDATE_ABILITY = 'server:update'; |
|
19
|
|
|
public const SERVER_CONSOLE_ABILITY = 'server:console'; |
|
20
|
|
|
public const SERVER_RCON_CONSOLE_ABILITY = 'server:rcon-console'; |
|
21
|
|
|
public const SERVER_RCON_PLAYERS_ABILITY = 'server:rcon-players'; |
|
22
|
|
|
|
|
23
|
|
|
public function getGrouppedAbilitiesDescriptions(User $user): array |
|
24
|
|
|
{ |
|
25
|
|
|
$userAbilities = [ |
|
26
|
|
|
'server' => [ |
|
27
|
|
|
self::SERVER_START_ABILITY => __('tokens.abilities_descriptions.server.start'), |
|
28
|
|
|
self::SERVER_STOP_ABILITY => __('tokens.abilities_descriptions.server.stop'), |
|
29
|
|
|
self::SERVER_RESTART_ABILITY => __('tokens.abilities_descriptions.server.restart'), |
|
30
|
|
|
self::SERVER_UPDATE_ABILITY => __('tokens.abilities_descriptions.server.update'), |
|
31
|
|
|
self::SERVER_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.console'), |
|
32
|
|
|
self::SERVER_RCON_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.rcon-console'), |
|
33
|
|
|
self::SERVER_RCON_PLAYERS_ABILITY => __('tokens.abilities_descriptions.server.rcon-players'), |
|
34
|
|
|
], |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
if ($user->can(PermissionHelper::ADMIN_PERMISSIONS)) { |
|
38
|
|
|
$userAbilities['server'][self::SERVER_CREATE_ABILITY] = __('tokens.abilities_descriptions.server.create'); |
|
39
|
|
|
$userAbilities['gdaemon-task'][self::GDAEMON_TASK_READ_ABILITY] = __('tokens.abilities_descriptions.gdaemon_task.read'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $userAbilities; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|