diff --git a/app/Filament/Pages/Installer/PanelInstaller.php b/app/Filament/Pages/Installer/PanelInstaller.php index 160439086..cca387332 100644 --- a/app/Filament/Pages/Installer/PanelInstaller.php +++ b/app/Filament/Pages/Installer/PanelInstaller.php @@ -7,6 +7,7 @@ use App\Filament\Pages\Installer\Steps\DatabaseStep; use App\Filament\Pages\Installer\Steps\EnvironmentStep; use App\Filament\Pages\Installer\Steps\RedisStep; use App\Filament\Pages\Installer\Steps\RequirementsStep; +use App\Models\User; use App\Services\Users\UserCreationService; use App\Traits\CheckMigrationsTrait; use App\Traits\EnvironmentWriterTrait; @@ -44,11 +45,22 @@ class PanelInstaller extends SimplePage implements HasForms return MaxWidth::SevenExtraLarge; } + public static function show(): bool + { + if (User::count() <= 0) { + return true; + } + + if (config('panel.client_features.installer.enabled')) { + return true; + } + + return false; + } + public function mount() { - if (is_installed()) { - abort(404); - } + abort_unless(self::show(), 404); $this->form->fill(); } @@ -123,7 +135,7 @@ class PanelInstaller extends SimplePage implements HasForms app(UserCreationService::class)->handle($userData); // Install setup complete - $this->writeToEnvironment(['APP_INSTALLED' => 'true']); + $this->writeToEnvironment(['APP_INSTALLER' => 'false']); $this->rememberData(); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index e1984bc88..45e4a7729 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Filament\Pages\Installer\PanelInstaller; use Carbon\CarbonImmutable; use Illuminate\Support\Str; use Illuminate\Http\Request; @@ -17,8 +18,12 @@ class LoginController extends AbstractLoginController * base authentication view component. React will take over at this point and * turn the login area into an SPA. */ - public function index(): View + public function index() { + if (PanelInstaller::show()) { + return redirect('/installer'); + } + return view('templates/auth.core'); } diff --git a/app/helpers.php b/app/helpers.php index 4f3e87021..2e21fc728 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -17,34 +17,3 @@ if (!function_exists('is_ip')) { return $address !== null && filter_var($address, FILTER_VALIDATE_IP) !== false; } } - -if (!function_exists('object_get_strict')) { - /** - * Get an object using dot notation. An object key with a value of null is still considered valid - * and will not trigger the response of a default value (unlike object_get). - */ - function object_get_strict(object $object, ?string $key, mixed $default = null): mixed - { - if (is_null($key) || trim($key) == '') { - return $object; - } - - foreach (explode('.', $key) as $segment) { - if (!is_object($object) || !property_exists($object, $segment)) { - return value($default); - } - - $object = $object->{$segment}; - } - - return $object; - } -} - -if (!function_exists('is_installed')) { - function is_installed(): bool - { - // This defaults to true so existing panels count as "installed" - return env('APP_INSTALLED', true); - } -} diff --git a/config/panel.php b/config/panel.php index 32b11bc3a..62273bbbf 100644 --- a/config/panel.php +++ b/config/panel.php @@ -74,7 +74,7 @@ return [ | Client Features |-------------------------------------------------------------------------- | - | Allow clients to create their own databases. + | Allow clients to turn features on or off */ 'client_features' => [ @@ -93,6 +93,10 @@ return [ 'range_start' => env('PANEL_CLIENT_ALLOCATIONS_RANGE_START'), 'range_end' => env('PANEL_CLIENT_ALLOCATIONS_RANGE_END'), ], + + 'installer' => [ + 'enabled' => env('APP_INSTALLER', true), + ], ], /*