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 <charles@pelican.dev>
This commit is contained in:
MartinOscar 2025-01-27 19:41:57 +01:00 committed by GitHub
parent 7cde90a39a
commit e352754e6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 19 additions and 16 deletions

View File

@ -34,7 +34,7 @@ final class DiscordProvider extends OAuthProvider
TextInput::make('_noenv_redirect') TextInput::make('_noenv_redirect')
->label('Redirect URL') ->label('Redirect URL')
->disabled() ->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'), ->formatStateUsing(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/discord'),
]), ]),
], parent::getSetupSteps()); ], parent::getSetupSteps());

View File

@ -26,7 +26,7 @@ final class GithubProvider extends OAuthProvider
TextInput::make('_noenv_callback') TextInput::make('_noenv_callback')
->label('Authorization callback URL') ->label('Authorization callback URL')
->disabled() ->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'), ->default(fn () => config('app.url') . (Str::endsWith(config('app.url'), '/') ? '' : '/') . 'auth/oauth/callback/github'),
Placeholder::make('') Placeholder::make('')
->content(new HtmlString('<p>When you filled all fields click on <b>Register application</b>.</p>')), ->content(new HtmlString('<p>When you filled all fields click on <b>Register application</b>.</p>')),

View File

@ -258,7 +258,7 @@ class EditNode extends EditRecord
'lg' => 2, 'lg' => 2,
]) ])
->label('Node UUID') ->label('Node UUID')
->hintAction(CopyAction::make()) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->disabled(), ->disabled(),
TagsInput::make('tags') TagsInput::make('tags')
->columnSpan([ ->columnSpan([
@ -513,7 +513,7 @@ class EditNode extends EditRecord
->label('/etc/pelican/config.yml') ->label('/etc/pelican/config.yml')
->disabled() ->disabled()
->rows(19) ->rows(19)
->hintAction(CopyAction::make()) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->columnSpanFull(), ->columnSpanFull(),
Grid::make() Grid::make()
->columns() ->columns()
@ -548,7 +548,7 @@ class EditNode extends EditRecord
->label('To auto-configure your node run the following command:') ->label('To auto-configure your node run the following command:')
->readOnly() ->readOnly()
->autosize() ->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')))), ->formatStateUsing(fn (NodeAutoDeployService $service, Node $node, Set $set, Get $get) => $set('generatedToken', $service->handle(request(), $node, $get('docker')))),
]) ])
->mountUsing(function (Forms\Form $form) { ->mountUsing(function (Forms\Form $form) {

View File

@ -136,7 +136,7 @@ class EditServer extends EditRecord
->columnSpanFull(), ->columnSpanFull(),
TextInput::make('uuid') TextInput::make('uuid')
->hintAction(CopyAction::make()) ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 2,
'sm' => 1, 'sm' => 1,
@ -147,7 +147,7 @@ class EditServer extends EditRecord
->dehydrated(false), ->dehydrated(false),
TextInput::make('uuid_short') TextInput::make('uuid_short')
->label('Short UUID') ->label('Short UUID')
->hintAction(CopyAction::make()) ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->columnSpan([ ->columnSpan([
'default' => 2, 'default' => 2,
'sm' => 1, 'sm' => 1,
@ -554,7 +554,7 @@ class EditServer extends EditRecord
->autosize(), ->autosize(),
Textarea::make('defaultStartup') Textarea::make('defaultStartup')
->hintAction(CopyAction::make()) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->label('Default Startup Command') ->label('Default Startup Command')
->disabled() ->disabled()
->autosize() ->autosize()

View File

@ -18,6 +18,7 @@ use Filament\Forms\Form;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Support\Enums\Alignment; use Filament\Support\Enums\Alignment;
use Illuminate\Support\Number; use Illuminate\Support\Number;
use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction;
class Settings extends ServerFormPage class Settings extends ServerFormPage
{ {
@ -161,7 +162,8 @@ class Settings extends ServerFormPage
->label('Connection') ->label('Connection')
->columnSpan(1) ->columnSpan(1)
->disabled() ->disabled()
->hintActions([ ->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->hintAction(
Action::make('connect_sftp') Action::make('connect_sftp')
->label('Connect to SFTP') ->label('Connect to SFTP')
->color('success') ->color('success')
@ -171,7 +173,7 @@ class Settings extends ServerFormPage
return 'sftp://' . auth()->user()->username . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp; return 'sftp://' . auth()->user()->username . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp;
}), }),
]) )
->formatStateUsing(function (Server $server) { ->formatStateUsing(function (Server $server) {
$fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn; $fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn;
@ -180,6 +182,7 @@ class Settings extends ServerFormPage
TextInput::make('username') TextInput::make('username')
->label('Username') ->label('Username')
->columnSpan(1) ->columnSpan(1)
->suffixAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->disabled() ->disabled()
->formatStateUsing(fn (Server $server) => auth()->user()->username . '.' . $server->uuid_short), ->formatStateUsing(fn (Server $server) => auth()->user()->username . '.' . $server->uuid_short),
Placeholder::make('password') Placeholder::make('password')

View File

@ -35,9 +35,9 @@ class ListDatabases extends ListRecords
->schema([ ->schema([
TextInput::make('database') TextInput::make('database')
->columnSpanFull() ->columnSpanFull()
->suffixAction(CopyAction::make()), ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
TextInput::make('username') TextInput::make('username')
->suffixAction(CopyAction::make()), ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
TextInput::make('password') TextInput::make('password')
->password()->revealable() ->password()->revealable()
->hidden(fn () => !auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server)) ->hidden(fn () => !auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server))
@ -45,7 +45,7 @@ class ListDatabases extends ListRecords
RotateDatabasePasswordAction::make() RotateDatabasePasswordAction::make()
->authorize(fn () => auth()->user()->can(Permission::ACTION_DATABASE_UPDATE, $server)) ->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), ->formatStateUsing(fn (Database $database) => $database->password),
TextInput::make('remote') TextInput::make('remote')
->label('Connections From'), ->label('Connections From'),
@ -55,7 +55,7 @@ class ListDatabases extends ListRecords
->label('JDBC Connection String') ->label('JDBC Connection String')
->password()->revealable() ->password()->revealable()
->hidden(!auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server)) ->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() ->columnSpanFull()
->formatStateUsing(fn (Database $database) => $database->jdbc), ->formatStateUsing(fn (Database $database) => $database->jdbc),
]); ]);

View File

@ -45,14 +45,14 @@ class QueueStep
TextInput::make('crontab') TextInput::make('crontab')
->label(new HtmlString('Run the following command to set up your crontab. Note that <code>www-data</code> is your webserver user. On some systems this username might be different!')) ->label(new HtmlString('Run the following command to set up your crontab. Note that <code>www-data</code> is your webserver user. On some systems this username might be different!'))
->disabled() ->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 -') ->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')) ->hidden(fn () => file_exists('/.dockerenv'))
->columnSpanFull(), ->columnSpanFull(),
TextInput::make('queueService') TextInput::make('queueService')
->label(new HtmlString('To setup the queue worker service you simply have to run the following command.')) ->label(new HtmlString('To setup the queue worker service you simply have to run the following command.'))
->disabled() ->disabled()
->hintAction(CopyAction::make()) ->hintAction(fn () => request()->isSecure() ? CopyAction::make() : null)
->default('sudo php ' . base_path() . '/artisan p:environment:queue-service') ->default('sudo php ' . base_path() . '/artisan p:environment:queue-service')
->hidden(fn () => file_exists('/.dockerenv')) ->hidden(fn () => file_exists('/.dockerenv'))
->columnSpanFull(), ->columnSpanFull(),