Skip to content

Commit d39a0c4

Browse files
authored
Allow to add translation prefix to custom subuser permissions (#2265)
1 parent 2e48095 commit d39a0c4

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

app/Filament/Server/Resources/Subusers/SubuserResource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public static function defaultTable(Table $table): Table
7979

8080
foreach ($data['permissions'] as $permission) {
8181
$options[$permission] = str($permission)->headline();
82-
$descriptions[$permission] = trans('server/user.permissions.' . $data['name'] . '_' . str($permission)->replace('-', '_'));
82+
$descriptions[$permission] = trans($data['translation_prefix']. '.' . $data['name'] . '_' . str($permission)->replace('-', '_'));
8383
$permissionsArray[$data['name']][] = $permission;
8484
}
8585

8686
$tabs[] = Tab::make($data['name'])
87-
->label(str($data['name'])->headline())
87+
->label(trans($data['translation_prefix']. '.' . $data['name'] . '_title'))
8888
->schema([
8989
Section::make()
90-
->description(trans('server/user.permissions.' . $data['name'] . '_desc'))
90+
->description(trans($data['translation_prefix']. '.' . $data['name'] . '_desc'))
9191
->icon($data['icon'])
9292
->contained(false)
9393
->schema([

app/Models/Subuser.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Contracts\Validatable;
66
use App\Enums\SubuserPermission;
77
use App\Traits\HasValidation;
8+
use BackedEnum;
89
use Illuminate\Database\Eloquent\Factories\HasFactory;
910
use Illuminate\Database\Eloquent\Model;
1011
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -44,17 +45,21 @@ class Subuser extends Model implements Validatable
4445
*/
4546
public const RESOURCE_NAME = 'server_subuser';
4647

47-
/** @var array<string, array{name: string, hidden: ?bool, icon: ?string, permissions: string[]}> */
48+
/** @var array<string, array{name: string, hidden: ?bool, icon: null|string|BackedEnum, translation_prefix: ?string, permissions: string[]}> */
4849
protected static array $customPermissions = [];
4950

5051
/** @param string[] $permissions */
51-
public static function registerCustomPermissions(string $name, array $permissions, ?string $icon = null, ?bool $hidden = null): void
52+
public static function registerCustomPermissions(string $name, array $permissions, ?string $translationPrefix = null, null|string|BackedEnum $icon = null, ?bool $hidden = null): void
5253
{
5354
$customPermission = static::$customPermissions[$name] ?? [];
5455

5556
$customPermission['name'] = $name;
5657
$customPermission['permissions'] = array_merge($customPermission['permissions'] ?? [], $permissions);
5758

59+
if (!is_null($translationPrefix)) {
60+
$customPermission['translation_prefix'] = $translationPrefix;
61+
}
62+
5863
if (!is_null($icon)) {
5964
$customPermission['icon'] = $icon;
6065
}
@@ -104,7 +109,7 @@ public function user(): BelongsTo
104109
return $this->belongsTo(User::class);
105110
}
106111

107-
/** @return array<array{name: string, hidden: bool, icon: string, permissions: string[]}> */
112+
/** @return array<array{name: string, hidden: bool, icon: null|string|BackedEnum, translation_prefix: string, permissions: string[]}> */
108113
public static function allPermissionData(): array
109114
{
110115
$allPermissions = [];
@@ -117,6 +122,7 @@ public static function allPermissionData(): array
117122
'hidden' => $subuserPermission->isHidden(),
118123
'icon' => $subuserPermission->getIcon(),
119124
'permissions' => array_merge($allPermissions[$group]['permissions'] ?? [], [$permission]),
125+
'translation_prefix' => 'server/user.permissions',
120126
];
121127
}
122128

@@ -130,6 +136,7 @@ public static function allPermissionData(): array
130136
'hidden' => $customPermission['hidden'] ?? $groupData['hidden'] ?? false,
131137
'icon' => $customPermission['icon'] ?? $groupData['icon'],
132138
'permissions' => array_unique(array_merge($groupData['permissions'] ?? [], $customPermission['permissions'])),
139+
'translation_prefix' => $customPermission['translation_prefix'] ?? $groupData['translation_prefix'] ?? 'server/user.permissions',
133140
];
134141

135142
$allPermissions[$name] = $groupData;

lang/en/server/user.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,84 @@
1717
'notification_failed' => 'Failed to invite user!',
1818
'permissions' => [
1919
'title' => 'Permissions',
20+
21+
'activity_title' => 'Activity',
2022
'activity_desc' => 'Permissions that control a user\'s access to the server activity logs.',
23+
24+
'startup_title' => 'Startup',
2125
'startup_desc' => 'Permissions that control a user\'s ability to view this server\'s startup parameters.',
26+
27+
'settings_title' => 'Settings',
2228
'settings_desc' => 'Permissions that control a user\'s ability to modify this server\'s settings.',
29+
30+
'control_title' => 'Control',
2331
'control_desc' => 'Permissions that control a user\'s ability to control the power state of a server, or send commands.',
32+
33+
'user_title' => 'User',
2434
'user_desc' => 'Permissions that allow a user to manage other subusers on a server. They will never be able to edit their own account, or assign permissions they do not have themselves.',
35+
36+
'file_title' => 'File',
2537
'file_desc' => 'Permissions that control a user\'s ability to modify the filesystem for this server.',
38+
39+
'allocation_title' => 'Allocation',
2640
'allocation_desc' => 'Permissions that control a user\'s ability to modify the port allocations for this server.',
41+
42+
'database_title' => 'Database',
2743
'database_desc' => 'Permissions that control a user\'s access to the database management for this server.',
44+
45+
'backup_title' => 'Backup',
2846
'backup_desc' => 'Permissions that control a user\'s ability to generate and manage server backups.',
47+
48+
'schedule_title' => 'Schedule',
2949
'schedule_desc' => 'Permissions that control a user\'s access to the schedule management for this server.',
50+
3051
'startup_read' => 'Allows a user to view the startup variables for a server.',
3152
'startup_update' => 'Allows a user to modify the startup variables for the server.',
3253
'startup_docker_image' => 'Allows a user to modify the Docker image used when running the server.',
54+
3355
'settings_reinstall' => 'Allows a user to trigger a reinstall of this server.',
3456
'settings_rename' => 'Allows a user to rename this server.',
3557
'settings_description' => 'Allows a user to change the description of this server.',
58+
3659
'activity_read' => 'Allows a user to view the activity logs for the server.',
60+
3761
'websocket_connect' => 'Allows a user access to the websocket for this server.',
62+
3863
'control_console' => 'Allows a user to send data to the server console.',
3964
'control_start' => 'Allows a user to start the server instance.',
4065
'control_stop' => 'Allows a user to stop the server instance.',
4166
'control_restart' => 'Allows a user to restart the server instance.',
4267
'control_kill' => 'Allows a user to kill the server instance.',
68+
4369
'user_create' => 'Allows a user to create new user accounts for the server.',
4470
'user_read' => 'Allows a user permission to view users associated with this server.',
4571
'user_update' => 'Allows a user to modify other users associated with this server.',
4672
'user_delete' => 'Allows a user to delete other users associated with this server.',
73+
4774
'file_create' => 'Allows a user permission to create new files and directories.',
4875
'file_read' => 'Allows a user to view the contents of a directory, but not view the contents of or download files.',
4976
'file_read_content' => 'Allows a user to view the contents of a given file. This will also allow the user to download files.',
5077
'file_update' => 'Allows a user to update files and folders associated with the server.',
5178
'file_delete' => 'Allows a user to delete files and directories.',
5279
'file_archive' => 'Allows a user to create file archives and decompress existing archives.',
5380
'file_sftp' => 'Allows a user to perform the above file actions using a SFTP client.',
81+
5482
'allocation_read' => 'Allows a user to view all allocations currently assigned to this server. Users with any level of access to this server can always view the primary allocation.',
5583
'allocation_update' => 'Allows a user to change the primary server allocation and attach notes to each allocation.',
5684
'allocation_delete' => 'Allows a user to delete an allocation from the server.',
5785
'allocation_create' => 'Allows a user to assign additional allocations to the server.',
86+
5887
'database_create' => 'Allows a user permission to create a new database for the server.',
5988
'database_read' => 'Allows a user permission to view the server databases.',
6089
'database_update' => 'Allows a user permission to make modifications to a database. If the user does not have the "View Password" permission as well they will not be able to modify the password.',
6190
'database_delete' => 'Allows a user permission to delete a database instance.',
6291
'database_view_password' => 'Allows a user permission to view a database password in the system.',
92+
6393
'schedule_create' => 'Allows a user to create a new schedule for the server.',
6494
'schedule_read' => 'Allows a user permission to view schedules for a server.',
6595
'schedule_update' => 'Allows a user permission to make modifications to an existing server schedule.',
6696
'schedule_delete' => 'Allows a user to delete a schedule for the server.',
97+
6798
'backup_create' => 'Allows a user to create new backups for this server.',
6899
'backup_read' => 'Allows a user to view all backups that exist for this server.',
69100
'backup_delete' => 'Allows a user to remove backups from the system.',

0 commit comments

Comments
 (0)