Skip to content

Commit

Permalink
.... Sure it works.
Browse files Browse the repository at this point in the history
TODO: Update permissions when you save editing a sub user.
  • Loading branch information
notAreYouScared committed Aug 6, 2024
1 parent f7a2c7c commit c67a2e9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/Filament/App/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public static function table(Table $table): Table
])
->actions([
DeleteAction::make()
->label('Remove User'),
->label('Remove User')
->requiresConfirmation(),
EditAction::make()
->label('Edit User')
->hidden(!auth()->user()->can(Permission::ACTION_USER_UPDATE, Filament::getTenant()))
->modalHeading(fn (User $user) => 'Editing ' . $user->email)
->form([
Grid::make()
->columnSpanFull()
Expand Down Expand Up @@ -168,6 +170,27 @@ public static function table(Table $table): Table
->icon('tabler-terminal-2')
->schema([
CheckboxList::make('control')
->formatStateUsing(function (User $user, Set $set) {
$server = Filament::getTenant();
$permissionsArray = Subuser::query()
->where('user_id', $user->id)
->where('server_id', $server->id)
->first()
->permissions;

$transformedPermissions = [];

foreach ($permissionsArray as $permission) {
[$group, $action] = explode('.', $permission, 2);
$transformedPermissions[$group][] = $action;
}

foreach ($transformedPermissions as $key => $value) {
$set($key, $value);
}

return $transformedPermissions['control'];
})
->bulkToggleable()
->label('')
->options([
Expand Down

0 comments on commit c67a2e9

Please sign in to comment.