diff --git a/README.md b/README.md index b9339c74..c01e7414 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ If you don't use certain feature sets of grocy (for example if you don't need "C - When the file `data/custom_css.html` exists, the contents of the file will be added just before `` (end of head) on every page ### Demo mode -When the file `data/demo.txt` exists, the application will work in a demo mode which means authentication is disabled and some demo data will be generated during the database schema migration. +When the `MODE` setting is set to `dev`, `demo` or `prerelease`, the application will work in a demo mode which means authentication is disabled and some demo data will be generated during the database schema migration. ### Embedded mode When the file `embedded.txt` exists, it must contain a valid and writable path which will be used as the data directory instead of `data` and authentication will be disabled (used in [grocy-desktop](https://github.com/grocy/grocy-desktop)). diff --git a/app.php b/app.php index c4c54df7..491b1a54 100644 --- a/app.php +++ b/app.php @@ -19,20 +19,6 @@ else define('GROCY_DATAPATH', __DIR__ . '/data'); } -// Definitions for demo mode -if (file_exists(GROCY_DATAPATH . '/demo.txt')) -{ - define('GROCY_IS_DEMO_INSTALL', true); - if (!defined('GROCY_USER_ID')) - { - define('GROCY_USER_ID', 1); - } -} -else -{ - define('GROCY_IS_DEMO_INSTALL', false); -} - // Load composer dependencies require_once __DIR__ . '/vendor/autoload.php'; @@ -40,6 +26,12 @@ require_once __DIR__ . '/vendor/autoload.php'; require_once GROCY_DATAPATH . '/config.php'; require_once __DIR__ . '/config-dist.php'; // For not in own config defined values we use the default ones +// Definitions for dev/demo/prerelease mode +if (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease') +{ + define('GROCY_USER_ID', 1); +} + // Definitions for disabled authentication mode if (GROCY_DISABLE_AUTH === true) { diff --git a/changelog/55_UNRELEASED_2019-xx-xx.md b/changelog/55_UNRELEASED_2019-xx-xx.md index 0ca3215f..f851ed91 100644 --- a/changelog/55_UNRELEASED_2019-xx-xx.md +++ b/changelog/55_UNRELEASED_2019-xx-xx.md @@ -33,6 +33,7 @@ - Fixed that the meal plan menu entry (sidebar) was not visible when the calendar was disabled (`FEATURE_FLAG_CALENDAR`) (thanks @lwis) - Slightly optimized table loading & search performance (thanks @lwis) - For integration: If a `GET` parameter `closeAfterCreation` is passed to the product edit page, the window will be closed on save (due to Browser restrictions, this only works when the window was opened from JavaScript) (thanks @Forceu) -- The `update.sh` file had wrong line endings (DOS instead of Unix) +- Fixed that the `update.sh` file had wrong line endings (DOS instead of Unix) +- Internal change: Demo mode is now handled via the setting `MODE` instead of checking the existence of the file `data/demo.txt` - New translations: (thanks all the translators) - Portuguese (Brazil) (demo available at https://pt-br.demo.grocy.info) diff --git a/config-dist.php b/config-dist.php index 9df72f0b..95dfbc32 100644 --- a/config-dist.php +++ b/config-dist.php @@ -15,7 +15,8 @@ # Either "production", "dev", "demo" or "prerelease" -# ("demo" and "prerelease" is reserved to be used only on the offical demo instances) +# When not "production", authentication will be disabled and +# demo data will be populated during database migrations Setting('MODE', 'production'); # Either "en" or "de" or the directory name of diff --git a/controllers/SystemController.php b/controllers/SystemController.php index 54cdb252..b212c001 100644 --- a/controllers/SystemController.php +++ b/controllers/SystemController.php @@ -22,7 +22,7 @@ class SystemController extends BaseController $databaseMigrationService = new DatabaseMigrationService(); $databaseMigrationService->MigrateDatabase(); - if (GROCY_IS_DEMO_INSTALL) + if (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease') { $demoDataGeneratorService = new DemoDataGeneratorService(); $demoDataGeneratorService->PopulateDemoData(); diff --git a/middleware/ApiKeyAuthMiddleware.php b/middleware/ApiKeyAuthMiddleware.php index f8a4de08..1dd238ed 100644 --- a/middleware/ApiKeyAuthMiddleware.php +++ b/middleware/ApiKeyAuthMiddleware.php @@ -22,7 +22,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware $route = $request->getAttribute('route'); $routeName = $route->getName(); - if (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) + if (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease' || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) { define('GROCY_AUTHENTICATED', true); $response = $next($request, $response); diff --git a/middleware/SessionAuthMiddleware.php b/middleware/SessionAuthMiddleware.php index 5cf436cc..adad241f 100644 --- a/middleware/SessionAuthMiddleware.php +++ b/middleware/SessionAuthMiddleware.php @@ -25,7 +25,7 @@ class SessionAuthMiddleware extends BaseMiddleware { $response = $next($request, $response); } - elseif (GROCY_IS_DEMO_INSTALL || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) + elseif (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease' || GROCY_IS_EMBEDDED_INSTALL || GROCY_DISABLE_AUTH) { $user = $sessionService->GetDefaultUser(); define('GROCY_AUTHENTICATED', true);