From b8e394227ef984990a8fb2441dbe5883e1cef198 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Mon, 19 May 2025 00:45:00 +0200 Subject: [PATCH] web: Clean up version constants. Tidy types --- web/src/admin/AdminInterface/AboutModal.ts | 3 +- .../admin/admin-overview/AdminOverviewPage.ts | 66 ++++--------------- web/src/common/api/config.ts | 6 +- web/src/common/constants.ts | 35 +++++++++- web/src/common/helpers/plex.ts | 3 +- web/src/common/sentry/index.ts | 3 +- web/src/components/ak-event-info.ts | 3 +- web/src/elements/banner/VersionBanner.ts | 24 ++++--- 8 files changed, 65 insertions(+), 78 deletions(-) diff --git a/web/src/admin/AdminInterface/AboutModal.ts b/web/src/admin/AdminInterface/AboutModal.ts index d947ba43ac..d5b7e7e71a 100644 --- a/web/src/admin/AdminInterface/AboutModal.ts +++ b/web/src/admin/AdminInterface/AboutModal.ts @@ -1,5 +1,4 @@ import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; -import { VERSION } from "@goauthentik/common/constants"; import { globalAK } from "@goauthentik/common/global"; import { DefaultBrand } from "@goauthentik/common/ui/config"; import "@goauthentik/elements/EmptyState"; @@ -45,7 +44,7 @@ export class AboutModal extends WithLicenseSummary(WithBrandConfig(ModalButton)) } return [ [msg("Version"), version.versionCurrent], - [msg("UI Version"), VERSION], + [msg("UI Version"), import.meta.env.AK_VERSION], [msg("Build"), build], [msg("Python version"), status.runtime.pythonVersion], [msg("Platform"), status.runtime.platform], diff --git a/web/src/admin/admin-overview/AdminOverviewPage.ts b/web/src/admin/admin-overview/AdminOverviewPage.ts index 8a750f15fc..db4d88f6c0 100644 --- a/web/src/admin/admin-overview/AdminOverviewPage.ts +++ b/web/src/admin/admin-overview/AdminOverviewPage.ts @@ -8,7 +8,6 @@ import "@goauthentik/admin/admin-overview/cards/WorkerStatusCard"; import "@goauthentik/admin/admin-overview/charts/AdminLoginAuthorizeChart"; import "@goauthentik/admin/admin-overview/charts/OutpostStatusChart"; import "@goauthentik/admin/admin-overview/charts/SyncStatusChart"; -import { VERSION } from "@goauthentik/common/constants"; import { me } from "@goauthentik/common/users"; import { AKElement } from "@goauthentik/elements/Base"; import { WithLicenseSummary } from "@goauthentik/elements/Interface/licenseSummaryProvider.js"; @@ -22,8 +21,6 @@ import { msg, str } from "@lit/localize"; import { CSSResult, TemplateResult, css, html, nothing } from "lit"; import { customElement, state } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.js"; -import { map } from "lit/directives/map.js"; -import { when } from "lit/directives/when.js"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; import PFDivider from "@patternfly/patternfly/components/Divider/divider.css"; @@ -33,21 +30,17 @@ import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { SessionUser } from "@goauthentik/api"; -export function versionFamily(): string { - const parts = VERSION.split("."); - parts.pop(); - return parts.join("."); +function createReleaseNotesURL(semver: string): URL { + const segments = semver.split("."); + const versionFamily = segments.slice(0, -1).join("."); + + const release = `${versionFamily}#fixed-in-${segments.join("")}`; + + return new URL(`/docs/releases/${release}`, "https://goauthentik.io"); } -const RELEASE = `${VERSION.split(".").slice(0, -1).join(".")}#fixed-in-${VERSION.replaceAll( - ".", - "", -)}`; - const AdminOverviewBase = WithLicenseSummary(AKElement); -type Renderer = () => TemplateResult | typeof nothing; - @customElement("ak-admin-overview") export class AdminOverviewPage extends AdminOverviewBase { static get styles(): CSSResult[] { @@ -83,7 +76,11 @@ export class AdminOverviewPage extends AdminOverviewBase { [msg("Check the logs"), paramURL("/events/log")], [msg("Explore integrations"), "https://goauthentik.io/integrations/", true], [msg("Manage users"), paramURL("/identity/users")], - [msg("Check the release notes"), `https://goauthentik.io/docs/releases/${RELEASE}`, true], + [ + msg("Check the release notes"), + createReleaseNotesURL(import.meta.env.AK_VERSION).href, + true, + ], ]; @state() @@ -193,45 +190,6 @@ export class AdminOverviewPage extends AdminOverviewBase { ` : nothing} `; } - - renderActions() { - const release = `${versionFamily()}#fixed-in-${VERSION.replaceAll(".", "")}`; - - const quickActions: [string, string][] = [ - [msg("Create a new application"), paramURL("/core/applications", { createForm: true })], - [msg("Check the logs"), paramURL("/events/log")], - [msg("Explore integrations"), "https://goauthentik.io/integrations/"], - [msg("Manage users"), paramURL("/identity/users")], - [msg("Check the release notes"), `https://goauthentik.io/docs/releases/${release}`], - ]; - - const action = ([label, url]: [string, string]) => { - const isExternal = url.startsWith("https://"); - const ex = (truecase: Renderer, falsecase: Renderer) => - when(isExternal, truecase, falsecase); - - const content = html`${label}${ex( - () => html``, - () => nothing, - )}`; - - return html`
  • - ${ex( - () => - html`${content}`, - () => html`${content}`, - )} -
  • `; - }; - - return html`${map(quickActions, action)}`; - } } declare global { diff --git a/web/src/common/api/config.ts b/web/src/common/api/config.ts index d003cb5029..a22a214aac 100644 --- a/web/src/common/api/config.ts +++ b/web/src/common/api/config.ts @@ -3,7 +3,7 @@ import { EventMiddleware, LoggingMiddleware, } from "@goauthentik/common/api/middleware.js"; -import { EVENT_LOCALE_REQUEST, VERSION } from "@goauthentik/common/constants.js"; +import { EVENT_LOCALE_REQUEST } from "@goauthentik/common/constants.js"; import { globalAK } from "@goauthentik/common/global.js"; import { SentryMiddleware } from "@goauthentik/common/sentry/middleware"; @@ -79,4 +79,6 @@ export function AndNext(url: string): string { return `?next=${encodeURIComponent(url)}`; } -console.debug(`authentik(early): version ${VERSION}, apiBase ${DEFAULT_CONFIG.basePath}`); +console.debug( + `authentik(early): version ${import.meta.env.AK_VERSION}, apiBase ${DEFAULT_CONFIG.basePath}`, +); diff --git a/web/src/common/constants.ts b/web/src/common/constants.ts index 917d480457..040105aca2 100644 --- a/web/src/common/constants.ts +++ b/web/src/common/constants.ts @@ -1,12 +1,35 @@ +/** + * @file Global constants used throughout the application. + * + * @todo Much of this content can be moved to a specific file, element, or component. + */ + +/// + +//#region Patternfly + export const SECONDARY_CLASS = "pf-m-secondary"; export const SUCCESS_CLASS = "pf-m-success"; export const ERROR_CLASS = "pf-m-danger"; export const PROGRESS_CLASS = "pf-m-in-progress"; export const CURRENT_CLASS = "pf-m-current"; -export const VERSION = "2025.4.1"; + +//#endregion + +//#region Application + export const TITLE_DEFAULT = "authentik"; +/** + * The delimiter used to parse the URL for the current route. + * + * @todo Move this to the ak-router. + */ export const ROUTE_SEPARATOR = ";"; +//#endregion + +//#region Events + export const EVENT_REFRESH = "ak-refresh"; export const EVENT_NOTIFICATION_DRAWER_TOGGLE = "ak-notification-toggle"; export const EVENT_API_DRAWER_TOGGLE = "ak-api-drawer-toggle"; @@ -20,7 +43,17 @@ export const EVENT_MESSAGE = "ak-message"; export const EVENT_THEME_CHANGE = "ak-theme-change"; export const EVENT_REFRESH_ENTERPRISE = "ak-refresh-enterprise"; +//#endregion + +//#region WebSocket + export const WS_MSG_TYPE_MESSAGE = "message"; export const WS_MSG_TYPE_REFRESH = "refresh"; +//#endregion + +//#region LocalStorage + export const LOCALSTORAGE_AUTHENTIK_KEY = "authentik-local-settings"; + +//#endregion diff --git a/web/src/common/helpers/plex.ts b/web/src/common/helpers/plex.ts index 228a505a07..4172d6672e 100644 --- a/web/src/common/helpers/plex.ts +++ b/web/src/common/helpers/plex.ts @@ -1,4 +1,3 @@ -import { VERSION } from "@goauthentik/common/constants"; import { SentryIgnoredError } from "@goauthentik/common/sentry"; export interface PlexPinResponse { @@ -19,7 +18,7 @@ export const DEFAULT_HEADERS = { "Accept": "application/json", "Content-Type": "application/json", "X-Plex-Product": "authentik", - "X-Plex-Version": VERSION, + "X-Plex-Version": import.meta.env.AK_VERSION, "X-Plex-Device-Vendor": "goauthentik.io", }; diff --git a/web/src/common/sentry/index.ts b/web/src/common/sentry/index.ts index 7aede31d78..37150e5f24 100644 --- a/web/src/common/sentry/index.ts +++ b/web/src/common/sentry/index.ts @@ -1,4 +1,3 @@ -import { VERSION } from "@goauthentik/common/constants"; import { globalAK } from "@goauthentik/common/global"; import { me } from "@goauthentik/common/users"; import { readInterfaceRouteParam } from "@goauthentik/elements/router/utils"; @@ -41,7 +40,7 @@ export function configureSentry(canDoPpi = false) { /MutationObserver.observe/gi, /NS_ERROR_FAILURE/gi, ], - release: `authentik@${VERSION}`, + release: `authentik@${import.meta.env.AK_VERSION}`, integrations: [ browserTracingIntegration({ // https://docs.sentry.io/platforms/javascript/tracing/instrumentation/automatic-instrumentation/#custom-routing diff --git a/web/src/components/ak-event-info.ts b/web/src/components/ak-event-info.ts index 2b2af8f284..23847ba8bc 100644 --- a/web/src/components/ak-event-info.ts +++ b/web/src/components/ak-event-info.ts @@ -1,5 +1,4 @@ import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; -import { VERSION } from "@goauthentik/common/constants"; import { PFSize } from "@goauthentik/common/enums.js"; import { EventContext, @@ -76,7 +75,7 @@ ${context.message as string} **Version and Deployment (please complete the following information):** -- authentik version: ${VERSION} +- authentik version: ${import.meta.env.AK_VERSION} - Deployment: [e.g. docker-compose, helm] **Additional context** diff --git a/web/src/elements/banner/VersionBanner.ts b/web/src/elements/banner/VersionBanner.ts index 9c8a6bf0bd..a5cb651118 100644 --- a/web/src/elements/banner/VersionBanner.ts +++ b/web/src/elements/banner/VersionBanner.ts @@ -1,4 +1,3 @@ -import { VERSION } from "@goauthentik/common/constants"; import { AKElement } from "@goauthentik/elements/Base"; import { WithVersion } from "@goauthentik/elements/Interface/versionProvider"; @@ -10,20 +9,19 @@ import PFBanner from "@patternfly/patternfly/components/Banner/banner.css"; @customElement("ak-version-banner") export class VersionBanner extends WithVersion(AKElement) { - static get styles() { - return [PFBanner]; - } + static styles = [PFBanner]; render() { - return this.version && this.version.versionCurrent !== VERSION - ? html` -
    - ${msg( - str`A newer version (${this.version.versionCurrent}) of the UI is available.`, - )} -
    - ` - : nothing; + if (!this.version?.versionCurrent) return nothing; + if (this.version.versionCurrent === import.meta.env.AK_VERSION) return nothing; + + return html` +
    + ${msg( + str`A newer version (${this.version.versionCurrent}) of the UI is available.`, + )} +
    + `; } }