Skip to content

Commit

Permalink
[Chore] Deprecate general settings public dashboard (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Mar 31, 2024
1 parent 4f84a6a commit fca913a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
24 changes: 23 additions & 1 deletion app/Console/Commands/UpdateGeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Console\Command;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;

class UpdateGeneralSettings extends Command
Expand All @@ -34,6 +35,7 @@ public function handle()
$settings = new GeneralSettings();

$this->updateSiteName($settings);
$this->updatePublicDashboard($settings);
$this->updateTimeZone($settings);
$this->updateSchedule($settings);
$this->resetSevers($settings);
Expand All @@ -57,12 +59,32 @@ protected function resetSevers($settings): void
}
}

protected function updatePublicDashboard($settings): void
{
$publicDashboard = select(
label: 'Make the dashboard public?',
options: ['Yes', 'No'],
default: 'Yes',
required: true,
);

if ($publicDashboard == 'Yes') {
$settings->public_dashboard_enabled = true;

$settings->save();
} else {
$settings->public_dashboard_enabled = false;
}

$settings->save();
}

protected function updateSchedule($settings): void
{
$cron = text(
label: 'What is the schedule?',
placeholder: '0 * * * *',
default: $settings->speedtest_schedule,
default: $settings->speedtest_schedule ?? '0 * * * *',
required: true,
validate: fn (string $value) => match (true) {
! CronExpression::isValidExpression($value) => 'The schedule expression is invalid.',
Expand Down
12 changes: 6 additions & 6 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Filament\Actions\ActionGroup;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard as BasePage;
use Filament\Support\Enums\ActionSize;
use Filament\Support\Enums\IconPosition;
use Illuminate\Support\Arr;

Expand All @@ -30,9 +29,11 @@ protected function getHeaderActions(): array
return [
Action::make('home')
->label('Public Dashboard')
->icon('heroicon-o-chart-bar')
->iconPosition(IconPosition::Before)
->color('gray')
->hidden(fn (GeneralSettings $settings): bool => ! $settings->public_dashboard_enabled)
->url('/'),
->hidden(fn (): bool => ! config('speedtest.public_dashboard'))
->url(shouldOpenInNewTab: true, url: '/'),
ActionGroup::make([
Action::make('ookla speedtest')
->action(function (GeneralSettings $settings) {
Expand All @@ -55,9 +56,8 @@ protected function getHeaderActions(): array
->dropdownPlacement('bottom-end')
->label('Run Speedtest')
->icon('heroicon-o-rocket-launch')
->iconPosition(IconPosition::After)
->hidden(! auth()->user()->is_admin)
->size(ActionSize::Small),
->iconPosition(IconPosition::Before)
->hidden(! auth()->user()->is_admin),
];
}

Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Pages/Settings/GeneralPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function form(Form $form): Form
->helperText(new HtmlString('⚠️ DEPRECATED: Use <code>APP_NAME</code> environment variable.'))
->columnSpanFull(),
Forms\Components\Toggle::make('public_dashboard_enabled')
->label('Public dashboard'),
->label('Public dashboard')
->disabled()
->helperText(new HtmlString('⚠️ DEPRECATED: Use <code>PUBLIC_DASHBOARD</code> environment variable.')),
])
->compact()
->columns([
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __invoke(Request $request)
{
$settings = new GeneralSettings();

if (! $settings->public_dashboard_enabled) {
if (! config('speedtest.public_dashboard')) {
return redirect()->route('filament.admin.auth.login');
}

Expand Down
3 changes: 3 additions & 0 deletions app/Settings/GeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class GeneralSettings extends Settings

public bool $db_has_timezone;

/**
* @deprecated Use PUBLIC_DASHBOARD environment variable.
*/
public bool $public_dashboard_enabled;

public static function group(): string
Expand Down
2 changes: 2 additions & 0 deletions config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
'content_width' => env('CONTENT_WIDTH', '7xl'),

'public_dashboard' => env('PUBLIC_DASHBOARD', false),

/**
* Polling
*/
Expand Down

0 comments on commit fca913a

Please sign in to comment.