From f43fb985a201fe65926875bd90070f357ccd90e8 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 7 Jun 2024 08:59:00 +0200 Subject: [PATCH 1/3] fix phpstan in Node and EditProfile --- .../UserResource/Pages/EditProfile.php | 33 +++++++++++-------- app/Models/Node.php | 5 +++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/Filament/Resources/UserResource/Pages/EditProfile.php b/app/Filament/Resources/UserResource/Pages/EditProfile.php index 0e96f7a04..441b58f12 100644 --- a/app/Filament/Resources/UserResource/Pages/EditProfile.php +++ b/app/Filament/Resources/UserResource/Pages/EditProfile.php @@ -101,15 +101,18 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ->icon('tabler-shield-lock') ->schema(function () { - if ($this->getUser()->use_totp) { + /** @var User */ + $user = auth()->user(); + + if (auth()->user()->use_totp) { return [ Placeholder::make('2fa-already-enabled') ->label('Two Factor Authentication is currently enabled!'), Textarea::make('backup-tokens') - ->hidden(fn () => !cache()->get("users.{$this->getUser()->id}.2fa.tokens")) + ->hidden(fn () => !cache()->get("users.{$user->id}.2fa.tokens")) ->rows(10) ->readOnly() - ->formatStateUsing(fn () => cache()->get("users.{$this->getUser()->id}.2fa.tokens")) + ->formatStateUsing(fn () => cache()->get("users.{$user->id}.2fa.tokens")) ->helperText('These will not be shown again!') ->label('Backup Tokens:'), TextInput::make('2fa-disable-code') @@ -117,15 +120,17 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ->helperText('Enter your current 2FA code to disable Two Factor Authentication'), ]; } + /** @var TwoFactorSetupService */ $setupService = app(TwoFactorSetupService::class); ['image_url_data' => $url, 'secret' => $secret] = cache()->remember( - "users.{$this->getUser()->id}.2fa.state", - now()->addMinutes(5), fn () => $setupService->handle($this->getUser()) + "users.{$user->id}.2fa.state", + now()->addMinutes(5), fn () => $setupService->handle(auth()->user()) ); $options = new QROptions([ 'svgLogo' => public_path('pelican.svg'), + 'svgLogoScale' => 0.05, 'addLogoSpace' => true, 'logoSpaceWidth' => 13, 'logoSpaceHeight' => 13, @@ -133,22 +138,24 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile // https://github.com/chillerlan/php-qrcode/blob/main/examples/svgWithLogo.php - // SVG logo options (see extended class) - $options->svgLogo = public_path('pelican.svg'); // logo from: https://github.com/simple-icons/simple-icons - $options->svgLogoScale = 0.05; - // $options->svgLogoCssClass = 'dark'; - // QROptions + // @phpstan-ignore property.protected $options->version = Version::AUTO; // $options->outputInterface = QRSvgWithLogo::class; + // @phpstan-ignore property.protected $options->outputBase64 = false; + // @phpstan-ignore property.protected $options->eccLevel = EccLevel::H; // ECC level H is necessary when using logos + // @phpstan-ignore property.protected $options->addQuietzone = true; // $options->drawLightModules = true; + // @phpstan-ignore property.protected $options->connectPaths = true; + // @phpstan-ignore property.protected $options->drawCircularModules = true; // $options->circleRadius = 0.45; + // @phpstan-ignore property.protected $options->svgDefs = ' @@ -196,8 +203,8 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ])->headerActions([ Action::make('Create') ->successRedirectUrl(route('filament.admin.auth.profile', ['tab' => '-api-keys-tab'])) - ->action(function (Get $get, Action $action) { - $token = auth()->user()->createToken( + ->action(function (Get $get, Action $action, $user) { + $token = $user->createToken( $get('description'), $get('allowed_ips'), ); @@ -258,7 +265,7 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ]), ]) ->operation('edit') - ->model($this->getUser()) + ->model(auth()->user()) ->statePath('data') ->inlineLabel(!static::isSimple()), ), diff --git a/app/Models/Node.php b/app/Models/Node.php index 65aeaa0ea..c1e66b574 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -34,6 +34,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; * @property int $daemon_listen * @property int $daemon_sftp * @property string $daemon_base + * @property array $tags * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at * @property \App\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts @@ -131,6 +132,10 @@ class Node extends Model ]; } + public int $servers_sum_memory; + public int $servers_sum_disk; + public int $servers_sum_cpu; + public function getRouteKeyName(): string { return 'id'; From 70fc84309fba641a4145349dca5bddbd33159df3 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 7 Jun 2024 09:11:40 +0200 Subject: [PATCH 2/3] revert some changes in EditProfile --- .../UserResource/Pages/EditProfile.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Filament/Resources/UserResource/Pages/EditProfile.php b/app/Filament/Resources/UserResource/Pages/EditProfile.php index 441b58f12..e04179ba8 100644 --- a/app/Filament/Resources/UserResource/Pages/EditProfile.php +++ b/app/Filament/Resources/UserResource/Pages/EditProfile.php @@ -31,6 +31,9 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\HtmlString; use Illuminate\Validation\Rules\Password; +/** + * @method User getUser() + */ class EditProfile extends \Filament\Pages\Auth\EditProfile { protected function getForms(): array @@ -101,18 +104,15 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ->icon('tabler-shield-lock') ->schema(function () { - /** @var User */ - $user = auth()->user(); - - if (auth()->user()->use_totp) { + if ($this->getUser()->use_totp) { return [ Placeholder::make('2fa-already-enabled') ->label('Two Factor Authentication is currently enabled!'), Textarea::make('backup-tokens') - ->hidden(fn () => !cache()->get("users.{$user->id}.2fa.tokens")) + ->hidden(fn () => !cache()->get("users.{$this->getUser()->id}.2fa.tokens")) ->rows(10) ->readOnly() - ->formatStateUsing(fn () => cache()->get("users.{$user->id}.2fa.tokens")) + ->formatStateUsing(fn () => cache()->get("users.{$this->getUser()->id}.2fa.tokens")) ->helperText('These will not be shown again!') ->label('Backup Tokens:'), TextInput::make('2fa-disable-code') @@ -124,8 +124,8 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile $setupService = app(TwoFactorSetupService::class); ['image_url_data' => $url, 'secret' => $secret] = cache()->remember( - "users.{$user->id}.2fa.state", - now()->addMinutes(5), fn () => $setupService->handle(auth()->user()) + "users.{$this->getUser()->id}.2fa.state", + now()->addMinutes(5), fn () => $setupService->handle($this->getUser()) ); $options = new QROptions([ @@ -265,7 +265,7 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile ]), ]) ->operation('edit') - ->model(auth()->user()) + ->model($this->getUser()) ->statePath('data') ->inlineLabel(!static::isSimple()), ), From 6b249b95458add312a55b26ee2f77829c1d37154 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 7 Jun 2024 09:17:10 +0200 Subject: [PATCH 3/3] fix tests --- app/Models/Node.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Models/Node.php b/app/Models/Node.php index c1e66b574..3efb762db 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -132,9 +132,9 @@ class Node extends Model ]; } - public int $servers_sum_memory; - public int $servers_sum_disk; - public int $servers_sum_cpu; + public int $servers_sum_memory = 0; + public int $servers_sum_disk = 0; + public int $servers_sum_cpu = 0; public function getRouteKeyName(): string {