From e352754e6f886e2840c4cc212bb8a678e4fd5d4a Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:41:57 +0100 Subject: [PATCH] Fix `CopyAction` & Add to Server Settings page (#950) * Fix & Add to Server Settings page * Add `request()->isSecure()` CopyAction only works on SSL, no point in showing it when its not SSL --------- Co-authored-by: notCharles --- app/Extensions/OAuth/Providers/DiscordProvider.php | 2 +- app/Extensions/OAuth/Providers/GithubProvider.php | 2 +- .../Admin/Resources/NodeResource/Pages/EditNode.php | 6 +++--- .../Admin/Resources/ServerResource/Pages/EditServer.php | 6 +++--- app/Filament/Server/Pages/Settings.php | 7 +++++-- .../Resources/DatabaseResource/Pages/ListDatabases.php | 8 ++++---- app/Livewire/Installer/Steps/QueueStep.php | 4 ++-- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/Extensions/OAuth/Providers/DiscordProvider.php b/app/Extensions/OAuth/Providers/DiscordProvider.php index ae83e61e7..ed3c80f84 100644 --- a/app/Extensions/OAuth/Providers/DiscordProvider.php +++ b/app/Extensions/OAuth/Providers/DiscordProvider.php @@ -34,7 +34,7 @@ final class DiscordProvider extends OAuthProvider TextInput::make('_noenv_redirect') ->label('Redirect URL') ->disabled() - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->formatStateUsing(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/discord'), ]), ], parent::getSetupSteps()); diff --git a/app/Extensions/OAuth/Providers/GithubProvider.php b/app/Extensions/OAuth/Providers/GithubProvider.php index 81a9606af..3565fc5e2 100644 --- a/app/Extensions/OAuth/Providers/GithubProvider.php +++ b/app/Extensions/OAuth/Providers/GithubProvider.php @@ -26,7 +26,7 @@ final class GithubProvider extends OAuthProvider TextInput::make('_noenv_callback') ->label('Authorization callback URL') ->disabled() - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->default(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/github'), Placeholder::make('') ->content(new HtmlString('

When you filled all fields click on Register application.

')), diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php index 7b893aaad..794153913 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php @@ -258,7 +258,7 @@ class EditNode extends EditRecord 'lg' => 2, ]) ->label('Node UUID') - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->disabled(), TagsInput::make('tags') ->columnSpan([ @@ -513,7 +513,7 @@ class EditNode extends EditRecord ->label('/etc/pelican/config.yml') ->disabled() ->rows(19) - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->columnSpanFull(), Grid::make() ->columns() @@ -548,7 +548,7 @@ class EditNode extends EditRecord ->label('To auto-configure your node run the following command:') ->readOnly() ->autosize() - ->hintAction(fn (string $state) => CopyAction::make()->copyable($state)) + ->hintAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->formatStateUsing(fn (NodeAutoDeployService $service, Node $node, Set $set, Get $get) => $set('generatedToken', $service->handle(request(), $node, $get('docker')))), ]) ->mountUsing(function (Forms\Form $form) { diff --git a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php index bec6d5ece..25aea5ed5 100644 --- a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php @@ -136,7 +136,7 @@ class EditServer extends EditRecord ->columnSpanFull(), TextInput::make('uuid') - ->hintAction(CopyAction::make()) + ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->columnSpan([ 'default' => 2, 'sm' => 1, @@ -147,7 +147,7 @@ class EditServer extends EditRecord ->dehydrated(false), TextInput::make('uuid_short') ->label('Short UUID') - ->hintAction(CopyAction::make()) + ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->columnSpan([ 'default' => 2, 'sm' => 1, @@ -554,7 +554,7 @@ class EditServer extends EditRecord ->autosize(), Textarea::make('defaultStartup') - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->label('Default Startup Command') ->disabled() ->autosize() diff --git a/app/Filament/Server/Pages/Settings.php b/app/Filament/Server/Pages/Settings.php index c99932759..dc2755157 100644 --- a/app/Filament/Server/Pages/Settings.php +++ b/app/Filament/Server/Pages/Settings.php @@ -18,6 +18,7 @@ use Filament\Forms\Form; use Filament\Notifications\Notification; use Filament\Support\Enums\Alignment; use Illuminate\Support\Number; +use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction; class Settings extends ServerFormPage { @@ -161,7 +162,8 @@ class Settings extends ServerFormPage ->label('Connection') ->columnSpan(1) ->disabled() - ->hintActions([ + ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null) + ->hintAction( Action::make('connect_sftp') ->label('Connect to SFTP') ->color('success') @@ -171,7 +173,7 @@ class Settings extends ServerFormPage return 'sftp://' . auth()->user()->username . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp; }), - ]) + ) ->formatStateUsing(function (Server $server) { $fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn; @@ -180,6 +182,7 @@ class Settings extends ServerFormPage TextInput::make('username') ->label('Username') ->columnSpan(1) + ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->disabled() ->formatStateUsing(fn (Server $server) => auth()->user()->username . '.' . $server->uuid_short), Placeholder::make('password') diff --git a/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php b/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php index bce64b791..44f4597d9 100644 --- a/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php +++ b/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php @@ -35,9 +35,9 @@ class ListDatabases extends ListRecords ->schema([ TextInput::make('database') ->columnSpanFull() - ->suffixAction(CopyAction::make()), + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), TextInput::make('username') - ->suffixAction(CopyAction::make()), + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), TextInput::make('password') ->password()->revealable() ->hidden(fn () => !auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server)) @@ -45,7 +45,7 @@ class ListDatabases extends ListRecords RotateDatabasePasswordAction::make() ->authorize(fn () => auth()->user()->can(Permission::ACTION_DATABASE_UPDATE, $server)) ) - ->suffixAction(CopyAction::make()) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->formatStateUsing(fn (Database $database) => $database->password), TextInput::make('remote') ->label('Connections From'), @@ -55,7 +55,7 @@ class ListDatabases extends ListRecords ->label('JDBC Connection String') ->password()->revealable() ->hidden(!auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server)) - ->suffixAction(CopyAction::make()) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->columnSpanFull() ->formatStateUsing(fn (Database $database) => $database->jdbc), ]); diff --git a/app/Livewire/Installer/Steps/QueueStep.php b/app/Livewire/Installer/Steps/QueueStep.php index 11816594f..ee2309a78 100644 --- a/app/Livewire/Installer/Steps/QueueStep.php +++ b/app/Livewire/Installer/Steps/QueueStep.php @@ -45,14 +45,14 @@ class QueueStep TextInput::make('crontab') ->label(new HtmlString('Run the following command to set up your crontab. Note that www-data is your webserver user. On some systems this username might be different!')) ->disabled() - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->default('(crontab -l -u www-data 2>/dev/null; echo "* * * * * php ' . base_path() . '/artisan schedule:run >> /dev/null 2>&1") | crontab -u www-data -') ->hidden(fn () => file_exists('/.dockerenv')) ->columnSpanFull(), TextInput::make('queueService') ->label(new HtmlString('To setup the queue worker service you simply have to run the following command.')) ->disabled() - ->hintAction(CopyAction::make()) + ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null) ->default('sudo php ' . base_path() . '/artisan p:environment:queue-service') ->hidden(fn () => file_exists('/.dockerenv')) ->columnSpanFull(),