Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed May 26, 2024
1 parent 5c5f246 commit 3fc15b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
32 changes: 18 additions & 14 deletions app/Services/PersonalAccessTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ class PersonalAccessTokenService
public const GDAEMON_TASK_READ_ABILITY = 'admin:gdaemon-task:read';

// User abilities
public const SERVER_START_ABILITY = 'server:start';
public const SERVER_STOP_ABILITY = 'server:stop';
public const SERVER_RESTART_ABILITY = 'server:restart';
public const SERVER_UPDATE_ABILITY = 'server:update';
public const SERVER_CONSOLE_ABILITY = 'server:console';
public const SERVER_RCON_CONSOLE_ABILITY = 'server:rcon-console';
public const SERVER_RCON_PLAYERS_ABILITY = 'server:rcon-players';
public const SERVER_START_ABILITY = 'server:start';
public const SERVER_STOP_ABILITY = 'server:stop';
public const SERVER_RESTART_ABILITY = 'server:restart';
public const SERVER_UPDATE_ABILITY = 'server:update';
public const SERVER_CONSOLE_ABILITY = 'server:console';
public const SERVER_RCON_CONSOLE_ABILITY = 'server:rcon-console';
public const SERVER_RCON_PLAYERS_ABILITY = 'server:rcon-players';
public const SERVER_TASKS_MANAGE_ABILITY = 'server:tasks-manage';
public const SERVER_SETTINGS_MANAGE_ABILITY = 'server:settings-manage';

public function getGrouppedAbilitiesDescriptions(User $user): array
{
$userAbilities = [
'server' => [
self::SERVER_START_ABILITY => __('tokens.abilities_descriptions.server.start'),
self::SERVER_STOP_ABILITY => __('tokens.abilities_descriptions.server.stop'),
self::SERVER_RESTART_ABILITY => __('tokens.abilities_descriptions.server.restart'),
self::SERVER_UPDATE_ABILITY => __('tokens.abilities_descriptions.server.update'),
self::SERVER_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.console'),
self::SERVER_RCON_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.rcon-console'),
self::SERVER_RCON_PLAYERS_ABILITY => __('tokens.abilities_descriptions.server.rcon-players'),
self::SERVER_START_ABILITY => __('tokens.abilities_descriptions.server.start'),
self::SERVER_STOP_ABILITY => __('tokens.abilities_descriptions.server.stop'),
self::SERVER_RESTART_ABILITY => __('tokens.abilities_descriptions.server.restart'),
self::SERVER_UPDATE_ABILITY => __('tokens.abilities_descriptions.server.update'),
self::SERVER_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.console'),
self::SERVER_RCON_CONSOLE_ABILITY => __('tokens.abilities_descriptions.server.rcon-console'),
self::SERVER_RCON_PLAYERS_ABILITY => __('tokens.abilities_descriptions.server.rcon-players'),
self::SERVER_TASKS_MANAGE_ABILITY => __('tokens.abilities_descriptions.server.tasks-manage'),
self::SERVER_SETTINGS_MANAGE_ABILITY => __('tokens.abilities_descriptions.server.settings-manage'),
],
];

Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
'console' => 'Access to read and write into game server console',
'rcon-console' => 'Access to game server RCON console',
'rcon-players' => 'Access to players management on game server',
'tasks-manage' => 'Manage game server tasks',
'settings-manage' => 'Manage game server settings',
],
'gdaemon_task' => [
'read' => 'Read GameAP Daemon task',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/ru/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
'console' => 'Доступ к чтению и записи в консоль игрового сервера',
'rcon-console' => 'Доступ к RCON консоли игрового сервера',
'rcon-players' => 'Доступ к управлению игроками на игровом сервере',
'tasks-manage' => 'Управление заданиями игрового сервера',
'settings-manage' => 'Управление настройками игрового сервера',
],
'gdaemon_task' => [
'read' => 'Чтение заданий GameAP Daemon',
Expand Down
27 changes: 20 additions & 7 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,28 @@
->middleware('abilities:' . PersonalAccessTokenService::SERVER_CONSOLE_ABILITY);

Route::name('servers.send_command')
->post('servers/{server}/console', [ServersController::class, 'sendCommand']);
->post('servers/{server}/console', [ServersController::class, 'sendCommand'])
->middleware('abilities:' . PersonalAccessTokenService::SERVER_CONSOLE_ABILITY);

Route::name('servers.get_tasks')->get('servers/{server}/tasks', [ServersTasksController::class, 'getList']);
Route::name('servers.add_task')->post('servers/{server}/tasks', [ServersTasksController::class, 'store']);
Route::name('servers.update_task')->put('servers/{server}/tasks/{server_task}', [ServersTasksController::class, 'update']);
Route::name('servers.delete_task')->delete('servers/{server}/tasks/{server_task}', [ServersTasksController::class, 'destroy']);
// Tasks
Route::middleware('abilities:' . PersonalAccessTokenService::SERVER_TASKS_MANAGE_ABILITY)->group(function() {
Route::name('servers.get_tasks')
->get('servers/{server}/tasks', [ServersTasksController::class, 'getList']);
Route::name('servers.add_task')
->post('servers/{server}/tasks', [ServersTasksController::class, 'store']);
Route::name('servers.update_task')
->put('servers/{server}/tasks/{server_task}', [ServersTasksController::class, 'update']);
Route::name('servers.delete_task')
->delete('servers/{server}/tasks/{server_task}', [ServersTasksController::class, 'destroy']);
});

Route::name('servers.get_settings')->get('servers/{server}/settings', [ServersSettingsController::class, 'get']);
Route::name('servers.save_settings')->put('servers/{server}/settings', [ServersSettingsController::class, 'save']);
// Settings
Route::middleware('abilities:' . PersonalAccessTokenService::SERVER_SETTINGS_MANAGE_ABILITY)->group(function() {
Route::name('servers.get_settings')
->get('servers/{server}/settings', [ServersSettingsController::class, 'get']);
Route::name('servers.save_settings')
->put('servers/{server}/settings', [ServersSettingsController::class, 'save']);
});

// Rcon
Route::middleware('abilities:' . PersonalAccessTokenService::SERVER_RCON_CONSOLE_ABILITY)->group(function() {
Expand Down

0 comments on commit 3fc15b5

Please sign in to comment.