From 3cf502460f3f3efa7c76e1a063ef143254ea377e Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 28 Jun 2020 12:19:21 +0200 Subject: [PATCH] Rename "site mode" to "app mode" --- byceps/application.py | 8 ++--- byceps/blueprints/authentication/views.py | 8 ++--- byceps/blueprints/authorization/registry.py | 2 +- .../core/templates/layout/base_auto.html | 2 +- byceps/blueprints/core/views.py | 14 ++++----- byceps/blueprints/user/creation/views.py | 4 +-- .../current/templates/user/current/view.html | 2 +- byceps/blueprints/user/current/views.py | 6 ++-- byceps/config.py | 30 +++++++++---------- config/development_admin.py | 2 +- config/development_party.py | 2 +- config/production_party.py | 2 +- config/test_admin.py | 2 +- config/test_party.py | 2 +- 14 files changed, 43 insertions(+), 43 deletions(-) diff --git a/byceps/application.py b/byceps/application.py index 79ca5207ad..d5de4fb6b0 100644 --- a/byceps/application.py +++ b/byceps/application.py @@ -79,7 +79,7 @@ def _get_blueprints(app: Flask) -> Iterator[BlueprintReg]: """Yield blueprints to register on the application.""" yield from _get_blueprints_common() - current_mode = config.get_site_mode(app) + current_mode = config.get_app_mode(app) if current_mode.is_public(): yield from _get_blueprints_site() elif current_mode.is_admin(): @@ -212,8 +212,8 @@ def init_app(app: Flask) -> None: with app.app_context(): _set_url_root_path(app) - site_mode = config.get_site_mode() - if site_mode.is_public(): + app_mode = config.get_app_mode() + if app_mode.is_public(): # Incorporate site-specific template overrides. app.jinja_loader = SiteTemplateOverridesLoader() @@ -223,7 +223,7 @@ def init_app(app: Flask) -> None: _load_announce_signal_handlers() - if site_mode.is_admin() and app.config['RQ_DASHBOARD_ENABLED']: + if app_mode.is_admin() and app.config['RQ_DASHBOARD_ENABLED']: import rq_dashboard app.register_blueprint( rq_dashboard.blueprint, url_prefix='/admin/rq' diff --git a/byceps/blueprints/authentication/views.py b/byceps/blueprints/authentication/views.py index a8d3647a40..a62b941b7c 100644 --- a/byceps/blueprints/authentication/views.py +++ b/byceps/blueprints/authentication/views.py @@ -10,7 +10,7 @@ from flask import abort, g, request, url_for -from ...config import get_site_mode +from ...config import get_app_mode from ...services.authentication.exceptions import AuthenticationFailed from ...services.authentication import service as authentication_service from ...services.authentication.password import service as password_service @@ -62,7 +62,7 @@ def login_form(): 'angemeldet.' ) - in_admin_mode = get_site_mode().is_admin() + in_admin_mode = get_app_mode().is_admin() if not _is_login_enabled(in_admin_mode): return { @@ -87,7 +87,7 @@ def login(): if g.current_user.is_active: return - in_admin_mode = get_site_mode().is_admin() + in_admin_mode = get_app_mode().is_admin() if not _is_login_enabled(in_admin_mode): abort(403, 'Log in to this site is generally disabled.') @@ -271,7 +271,7 @@ def request_password_reset(): def _get_sender() -> Optional[Sender]: - if not get_site_mode().is_public(): + if not get_app_mode().is_public(): return None site = site_service.get_site(g.site_id) diff --git a/byceps/blueprints/authorization/registry.py b/byceps/blueprints/authorization/registry.py index 2213563200..1f45a88018 100644 --- a/byceps/blueprints/authorization/registry.py +++ b/byceps/blueprints/authorization/registry.py @@ -32,7 +32,7 @@ def get_enum_member(self, permission_id): if enum is None: # No enum found for that key. This happens if the blueprint # which contains the authorization enum is not registered in - # the current site mode (public/admin). + # the current app mode (public/admin). return None try: diff --git a/byceps/blueprints/core/templates/layout/base_auto.html b/byceps/blueprints/core/templates/layout/base_auto.html index 7bdd14355c..d0770329ba 100644 --- a/byceps/blueprints/core/templates/layout/base_auto.html +++ b/byceps/blueprints/core/templates/layout/base_auto.html @@ -1 +1 @@ -{% extends ('layout/admin/base.html' if g.site_mode.is_admin() else 'layout/base.html') %} +{% extends ('layout/admin/base.html' if g.app_mode.is_admin() else 'layout/base.html') %} diff --git a/byceps/blueprints/core/views.py b/byceps/blueprints/core/views.py index a93f91af51..19616561fe 100644 --- a/byceps/blueprints/core/views.py +++ b/byceps/blueprints/core/views.py @@ -74,19 +74,19 @@ def is_current_page(nav_item_path, current_page=None): @blueprint.before_app_request -def provide_site_mode(): - # site mode - site_mode = config.get_site_mode() - g.site_mode = site_mode +def provide_app_mode(): + # app mode + app_mode = config.get_app_mode() + g.app_mode = app_mode # site ID - if site_mode.is_public(): + if app_mode.is_public(): site_id = config.get_current_site_id() g.site_id = site_id # current party and brand party_id = None - if site_mode.is_public(): + if app_mode.is_public(): site = site_service.get_site(site_id) party_id = site.party_id @@ -101,7 +101,7 @@ def provide_site_mode(): g.brand_id = None # current user - is_admin_mode = site_mode.is_admin() + is_admin_mode = app_mode.is_admin() g.current_user = authentication_blueprint_service.get_current_user( is_admin_mode, party_id=party_id ) diff --git a/byceps/blueprints/user/creation/views.py b/byceps/blueprints/user/creation/views.py index 2cd731ae98..da6b7f3e37 100644 --- a/byceps/blueprints/user/creation/views.py +++ b/byceps/blueprints/user/creation/views.py @@ -11,7 +11,7 @@ from flask import abort, g, request -from ....config import get_site_mode +from ....config import get_app_mode from ....services.brand import settings_service as brand_settings_service from ....services.consent.transfer.models import Consent, SubjectID from ....services.newsletter.transfer.models import ( @@ -182,7 +182,7 @@ def _abort_if_user_account_creation_disabled(): def _is_user_account_creation_enabled(): - if get_site_mode().is_admin(): + if get_app_mode().is_admin(): return False site = site_service.get_site(g.site_id) diff --git a/byceps/blueprints/user/current/templates/user/current/view.html b/byceps/blueprints/user/current/templates/user/current/view.html index 21a93b0ae4..8875b0c46f 100644 --- a/byceps/blueprints/user/current/templates/user/current/view.html +++ b/byceps/blueprints/user/current/templates/user/current/view.html @@ -21,7 +21,7 @@

