import { ROUTES } from "@goauthentik/admin/Routes"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_API_DRAWER_TOGGLE, EVENT_NOTIFICATION_DRAWER_TOGGLE, EVENT_SIDEBAR_TOGGLE, VERSION, } from "@goauthentik/common/constants"; import { autoDetectLanguage } from "@goauthentik/common/ui/locale"; import { me } from "@goauthentik/common/users"; import { WebsocketClient } from "@goauthentik/common/ws"; import { Interface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/notifications/APIDrawer"; import "@goauthentik/elements/notifications/NotificationDrawer"; import { ID_REGEX, SLUG_REGEX, UUID_REGEX } from "@goauthentik/elements/router/Route"; import { getURLParam, updateURLParams } from "@goauthentik/elements/router/RouteMatch"; import "@goauthentik/elements/router/RouterOutlet"; import "@goauthentik/elements/sidebar/Sidebar"; import "@goauthentik/elements/sidebar/SidebarItem"; import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css"; import PFPage from "@patternfly/patternfly/components/Page/page.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import { AdminApi, SessionUser, Version } from "@goauthentik/api"; autoDetectLanguage(); @customElement("ak-interface-admin") export class AdminInterface extends Interface { @property({ type: Boolean }) sidebarOpen = true; @property({ type: Boolean }) notificationDrawerOpen = getURLParam("notificationDrawerOpen", false); @property({ type: Boolean }) apiDrawerOpen = getURLParam("apiDrawerOpen", false); ws: WebsocketClient; @state() version?: Version; @state() user?: SessionUser; static get styles(): CSSResult[] { return [ PFBase, PFPage, PFButton, PFDrawer, css` .pf-c-page__main, .pf-c-drawer__content, .pf-c-page__drawer { z-index: auto !important; background-color: transparent; } .display-none { display: none; } .pf-c-page { background-color: var(--pf-c-page--BackgroundColor) !important; } /* Global page background colour */ :host([theme="dark"]) .pf-c-page { --pf-c-page--BackgroundColor: var(--ak-dark-background); } `, ]; } constructor() { super(); this.ws = new WebsocketClient(); this.sidebarOpen = window.innerWidth >= 1280; window.addEventListener("resize", () => { this.sidebarOpen = window.innerWidth >= 1280; }); window.addEventListener(EVENT_SIDEBAR_TOGGLE, () => { this.sidebarOpen = !this.sidebarOpen; }); window.addEventListener(EVENT_NOTIFICATION_DRAWER_TOGGLE, () => { this.notificationDrawerOpen = !this.notificationDrawerOpen; updateURLParams({ notificationDrawerOpen: this.notificationDrawerOpen, }); }); window.addEventListener(EVENT_API_DRAWER_TOGGLE, () => { this.apiDrawerOpen = !this.apiDrawerOpen; updateURLParams({ apiDrawerOpen: this.apiDrawerOpen, }); }); } async firstUpdated(): Promise { this.version = await new AdminApi(DEFAULT_CONFIG).adminVersionRetrieve(); this.user = await me(); if (!this.user.user.isSuperuser && this.user.user.pk > 0) { window.location.assign("/if/user"); } } render(): TemplateResult { return html`
${this.renderSidebarItems()}
`; } renderSidebarItems(): TemplateResult { return html` ${this.version && this.version.versionCurrent !== VERSION ? html` ${t`A newer version of the frontend is available.`} ` : html``} ${this.user?.original ? html` ${t`You're currently impersonating ${this.user.user.username}. Click to stop.`} ` : html``} ${t`User interface`} ${t`Dashboards`} ${t`Overview`} ${t`Users`} ${t`System Tasks`} ${t`Applications`} ${SLUG_REGEX})$`]} > ${t`Applications`} ${ID_REGEX})$`]} > ${t`Providers`} ${t`Outposts`} ${t`Events`} ${UUID_REGEX})$`]} > ${t`Logs`} ${t`Notification Rules`} ${t`Notification Transports`} ${t`Customisation`} ${t`Policies`} ${t`Property Mappings`} ${t`Blueprints`} ${t`Reputation scores`} ${t`Flows & Stages`} ${SLUG_REGEX})$`]} > ${t`Flows`} ${t`Stages`} ${t`Prompts`} ${t`Directory`} ${ID_REGEX})$`]} > ${t`Users`} ${UUID_REGEX})$`]} > ${t`Groups`} ${SLUG_REGEX})$`]} > ${t`Federation & Social login`} ${t`Tokens & App passwords`} ${t`Invitations`} ${t`System`} ${t`Tenants`} ${t`Certificates`} ${t`Outpost Integrations`} `; } }