From fd2fd8d73aa3faa5feb5891b625f1ad7708a5e5c Mon Sep 17 00:00:00 2001 From: Finn Stutzenstein Date: Fri, 2 Oct 2020 09:57:28 +0200 Subject: [PATCH] Add demo mode to all docker setups --- .../users/user-repository.service.ts | 4 ++-- docker/.env | 1 + docker/docker-compose.yml.m4 | 1 + docker/docker-stack.yml.m4 | 1 + server/SETTINGS.rst | 6 +++--- server/docker/settings.py | 17 +++++++++++------ server/openslides/core/apps.py | 2 +- server/openslides/users/views.py | 2 +- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/src/app/core/repositories/users/user-repository.service.ts b/client/src/app/core/repositories/users/user-repository.service.ts index 00364c10e..4aaf0a77d 100644 --- a/client/src/app/core/repositories/users/user-repository.service.ts +++ b/client/src/app/core/repositories/users/user-repository.service.ts @@ -89,9 +89,9 @@ export class UserRepositoryService extends BaseRepository('Settings').subscribe(settings => { + this.constantsService.get<{ DEMO_USERS?: number[] }>('Settings').subscribe(settings => { if (settings) { - this.demoModeUserIds = settings.DEMO || null; + this.demoModeUserIds = settings.DEMO_USERS || null; } }); } diff --git a/docker/.env b/docker/.env index d9fee5b9f..c4dbdfd09 100644 --- a/docker/.env +++ b/docker/.env @@ -51,6 +51,7 @@ POSTFIX_RELAYHOST= # Features ENABLE_SAML= ENABLE_ELECTRONIC_VOTING= +DEMO_USERS= # Connections AUTOUPDATE_DELAY= CONNECTION_POOL_LIMIT= diff --git a/docker/docker-compose.yml.m4 b/docker/docker-compose.yml.m4 index 8cbc3c7dd..6d7d86780 100644 --- a/docker/docker-compose.yml.m4 +++ b/docker/docker-compose.yml.m4 @@ -45,6 +45,7 @@ x-osserver: x-osserver-env: &default-osserver-env AMOUNT_REPLICAS: ifenvelse(`REDIS_RO_SERVICE_REPLICAS', 1) AUTOUPDATE_DELAY: ifenvelse(`AUTOUPDATE_DELAY', 1) + DEMO_USERS: "ifenvelse(`DEMO_USERS',)" CONNECTION_POOL_LIMIT: ifenvelse(`CONNECTION_POOL_LIMIT', 100) DATABASE_HOST: "ifenvelse(`DATABASE_HOST', pgbouncer)" DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)" diff --git a/docker/docker-stack.yml.m4 b/docker/docker-stack.yml.m4 index 640843363..005aefc7d 100644 --- a/docker/docker-stack.yml.m4 +++ b/docker/docker-stack.yml.m4 @@ -44,6 +44,7 @@ x-osserver: x-osserver-env: &default-osserver-env AMOUNT_REPLICAS: ifenvelse(`REDIS_RO_SERVICE_REPLICAS', 3) AUTOUPDATE_DELAY: ifenvelse(`AUTOUPDATE_DELAY', 1) + DEMO_USERS: "ifenvelse(`DEMO_USERS',)" CONNECTION_POOL_LIMIT: ifenvelse(`CONNECTION_POOL_LIMIT', 100) DATABASE_HOST: "ifenvelse(`DATABASE_HOST', pgbouncer)" DATABASE_PASSWORD: "ifenvelse(`DATABASE_PASSWORD', openslides)" diff --git a/server/SETTINGS.rst b/server/SETTINGS.rst index 90eed3c2e..7509913d0 100644 --- a/server/SETTINGS.rst +++ b/server/SETTINGS.rst @@ -147,6 +147,6 @@ these requests from "prioritized clients" can be routed to different servers. deactivated by setting it to `None`. It is deactivated per default. The Delay is given in seconds -`DEMO`: Apply special settings for demo use cases. A list of protected user ids handlers -to be given. Updating these users (also password) is not allowed. Some bulk actions like -resetting password are completly disabled. Irrelevant for normal use cases. \ No newline at end of file +`DEMO_USERS`: Apply special settings for demo use cases. A list of protected user ids +handlers to be given. Updating these users (also password) is not allowed. Some bulk +actions like resetting password are completly disabled. Irrelevant for normal use cases. \ No newline at end of file diff --git a/server/docker/settings.py b/server/docker/settings.py index e5fb0537a..722795b14 100644 --- a/server/docker/settings.py +++ b/server/docker/settings.py @@ -6,6 +6,7 @@ https://github.com/OpenSlides/OpenSlides/blob/master/SETTINGS.rst """ import os +import json from openslides.global_settings import * @@ -19,17 +20,18 @@ undefined = object() def get_env(name, default=undefined, cast=str): env = os.environ.get(name) default_extension = "" - if env is None: + if not env: env = default default_extension = " (default)" if env is undefined: raise MissingEnvironmentVariable(name) - if cast is bool: - env = env in ("1", "true", "True") - else: - env = cast(env) + if env is not None: + if cast is bool: + env = env in ("1", "true", "True") + else: + env = cast(env) if env is None: print(f"{name}={default_extension}", flush=True) @@ -51,7 +53,10 @@ DEBUG = False # messages. An success message will always be shown. RESET_PASSWORD_VERBOSE_ERRORS = get_env("RESET_PASSWORD_VERBOSE_ERRORS", True, bool) +# OpenSlides specific settings AUTOUPDATE_DELAY = get_env("AUTOUPDATE_DELAY", 1, int) +DEMO_USERS = get_env("DEMO_USERS", default=None) +DEMO_USERS = json.loads(DEMO_USERS) if DEMO_USERS else None # Email settings # For SSL/TLS specific settings see https://docs.djangoproject.com/en/1.11/topics/email/#smtp-backend @@ -109,7 +114,7 @@ CHANNEL_LAYERS = { # Collection Cache REDIS_ADDRESS = f"redis://{REDIS_HOST}:{REDIS_PORT}/0" REDIS_READ_ONLY_ADDRESS = f"redis://{REDIS_SLAVE_HOST}:{REDIS_SLAVE_PORT}/0" -AMOUNT_REPLICAS = get_env("AMOUNT_REPLICAS", 1) +AMOUNT_REPLICAS = get_env("AMOUNT_REPLICAS", 1, int) CONNECTION_POOL_LIMIT = get_env("CONNECTION_POOL_LIMIT", 100, int) # Session backend diff --git a/server/openslides/core/apps.py b/server/openslides/core/apps.py index 5d993e3c2..835b21335 100644 --- a/server/openslides/core/apps.py +++ b/server/openslides/core/apps.py @@ -133,7 +133,7 @@ class CoreAppConfig(AppConfig): "JITSI_DOMAIN", "JITSI_ROOM_NAME", "JITSI_ROOM_PASSWORD", - "DEMO", + "DEMO_USERS", ] client_settings_dict = {} for key in client_settings_keys: diff --git a/server/openslides/users/views.py b/server/openslides/users/views.py index 1361f8da5..dc79b5228 100644 --- a/server/openslides/users/views.py +++ b/server/openslides/users/views.py @@ -56,7 +56,7 @@ from .serializers import GroupSerializer, PermissionRelatedField from .user_backend import user_backend_manager -demo_mode_users = getattr(settings, "DEMO", None) +demo_mode_users = getattr(settings, "DEMO_USERS", None) is_demo_mode = isinstance(demo_mode_users, list) and len(demo_mode_users) > 0 logger = logging.getLogger(__name__) if is_demo_mode: