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
|
|
|
public const SERVER_TASKS_MANAGE_ABILITY = 'server:tasks-manage'; |
23
|
|
|
public const SERVER_SETTINGS_MANAGE_ABILITY = 'server:settings-manage'; |
24
|
|
|
|
25
|
|
|
public function getGrouppedAbilitiesDescriptions(User $user): array |
26
|
|
|
{ |
27
|
|
|
$userAbilities = [ |
28
|
|
|
'server' => [ |
29
|
|
|
self::SERVER_START_ABILITY => __('tokens.abilities_descriptions.server.start'), |
30
|
|
|
self::SERVER_STOP_ABILITY => __('tokens.abilities_descriptions.server.stop'), |
31
|
|
|
self::SERVER_RESTART_ABILITY => __('tokens.abilities_descriptions.server.restart'), |
32
|
|
|
self::SERVER_UPDATE_ABILITY => __('tokens.abilities_descriptions.server.update'), |
33
|
|
|
self::SERVER_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.console'), |
34
|
|
|
self::SERVER_RCON_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.rcon-console'), |
35
|
|
|
self::SERVER_RCON_PLAYERS_ABILITY => __('tokens.abilities_descriptions.server.rcon-players'), |
36
|
|
|
self::SERVER_TASKS_MANAGE_ABILITY => __('tokens.abilities_descriptions.server.tasks-manage'), |
37
|
|
|
self::SERVER_SETTINGS_MANAGE_ABILITY => __('tokens.abilities_descriptions.server.settings-manage'), |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
if ($user->can(PermissionHelper::ADMIN_PERMISSIONS)) { |
42
|
|
|
$userAbilities['server'][self::SERVER_CREATE_ABILITY] = __('tokens.abilities_descriptions.server.create'); |
43
|
|
|
$userAbilities['gdaemon-task'][self::GDAEMON_TASK_READ_ABILITY] = __('tokens.abilities_descriptions.gdaemon_task.read'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $userAbilities; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|