From aa86f5de487edd9a38e93ff94f7dcf62e487f679 Mon Sep 17 00:00:00 2001 From: xeals Date: Sat, 3 Sep 2022 15:03:29 +1000 Subject: [PATCH] routes/home: configure brand name --- frontpage/config.py | 5 +++-- frontpage/routes.py | 10 +++++++--- frontpage/templates/home.html | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frontpage/config.py b/frontpage/config.py index 2dcca99..66da0e1 100644 --- a/frontpage/config.py +++ b/frontpage/config.py @@ -15,6 +15,7 @@ class CoreConfig: debug: bool = False port: int = 5000 + name: str = "Front page" @dataclass @@ -43,8 +44,8 @@ class AppConfig: class Config: """Top-level configuration.""" - core: CoreConfig - oidc: OidcConfig + core: CoreConfig = field(default_factory=CoreConfig) + oidc: OidcConfig = field(default_factory=OidcConfig) apps: Dict[str, AppConfig] = field(default_factory=dict) diff --git a/frontpage/routes.py b/frontpage/routes.py index 42fce10..b9efc27 100644 --- a/frontpage/routes.py +++ b/frontpage/routes.py @@ -7,7 +7,7 @@ from flask import Blueprint, current_app, render_template from flask_pyoidc import OIDCAuthentication from flask_pyoidc.user_session import UserSession -from frontpage.config import AppConfig, current_config +from frontpage.config import AppConfig, Config, current_config def _allowed(items_from: Iterable[Any], items_in: Iterable[Any]) -> bool: @@ -31,10 +31,14 @@ def register(auth: OIDCAuthentication, auth_provider: str) -> Blueprint: user_session = UserSession(flask.session) groups: List[str] = user_session.userinfo["groups"] - apps: AppConfig = current_config().apps + config: Config = current_config() + name = config.core.name + apps = config.apps allowed_apps = { ident: a for ident, a in apps.items() if _allowed(a.groups, groups) } - return render_template("home.html", apps=allowed_apps, groups=groups) + return render_template( + "home.html", brand_name=name, apps=allowed_apps, groups=groups + ) return routes diff --git a/frontpage/templates/home.html b/frontpage/templates/home.html index abb0496..e14eafd 100644 --- a/frontpage/templates/home.html +++ b/frontpage/templates/home.html @@ -8,7 +8,7 @@