From 1020a36574a4593d13ea91dec14489267d9caf52 Mon Sep 17 00:00:00 2001 From: I Wayan Rupadana Date: Mon, 29 Jan 2024 10:11:15 +0800 Subject: [PATCH] update token resource access --- README.md | 8 ++------ config/api-service.php | 5 +++++ src/ApiServiceServiceProvider.php | 7 ------- src/Resources/TokenResource.php | 5 +++++ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c3e059e..15440c2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/api-service.php b/config/api-service.php index 9a77c02..18ccbc4 100644 --- a/config/api-service.php +++ b/config/api-service.php @@ -7,4 +7,9 @@ 'token' => 'User', ], ], + 'can_access' => [ + 'role' => [ + 'super_admin' + ] + ] ]; diff --git a/src/ApiServiceServiceProvider.php b/src/ApiServiceServiceProvider.php index 41d4ed1..56e6a36 100644 --- a/src/ApiServiceServiceProvider.php +++ b/src/ApiServiceServiceProvider.php @@ -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); diff --git a/src/Resources/TokenResource.php b/src/Resources/TokenResource.php index 55fdc76..582056c 100644 --- a/src/Resources/TokenResource.php +++ b/src/Resources/TokenResource.php @@ -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', [])); + } }