import "@goauthentik/admin/AdminInterface/AboutModal"; import type { AboutModal } from "@goauthentik/admin/AdminInterface/AboutModal"; import { ROUTES } from "@goauthentik/admin/Routes"; import { EVENT_API_DRAWER_TOGGLE, EVENT_NOTIFICATION_DRAWER_TOGGLE, EVENT_SIDEBAR_TOGGLE, } from "@goauthentik/common/constants"; import { configureSentry } from "@goauthentik/common/sentry"; import { me } from "@goauthentik/common/users"; import { WebsocketClient } from "@goauthentik/common/ws"; import { AuthenticatedInterface } from "@goauthentik/elements/Interface"; import "@goauthentik/elements/ak-locale-context"; import "@goauthentik/elements/banner/EnterpriseStatusBanner"; import "@goauthentik/elements/banner/EnterpriseStatusBanner"; import "@goauthentik/elements/banner/VersionBanner"; import "@goauthentik/elements/banner/VersionBanner"; import "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/notifications/APIDrawer"; import "@goauthentik/elements/notifications/NotificationDrawer"; import { getURLParam, updateURLParams } from "@goauthentik/elements/router/RouteMatch"; import "@goauthentik/elements/router/RouterOutlet"; import "@goauthentik/elements/sidebar/Sidebar"; import "@goauthentik/elements/sidebar/SidebarItem"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, property, query, state } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.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 { SessionUser, UiThemeEnum } from "@goauthentik/api"; import "./AdminSidebar"; if (process.env.NODE_ENV === "development") { await import("@goauthentik/esbuild-plugin-live-reload/client"); } @customElement("ak-interface-admin") export class AdminInterface extends AuthenticatedInterface { //#region Properties @property({ type: Boolean }) notificationDrawerOpen = getURLParam("notificationDrawerOpen", false); @property({ type: Boolean }) apiDrawerOpen = getURLParam("apiDrawerOpen", false); ws: WebsocketClient; @state() user?: SessionUser; @query("ak-about-modal") aboutModal?: AboutModal; @state() sidebarVisible = false; #toggleSidebar = () => { this.sidebarVisible = !this.sidebarVisible; }; //#endregion //#region Styles 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; } :host([theme="dark"]) { /* Global page background colour */ .pf-c-page { --pf-c-page--BackgroundColor: var(--ak-dark-background); } } ak-page-navbar { grid-area: header; } ak-admin-sidebar { grid-area: nav; } .pf-c-drawer__panel { z-index: var(--pf-global--ZIndex--xl); } `, ]; } //#endregion //#region Lifecycle constructor() { super(); this.ws = new WebsocketClient(); 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 { configureSentry(true); this.user = await me(); const canAccessAdmin = this.user.user.isSuperuser || // TODO: somehow add `access_admin_interface` to the API schema this.user.user.systemPermissions.includes("access_admin_interface"); if (!canAccessAdmin && this.user.user.pk > 0) { window.location.assign("/if/user/"); } } async connectedCallback(): Promise { super.connectedCallback(); window.addEventListener(EVENT_SIDEBAR_TOGGLE, this.#toggleSidebar); } disconnectedCallback(): void { super.disconnectedCallback(); window.removeEventListener(EVENT_SIDEBAR_TOGGLE, this.#toggleSidebar); } render(): TemplateResult { const sidebarClasses = { "pf-m-light": this.activeTheme === UiThemeEnum.Light, "pf-m-expanded": !this.sidebarVisible, "pf-m-collapsed": this.sidebarVisible, }; const drawerOpen = this.notificationDrawerOpen || this.apiDrawerOpen; const drawerClasses = { "pf-m-expanded": drawerOpen, "pf-m-collapsed": !drawerOpen, }; return html`
`; } } declare global { interface HTMLElementTagNameMap { "ak-interface-admin": AdminInterface; } }