Skip to content

Commit

Permalink
update token resource access
Browse files Browse the repository at this point in the history
  • Loading branch information
rupadana committed Jan 29, 2024
1 parent 323454d commit 1020a36
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ The routes will be :
On CreateHandler, you need to be create your custom request validation.


## Publish Token Resource
## Token Resource

```bash
php artisan vendor:publish --tag=api-service-resource
```

and you can modify it and show for spesific users by your own Authorization system
By default, Token resource only show on `super_admin` role. you can modify it by publishing config and change `api-service.can_access.role`

## Filtering & Allowed Field

Expand Down
5 changes: 5 additions & 0 deletions config/api-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
'token' => 'User',
],
],
'can_access' => [
'role' => [
'super_admin'
]
]
];
7 changes: 0 additions & 7 deletions src/ApiServiceServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ public function packageBooted(): void
// Icon Registration
FilamentIcon::register($this->getIcons());

// Handle Stubs
if (app()->runningInConsole()) {
$this->publishes([
__DIR__.'/Resources' => app_path('/Filament/Resources'),
], 'api-service-resource');
}

$router = app('router');
$router->aliasMiddleware('abilities', CheckAbilities::class);
$router->aliasMiddleware('ability', CheckForAnyAbility::class);
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/TokenResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public static function getNavigationGroup(): ?string
{
return config('api-service.navigation.group.token');
}

public static function canAccess(): bool
{
return auth()->user()->hasRole(config('api-service.can_access.role', []));
}
}

0 comments on commit 1020a36

Please sign in to comment.