From 4f63cdaee4d858895b6e7453c6e03b74e200906a Mon Sep 17 00:00:00 2001 From: Boy132 Date: Wed, 18 Sep 2024 10:31:27 +0200 Subject: [PATCH] small cleanup --- app/Filament/Pages/Settings.php | 41 +++++---------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 489e419d88..4c766a53ee 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -3,7 +3,6 @@ namespace App\Filament\Pages; use App\Models\Backup; -use App\Models\User; use App\Notifications\MailTested; use App\Traits\EnvironmentWriterTrait; use Exception; @@ -52,10 +51,7 @@ public function mount(): void public static function canAccess(): bool { - /** @var User $user */ - $user = auth()->user(); - - return $user->can('view settings'); + return auth()->user()->can('view settings'); } protected function getFormSchema(): array @@ -64,12 +60,7 @@ protected function getFormSchema(): array Tabs::make('Tabs') ->columns() ->persistTabInQueryString() - ->disabled(function () { - /** @var User $user */ - $user = auth()->user(); - - return !$user->can('update settings'); - }) + ->disabled(fn () => !auth()->user()->can('update settings')) ->tabs([ Tab::make('general') ->label('General') @@ -162,22 +153,12 @@ private function generalSettings(): array ->color('danger') ->icon('tabler-trash') ->requiresConfirmation() - ->disabled(function () { - /** @var User $user */ - $user = auth()->user(); - - return !$user->can('update settings'); - }) + ->authorize(fn () => auth()->user()->can('update settings')) ->action(fn (Set $set) => $set('TRUSTED_PROXIES', [])), FormAction::make('cloudflare') ->label('Set to Cloudflare IPs') ->icon('tabler-brand-cloudflare') - ->disabled(function () { - /** @var User $user */ - $user = auth()->user(); - - return !$user->can('update settings'); - }) + ->authorize(fn () => auth()->user()->can('update settings')) ->action(fn (Set $set) => $set('TRUSTED_PROXIES', [ '173.245.48.0/20', '103.21.244.0/22', @@ -253,12 +234,7 @@ private function mailSettings(): array ->label('Send Test Mail') ->icon('tabler-send') ->hidden(fn (Get $get) => $get('MAIL_MAILER') === 'log') - ->disabled(function () { - /** @var User $user */ - $user = auth()->user(); - - return !$user->can('update settings'); - }) + ->authorize(fn () => auth()->user()->can('update settings')) ->action(function () { try { MailNotification::route('mail', auth()->user()->email) @@ -594,12 +570,7 @@ protected function getHeaderActions(): array return [ Action::make('save') ->action('save') - ->hidden(function () { - /** @var User $user */ - $user = auth()->user(); - - return !$user->can('update settings'); - }) + ->authorize(fn () => auth()->user()->can('update settings')) ->keyBindings(['mod+s']), ];