1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-04-21 23:42:10 +02:00

Remove SETUP_COMPLETED variable (#398)

Replaces SETUP_COMPLETED variable with a database setting. Changes setup to add the setting to the database. Also adds a migration for existing installations.
This commit is contained in:
Kovah 2022-03-25 00:10:58 +01:00
parent 00c6693b1c
commit 03996f8bb3
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
21 changed files with 79 additions and 56 deletions

View File

@ -8,8 +8,6 @@ APP_ENV=local
APP_KEY=someRandomStringWith32Characters
# Enable the debug more if you are running into issues or while developing
APP_DEBUG=true
# Indicates that the setup was completed and the app can be used now
SETUP_COMPLETED=false
## Configuration of the database connection
## Attention: Those settings are configured during the web setup, please do not modify them now.
@ -28,7 +26,7 @@ DB_PASSWORD=ChangeThisToASecurePassword!
## Redis cache configuration
# Set the Redis connection here if you want to use it
REDIS_HOST=redis
REDIS_PASSWORD=changeThisPassword
REDIS_PASSWORD=ChangeThisToASecurePassword!
REDIS_PORT=6379
## You probably do not want to change any values blow. Only continue if you know what you are doing.

View File

@ -4,8 +4,6 @@
COMPOSE_PROJECT_NAME=linkace
# The app key is generated later, please leave it blank
APP_KEY=someRandomStringWith32Characters
# Indicates that the setup was completed and the app can be used now
SETUP_COMPLETED=false
## Configuration of the database connection
## Attention: Those settings are configured during the web setup, please do not modify them now.
@ -24,5 +22,5 @@ DB_PASSWORD=ChangeThisToASecurePassword!
## Redis cache configuration
# Set the Redis connection here if you want to use it
REDIS_HOST=redis
REDIS_PASSWORD=changeThisPassword
REDIS_PASSWORD=ChangeThisToASecurePassword!
REDIS_PORT=6379

View File

@ -3,8 +3,6 @@
## Basic app configuration
# The app key is generated later, please leave it blank
APP_KEY=someRandomStringWith32Characters
# Indicates that the setup was completed and the app can be used now
SETUP_COMPLETED=false
## Configuration of the database connection
## Attention: Those settings are configured during the web setup, please do not modify them now.

View File

@ -7,6 +7,22 @@ use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
/**
* Check if the setup was completed.
*
* @return bool
*/
function setupCompleted()
{
try {
return systemsettings('system_setup_completed');
} catch (PDOException $e) {
Log::error($e->getMessage());
return false;
}
}
/**
* Shorthand for the current user settings

View File

@ -16,7 +16,7 @@ use PDOException;
class DatabaseController extends Controller
{
protected $dbConfig;
protected array $dbConfig;
/**
* Display the form for configuration of the database.
@ -100,7 +100,7 @@ class DatabaseController extends Controller
/**
* At this point we write the database credentials to the .env file.
* We can ignore the FileNotFoundException exception as we already checked
* the presence and writability of the file in the previous setup step.
* the presence and write-ability of the file in the previous setup step.
*/
protected function storeConfigurationInEnv(): void
{
@ -127,7 +127,7 @@ class DatabaseController extends Controller
/**
* To prevent unwanted data loss we check for data in the database. It does
* not matter which data, because users may accidentially enter the
* not matter which data, because users may accidentally enter the
* credentials for a wrong database.
*
* @return bool

View File

@ -3,7 +3,9 @@
namespace App\Http\Controllers\Setup;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
class MetaController extends Controller
@ -25,21 +27,9 @@ class MetaController extends Controller
*/
public function complete(): View
{
$this->markSetupCompleted();
Setting::create(['key' => 'system_setup_completed', 'value' => true]);
Cache::forget('systemsettings');
return view('setup.complete');
}
/**
* After the setup is finished, we change the SETUP_COMPLETED variable
* from false to true to prevent the setup from being run again.
*/
protected function markSetupCompleted(): void
{
$envContent = File::get(base_path('.env'));
$envContent = str_replace('SETUP_COMPLETED=false', 'SETUP_COMPLETED=true', $envContent);
File::put(base_path('.env'), $envContent);
}
}

View File

@ -26,7 +26,7 @@ class RequirementsController extends Controller
protected function checkRequirements(): array
{
$results = [
'php_version' => PHP_VERSION_ID >= 70300,
'php_version' => PHP_VERSION_ID >= 70400,
'extension_bcmath' => extension_loaded('bcmath'),
'extension_ctype' => extension_loaded('ctype'),
'extension_json' => extension_loaded('json'),

View File

@ -8,7 +8,7 @@ use Illuminate\Http\Request;
class SettingsMiddleware
{
/**
* Handle an incoming request.
* Load some settings for the current user if applicable.
*
* @param Request $request
* @param Closure $next
@ -16,6 +16,10 @@ class SettingsMiddleware
*/
public function handle(Request $request, Closure $next)
{
if (!setupCompleted()) {
return $next($request);
}
// Set global configs based on the user settings
if ($user_timezone = usersettings('timezone')) {
config(['app.timezone' => $user_timezone]);

View File

@ -31,9 +31,11 @@ class SetupCheckMiddleware
return redirect()->refresh();
}
$setupCompleted = setupCompleted();
if ($request->is('setup/*')) {
if (config('app.setup_completed') === true) {
// Do not allow access to setup after it was completed
if ($setupCompleted) {
// Do not allow access to the setup after it was completed
return redirect()->route('front');
}
@ -41,7 +43,7 @@ class SetupCheckMiddleware
return $next($request);
}
if (config('app.setup_completed') !== true) {
if (!$setupCompleted) {
// Start the setup if it was not completed yet
return redirect()->route('setup.welcome');
}

View File

@ -133,15 +133,11 @@ return [
'guest_access' => env('GUEST_ACCESS', false),
/*
/**
|--------------------------------------------------------------------------
| setup Completed
| Setup Completed Flag
|--------------------------------------------------------------------------
|
| After the user completed the app setup, the env file will change the
| SETUP_COMPLETED value in the .env file. This setting makes the
| environment variable available in the application.
|
* @deprecated v1.10.0 Setting is no longer actively used and remains for proper migration to a database setting.
*/
'setup_completed' => env('SETUP_COMPLETED', false),

View File

@ -0,0 +1,16 @@
<?php
use App\Models\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Cache;
class AddCompletedSetupSetting extends Migration
{
public function up()
{
if (config('app.setup_completed')) {
Setting::updateOrCreate(['key' => 'system_setup_completed', 'value' => true]);
Cache::forget('systemsettings');
}
}
}

View File

@ -48,7 +48,6 @@
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="SETUP_COMPLETED" value="true"/>
<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Crea compte d\'usuari nou.',
'check_requirements' => 'Comprovar requeriments',
'requirements.php_version' => 'Versió de PHP >= 7.3.0',
'requirements.php_version' => 'Versió de PHP >= 7.4.0',
'requirements.extension_bcmath' => 'Extensió PHP: BCMath',
'requirements.extension_ctype' => 'Extensió PHP: Ctype',
'requirements.extension_json' => 'Extensió PHP: JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Erstellen Sie Ihr Benutzerkonto.',
'check_requirements' => 'Anforderungen prüfen',
'requirements.php_version' => 'PHP Version >= 7.3.0',
'requirements.php_version' => 'PHP Version >= 7.4.0',
'requirements.extension_bcmath' => 'PHP Extension: BCMath',
'requirements.extension_ctype' => 'PHP Extension: Ctype',
'requirements.extension_json' => 'PHP Extension: JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Create your user account.',
'check_requirements' => 'Check Requirements',
'requirements.php_version' => 'PHP version >= 7.3.0',
'requirements.php_version' => 'PHP version >= 7.4.0',
'requirements.extension_bcmath' => 'PHP Extension: BCMath',
'requirements.extension_ctype' => 'PHP Extension: Ctype',
'requirements.extension_json' => 'PHP Extension: JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Crea tu cuenta de usuario.',
'check_requirements' => 'Comprobar requisitos',
'requirements.php_version' => 'Versión PHP >= 7.3.0',
'requirements.php_version' => 'Versión PHP >= 7.4.0',
'requirements.extension_bcmath' => 'Extensión PHP: BCMath',
'requirements.extension_ctype' => 'Extensión PHP: Ctype',
'requirements.extension_json' => 'Extensión PHP: JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Créez votre compte utilisateur.',
'check_requirements' => 'Vérifier Prérequis',
'requirements.php_version' => 'Version PHP >= 7.3.0',
'requirements.php_version' => 'Version PHP >= 7.4.0',
'requirements.extension_bcmath' => 'Module PHP : BCMath',
'requirements.extension_ctype' => 'Module PHP : Ctype',
'requirements.extension_json' => 'Module PHP : JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => 'Hozzon létre felhasználói fiókot.',
'check_requirements' => 'Ellenőrizze a követelményeket',
'requirements.php_version' => 'PHP-verzió >= 7.3.0',
'requirements.php_version' => 'PHP-verzió >= 7.4.0',
'requirements.extension_bcmath' => 'PHP-bővítmény: BCMath',
'requirements.extension_ctype' => 'PHP-bővítmény: Ctype',
'requirements.extension_json' => 'PHP-bővítmény: JSON',

View File

@ -12,7 +12,7 @@ return [
'intro.step3' => '创建您的帐户。',
'check_requirements' => '检查要求',
'requirements.php_version' => 'PHP version >= 7.3.0',
'requirements.php_version' => 'PHP version >= 7.4.0',
'requirements.extension_bcmath' => 'PHP Extension: BCMath',
'requirements.extension_ctype' => 'PHP Extension: Ctype',
'requirements.extension_json' => 'PHP Extension: JSON',

View File

@ -2,22 +2,19 @@
namespace Tests\Controller\Setup;
use App\Models\Setting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
class MetaControllerTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
config(['app.setup_completed' => false]);
}
public function testSetupCheckRedirect(): void
{
Setting::where('key', 'system_setup_completed')->delete();
$response = $this->get('/');
$response->assertRedirect('setup/start');
@ -25,8 +22,6 @@ class MetaControllerTest extends TestCase
public function testSetupCheckWithoutRedirect(): void
{
config(['app.setup_completed' => true]);
$response = $this->get('/');
$response->assertRedirect('login');
@ -34,8 +29,6 @@ class MetaControllerTest extends TestCase
public function testRedirectIfSetupCompleted(): void
{
config(['app.setup_completed' => true]);
$response = $this->get('setup/start');
$response->assertRedirect('/');
@ -43,6 +36,8 @@ class MetaControllerTest extends TestCase
public function testSetupWelcomeView(): void
{
Setting::where('key', 'system_setup_completed')->delete();
$response = $this->get('setup/start');
$response->assertOk()

View File

@ -2,9 +2,20 @@
namespace Tests;
use App\Models\Setting;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp(): void
{
parent::setUp();
Setting::updateOrCreate(
['key' => 'system_setup_completed'],
['key' => 'system_setup_completed', 'value' => true]
);
}
}