Skip to content

Commit

Permalink
Rename "site mode" to "app mode"
Browse files Browse the repository at this point in the history
  • Loading branch information
homeworkprod committed Jun 28, 2020
1 parent 4c245aa commit 3cf5024
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions byceps/application.py
Expand Up @@ -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():
Expand Down Expand Up @@ -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()

Expand All @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions byceps/blueprints/authentication/views.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.')
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion byceps/blueprints/authorization/registry.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion 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') %}
14 changes: 7 additions & 7 deletions byceps/blueprints/core/views.py
Expand Up @@ -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
Expand All @@ -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
)
4 changes: 2 additions & 2 deletions byceps/blueprints/user/creation/views.py
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -21,7 +21,7 @@ <h1>{{ title }}</h1>
{%- 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 %}
Expand Down
6 changes: 3 additions & 3 deletions byceps/blueprints/user/current/views.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions byceps/config.py
Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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)


# -------------------------------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion config/development_admin.py
Expand Up @@ -7,7 +7,7 @@

RQ_DASHBOARD_ENABLED = True

SITE_MODE = 'admin'
APP_MODE = 'admin'

MAIL_DEBUG = True
MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'
Expand Down
2 changes: 1 addition & 1 deletion config/development_party.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/production_party.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/test_admin.py
Expand Up @@ -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 <noreply@example.com>'
Expand Down
2 changes: 1 addition & 1 deletion config/test_party.py
Expand Up @@ -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
Expand Down

0 comments on commit 3cf5024

Please sign in to comment.