From 10110deae5e8ffa9c5173addf7a96a30707754a2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 24 Dec 2021 20:04:21 +0100 Subject: [PATCH] web/admin: add Admin in titlebar for admin interface Signed-off-by: Jens Langhammer --- web/src/api/Sentry.ts | 20 ++++++++++++-------- web/src/elements/PageHeader.ts | 15 +++++++++++---- web/src/locales/en.po | 6 +++--- web/src/locales/fr_FR.po | 5 +++-- web/src/locales/pseudo-LOCALE.po | 6 +++--- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index 58ca538d9..31f43a264 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -45,14 +45,8 @@ export function configureSentry(canDoPpi: boolean = false): Promise { }); Sentry.setTag(TAG_SENTRY_CAPABILITIES, config.capabilities.join(",")); if (window.location.pathname.includes("if/")) { - // Get the interface name from URL - const pathMatches = window.location.pathname.match(/.+if\/(\w+)\//); - let currentInterface = "unknown"; - if (pathMatches && pathMatches.length >= 2) { - currentInterface = pathMatches[1]; - } - Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface}`); - Sentry.configureScope((scope) => scope.setTransactionName(`authentik.web.if.${currentInterface}`)); + Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface()}`); + Sentry.configureScope((scope) => scope.setTransactionName(`authentik.web.if.${currentInterface()}`)); } if (config.errorReporting.sendPii && canDoPpi) { me().then(user => { @@ -66,3 +60,13 @@ export function configureSentry(canDoPpi: boolean = false): Promise { return config; }); } + +// Get the interface name from URL +export function currentInterface(): string { + const pathMatches = window.location.pathname.match(/.+if\/(\w+)\//); + let currentInterface = "unknown"; + if (pathMatches && pathMatches.length >= 2) { + currentInterface = pathMatches[1]; + } + return currentInterface; +} diff --git a/web/src/elements/PageHeader.ts b/web/src/elements/PageHeader.ts index 9ead25281..1674b1d11 100644 --- a/web/src/elements/PageHeader.ts +++ b/web/src/elements/PageHeader.ts @@ -1,3 +1,5 @@ +import { t } from "@lingui/macro"; + import { CSSResult, LitElement, TemplateResult, css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; @@ -10,6 +12,7 @@ import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { EventsApi } from "@goauthentik/api"; import { DEFAULT_CONFIG, tenant } from "../api/Config"; +import { currentInterface } from "../api/Sentry"; import { EVENT_API_DRAWER_TOGGLE, EVENT_NOTIFICATION_DRAWER_TOGGLE, @@ -32,11 +35,15 @@ export class PageHeader extends LitElement { @property() set header(value: string) { tenant().then((tenant) => { - if (value !== "") { - document.title = `${value} - ${tenant.brandingTitle}`; - } else { - document.title = tenant.brandingTitle || TITLE_DEFAULT; + const currentIf = currentInterface(); + let title = tenant.brandingTitle || TITLE_DEFAULT; + if (currentIf === "admin") { + title = `${t`Admin`} - ${title}`; } + if (value !== "") { + title = `${value} - ${title}`; + } + document.title = title; }); this._header = value; } diff --git a/web/src/locales/en.po b/web/src/locales/en.po index 9193f47e8..770d13eb0 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -224,9 +224,9 @@ msgstr "Additional settings" msgid "Additional user DN, prepended to the Base DN." msgstr "Additional user DN, prepended to the Base DN." -#: -#~ msgid "Admin" -#~ msgstr "Admin" +#: src/elements/PageHeader.ts +msgid "Admin" +msgstr "Admin" #: src/interfaces/UserInterface.ts msgid "Admin interface" diff --git a/web/src/locales/fr_FR.po b/web/src/locales/fr_FR.po index 653b30abe..190f4ca88 100644 --- a/web/src/locales/fr_FR.po +++ b/web/src/locales/fr_FR.po @@ -229,8 +229,9 @@ msgstr "Paramètres supplémentaire" msgid "Additional user DN, prepended to the Base DN." msgstr "DN à préfixer au DN de base pour les utilisateurs" -#~ msgid "Admin" -#~ msgstr "Administrateur" +#: src/elements/PageHeader.ts +msgid "Admin" +msgstr "Administrateur" #: src/interfaces/UserInterface.ts msgid "Admin interface" diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index 3601b4324..179cdecce 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -224,9 +224,9 @@ msgstr "" msgid "Additional user DN, prepended to the Base DN." msgstr "" -#: -#~ msgid "Admin" -#~ msgstr "" +#: src/elements/PageHeader.ts +msgid "Admin" +msgstr "" #: src/interfaces/UserInterface.ts msgid "Admin interface"