{{ title }}

{%- with label_column_width = '8rem', data_column_min_width = '12rem' %} {%- include 'user/current/_account.html' %} {%- include 'user/current/_details_personal.html' %} - {%- if g.site_mode.is_public() and newsletter_offered %} + {%- if g.app_mode.is_public() and newsletter_offered %} {%- include 'user/current/_newsletter.html' %} {%- endif %} {%- endwith %} diff --git a/byceps/blueprints/user/current/views.py b/byceps/blueprints/user/current/views.py index 5a89dbe82e..b34efa7c22 100644 --- a/byceps/blueprints/user/current/views.py +++ b/byceps/blueprints/user/current/views.py @@ -8,7 +8,7 @@ from flask import abort, g, jsonify, request, Response -from ....config import get_site_mode +from ....config import get_app_mode from ....services.country import service as country_service from ....services.newsletter import service as newsletter_service from ....services.user import command_service as user_command_service @@ -40,7 +40,7 @@ def view(): if user is None: abort(404) - if get_site_mode().is_public(): + if get_app_mode().is_public(): newsletter_list_id = _find_newsletter_list_for_brand() newsletter_offered = (newsletter_list_id is not None) @@ -63,7 +63,7 @@ def view(): @blueprint.route('/me.json') def view_as_json(): """Show selected attributes of the current user's profile as JSON.""" - if get_site_mode().is_admin(): + if get_app_mode().is_admin(): abort(404) user = g.current_user diff --git a/byceps/config.py b/byceps/config.py index 5cd223e67f..590cb60afb 100644 --- a/byceps/config.py +++ b/byceps/config.py @@ -15,13 +15,13 @@ EXTENSION_KEY = 'byceps_config' -KEY_SITE_MODE = 'site_mode' +KEY_APP_MODE = 'app_mode' KEY_SITE_ID = 'site_id' -SiteMode = Enum('SiteMode', ['public', 'admin']) -SiteMode.is_admin = lambda self: self == SiteMode.admin -SiteMode.is_public = lambda self: self == SiteMode.public +AppMode = Enum('AppMode', ['public', 'admin']) +AppMode.is_admin = lambda self: self == AppMode.admin +AppMode.is_public = lambda self: self == AppMode.public class ConfigurationError(Exception): @@ -31,10 +31,10 @@ class ConfigurationError(Exception): def init_app(app: Flask) -> None: app.extensions[EXTENSION_KEY] = {} - site_mode = _determine_site_mode(app) - set_extension_value(KEY_SITE_MODE, site_mode, app) + app_mode = _determine_app_mode(app) + set_extension_value(KEY_APP_MODE, app_mode, app) - if site_mode.is_public(): + if app_mode.is_public(): site_id = _determine_site_id(app) set_extension_value(KEY_SITE_ID, site_id, app) @@ -62,23 +62,23 @@ def set_extension_value(key: str, value: Any, app: Flask) -> None: # -------------------------------------------------------------------- # -# site mode +# app mode -def _determine_site_mode(app: Flask) -> SiteMode: - value = app.config.get('SITE_MODE') +def _determine_app_mode(app: Flask) -> AppMode: + value = app.config.get('APP_MODE') if value is None: - raise ConfigurationError('No site mode configured.') + raise ConfigurationError('No app mode configured.') try: - return SiteMode[value] + return AppMode[value] except KeyError: - raise ConfigurationError(f'Invalid site mode "{value}" configured.') + raise ConfigurationError(f'Invalid app mode "{value}" configured.') -def get_site_mode(app: Optional[Flask]=None) -> SiteMode: +def get_app_mode(app: Optional[Flask]=None) -> AppMode: """Return the mode the site should run in.""" - return get_extension_value(KEY_SITE_MODE, app) + return get_extension_value(KEY_APP_MODE, app) # -------------------------------------------------------------------- # diff --git a/config/development_admin.py b/config/development_admin.py index 27f6724093..8d852eaa19 100644 --- a/config/development_admin.py +++ b/config/development_admin.py @@ -7,7 +7,7 @@ RQ_DASHBOARD_ENABLED = True -SITE_MODE = 'admin' +APP_MODE = 'admin' MAIL_DEBUG = True MAIL_DEFAULT_SENDER = 'BYCEPS ' diff --git a/config/development_party.py b/config/development_party.py index 5806d0f5ee..89ab07e0ab 100644 --- a/config/development_party.py +++ b/config/development_party.py @@ -8,7 +8,7 @@ REDIS_URL = 'redis://127.0.0.1:6379/0' -SITE_MODE = 'public' +APP_MODE = 'public' SITE_ID = 'example-dev' MAIL_DEBUG = True diff --git a/config/production_party.py b/config/production_party.py index b1dbde834b..904b590850 100644 --- a/config/production_party.py +++ b/config/production_party.py @@ -15,7 +15,7 @@ REDIS_URL = 'unix:///var/run/redis/redis.sock?db=0' -SITE_MODE = 'public' +APP_MODE = 'public' SITE_ID = 'example-prod' MAIL_DEBUG = False diff --git a/config/test_admin.py b/config/test_admin.py index d48cc2941b..71a43d7156 100644 --- a/config/test_admin.py +++ b/config/test_admin.py @@ -9,7 +9,7 @@ REDIS_URL = 'redis://127.0.0.1:6379/0' -SITE_MODE = 'admin' +APP_MODE = 'admin' MAIL_DEBUG = False MAIL_DEFAULT_SENDER = 'BYCEPS ' diff --git a/config/test_party.py b/config/test_party.py index 6a8fcca4d9..b95813573c 100644 --- a/config/test_party.py +++ b/config/test_party.py @@ -9,7 +9,7 @@ REDIS_URL = 'redis://127.0.0.1:6379/0' -SITE_MODE = 'public' +APP_MODE = 'public' SITE_ID = 'acmecon-2014-website' MAIL_DEBUG = False