Handle demo mode via a setting instead of checking the existence of a file (closes #484)

This commit is contained in:
Bernd Bestel 2020-01-05 09:11:11 +01:00
parent 539334f5ee
commit a8cf5ae9ab
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
7 changed files with 14 additions and 20 deletions

View File

@ -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 `</head>` (end of head) on every page - When the file `data/custom_css.html` exists, the contents of the file will be added just before `</head>` (end of head) on every page
### Demo mode ### 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 ### 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)). 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)).

20
app.php
View File

@ -19,20 +19,6 @@ else
define('GROCY_DATAPATH', __DIR__ . '/data'); 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 // Load composer dependencies
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
@ -40,6 +26,12 @@ require_once __DIR__ . '/vendor/autoload.php';
require_once GROCY_DATAPATH . '/config.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 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 // Definitions for disabled authentication mode
if (GROCY_DISABLE_AUTH === true) if (GROCY_DISABLE_AUTH === true)
{ {

View File

@ -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) - 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) - 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) - 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) - New translations: (thanks all the translators)
- Portuguese (Brazil) (demo available at https://pt-br.demo.grocy.info) - Portuguese (Brazil) (demo available at https://pt-br.demo.grocy.info)

View File

@ -15,7 +15,8 @@
# Either "production", "dev", "demo" or "prerelease" # 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'); Setting('MODE', 'production');
# Either "en" or "de" or the directory name of # Either "en" or "de" or the directory name of

View File

@ -22,7 +22,7 @@ class SystemController extends BaseController
$databaseMigrationService = new DatabaseMigrationService(); $databaseMigrationService = new DatabaseMigrationService();
$databaseMigrationService->MigrateDatabase(); $databaseMigrationService->MigrateDatabase();
if (GROCY_IS_DEMO_INSTALL) if (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease')
{ {
$demoDataGeneratorService = new DemoDataGeneratorService(); $demoDataGeneratorService = new DemoDataGeneratorService();
$demoDataGeneratorService->PopulateDemoData(); $demoDataGeneratorService->PopulateDemoData();

View File

@ -22,7 +22,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
$route = $request->getAttribute('route'); $route = $request->getAttribute('route');
$routeName = $route->getName(); $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); define('GROCY_AUTHENTICATED', true);
$response = $next($request, $response); $response = $next($request, $response);

View File

@ -25,7 +25,7 @@ class SessionAuthMiddleware extends BaseMiddleware
{ {
$response = $next($request, $response); $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(); $user = $sessionService->GetDefaultUser();
define('GROCY_AUTHENTICATED', true); define('GROCY_AUTHENTICATED', true);