2023-03-17 22:10:19 +00:00
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
2022-06-25 15:44:17 +00:00
|
|
|
import {
|
|
|
|
EVENT_API_DRAWER_TOGGLE,
|
|
|
|
EVENT_NOTIFICATION_DRAWER_TOGGLE,
|
|
|
|
EVENT_WS_MESSAGE,
|
2022-09-14 22:05:21 +00:00
|
|
|
} from "@goauthentik/common/constants";
|
|
|
|
import { configureSentry } from "@goauthentik/common/sentry";
|
2023-03-23 13:05:14 +00:00
|
|
|
import { UserDisplay } from "@goauthentik/common/ui/config";
|
2022-09-14 22:05:21 +00:00
|
|
|
import { autoDetectLanguage } from "@goauthentik/common/ui/locale";
|
|
|
|
import { me } from "@goauthentik/common/users";
|
|
|
|
import { first } from "@goauthentik/common/utils";
|
|
|
|
import { WebsocketClient } from "@goauthentik/common/ws";
|
2023-03-09 22:17:53 +00:00
|
|
|
import { Interface } from "@goauthentik/elements/Base";
|
2022-09-14 22:05:21 +00:00
|
|
|
import "@goauthentik/elements/messages/MessageContainer";
|
2022-10-10 09:52:14 +00:00
|
|
|
import "@goauthentik/elements/notifications/APIDrawer";
|
2022-09-14 22:05:21 +00:00
|
|
|
import "@goauthentik/elements/notifications/NotificationDrawer";
|
|
|
|
import { getURLParam, updateURLParams } from "@goauthentik/elements/router/RouteMatch";
|
|
|
|
import "@goauthentik/elements/router/RouterOutlet";
|
|
|
|
import "@goauthentik/elements/sidebar/Sidebar";
|
|
|
|
import { DefaultTenant } from "@goauthentik/elements/sidebar/SidebarBrand";
|
|
|
|
import "@goauthentik/elements/sidebar/SidebarItem";
|
|
|
|
import { ROUTES } from "@goauthentik/user/Routes";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-09-21 09:31:37 +00:00
|
|
|
import { t } from "@lingui/macro";
|
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
import { CSSResult, TemplateResult, css, html } from "lit";
|
2023-02-04 17:30:22 +00:00
|
|
|
import { customElement, property, state } from "lit/decorators.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import PFAvatar from "@patternfly/patternfly/components/Avatar/avatar.css";
|
2021-09-16 20:17:05 +00:00
|
|
|
import PFBrand from "@patternfly/patternfly/components/Brand/brand.css";
|
2021-09-16 15:30:16 +00:00
|
|
|
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
|
|
|
import PFDrawer from "@patternfly/patternfly/components/Drawer/drawer.css";
|
2021-09-16 20:17:05 +00:00
|
|
|
import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css";
|
|
|
|
import PFNotificationBadge from "@patternfly/patternfly/components/NotificationBadge/notification-badge.css";
|
2021-09-21 09:31:37 +00:00
|
|
|
import PFPage from "@patternfly/patternfly/components/Page/page.css";
|
|
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
2021-10-13 09:23:26 +00:00
|
|
|
import PFDisplay from "@patternfly/patternfly/utilities/Display/display.css";
|
2021-09-16 15:30:16 +00:00
|
|
|
|
2023-03-17 22:10:19 +00:00
|
|
|
import { EventsApi, SessionUser } from "@goauthentik/api";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
autoDetectLanguage();
|
|
|
|
|
2021-09-16 15:30:16 +00:00
|
|
|
@customElement("ak-interface-user")
|
2023-03-09 22:17:53 +00:00
|
|
|
export class UserInterface extends Interface {
|
2021-09-16 15:30:16 +00:00
|
|
|
@property({ type: Boolean })
|
2021-11-18 20:40:34 +00:00
|
|
|
notificationDrawerOpen = getURLParam("notificationDrawerOpen", false);
|
2021-09-16 15:30:16 +00:00
|
|
|
|
|
|
|
@property({ type: Boolean })
|
2021-11-18 20:40:34 +00:00
|
|
|
apiDrawerOpen = getURLParam("apiDrawerOpen", false);
|
2021-09-16 15:30:16 +00:00
|
|
|
|
|
|
|
ws: WebsocketClient;
|
|
|
|
|
2021-09-16 20:17:05 +00:00
|
|
|
@property({ type: Number })
|
2022-06-18 11:36:18 +00:00
|
|
|
notificationsCount = 0;
|
2021-09-16 15:30:16 +00:00
|
|
|
|
2023-02-04 17:30:22 +00:00
|
|
|
@state()
|
|
|
|
me?: SessionUser;
|
|
|
|
|
2021-09-16 15:30:16 +00:00
|
|
|
static get styles(): CSSResult[] {
|
|
|
|
return [
|
|
|
|
PFBase,
|
2021-10-13 09:23:26 +00:00
|
|
|
PFDisplay,
|
2021-09-16 20:17:05 +00:00
|
|
|
PFBrand,
|
2021-09-16 15:30:16 +00:00
|
|
|
PFPage,
|
2021-09-16 20:17:05 +00:00
|
|
|
PFAvatar,
|
2021-09-16 15:30:16 +00:00
|
|
|
PFButton,
|
|
|
|
PFDrawer,
|
2021-09-16 20:17:05 +00:00
|
|
|
PFDropdown,
|
|
|
|
PFNotificationBadge,
|
2021-09-16 15:30:16 +00:00
|
|
|
css`
|
|
|
|
.pf-c-page__main,
|
|
|
|
.pf-c-drawer__content,
|
|
|
|
.pf-c-page__drawer {
|
|
|
|
z-index: auto !important;
|
2021-09-20 10:29:32 +00:00
|
|
|
background-color: transparent !important;
|
|
|
|
}
|
|
|
|
.pf-c-page {
|
2022-04-06 08:22:36 +00:00
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
.background-wrapper {
|
|
|
|
background-color: var(--pf-c-page--BackgroundColor) !important;
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
.display-none {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-09-16 20:17:05 +00:00
|
|
|
.pf-c-brand {
|
|
|
|
min-height: 48px;
|
2021-09-24 09:50:46 +00:00
|
|
|
height: 48px;
|
2021-09-16 20:17:05 +00:00
|
|
|
}
|
|
|
|
.has-notifications {
|
|
|
|
color: #2b9af3;
|
|
|
|
}
|
2022-04-05 21:47:15 +00:00
|
|
|
.background-wrapper {
|
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
position: absolute;
|
|
|
|
z-index: -1;
|
|
|
|
}
|
2021-09-16 15:30:16 +00:00
|
|
|
`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.ws = new WebsocketClient();
|
|
|
|
window.addEventListener(EVENT_NOTIFICATION_DRAWER_TOGGLE, () => {
|
2021-11-18 20:40:34 +00:00
|
|
|
this.notificationDrawerOpen = !this.notificationDrawerOpen;
|
|
|
|
updateURLParams({
|
|
|
|
notificationDrawerOpen: this.notificationDrawerOpen,
|
|
|
|
});
|
2021-09-16 15:30:16 +00:00
|
|
|
});
|
|
|
|
window.addEventListener(EVENT_API_DRAWER_TOGGLE, () => {
|
|
|
|
this.apiDrawerOpen = !this.apiDrawerOpen;
|
2021-11-18 20:40:34 +00:00
|
|
|
updateURLParams({
|
|
|
|
apiDrawerOpen: this.apiDrawerOpen,
|
|
|
|
});
|
2021-09-16 15:30:16 +00:00
|
|
|
});
|
2022-05-23 18:26:33 +00:00
|
|
|
window.addEventListener(EVENT_WS_MESSAGE, () => {
|
2021-09-19 19:58:59 +00:00
|
|
|
this.firstUpdated();
|
|
|
|
});
|
2021-09-22 20:35:52 +00:00
|
|
|
configureSentry(true);
|
2021-09-19 19:58:59 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 17:30:22 +00:00
|
|
|
async firstUpdated(): Promise<void> {
|
|
|
|
this.me = await me();
|
|
|
|
const notifications = await new EventsApi(DEFAULT_CONFIG).eventsNotificationsList({
|
|
|
|
seen: false,
|
|
|
|
ordering: "-created",
|
|
|
|
pageSize: 1,
|
|
|
|
user: this.me.user.pk,
|
2022-05-14 20:31:13 +00:00
|
|
|
});
|
2023-02-04 17:30:22 +00:00
|
|
|
this.notificationsCount = notifications.pagination.count;
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): TemplateResult {
|
2023-03-23 13:05:14 +00:00
|
|
|
if (!this.uiConfig || !this.me) {
|
2023-02-04 17:30:22 +00:00
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
let userDisplay = "";
|
2023-03-23 13:05:14 +00:00
|
|
|
switch (this.uiConfig.navbar.userDisplay) {
|
2023-02-04 17:30:22 +00:00
|
|
|
case UserDisplay.username:
|
|
|
|
userDisplay = this.me.user.username;
|
|
|
|
break;
|
|
|
|
case UserDisplay.name:
|
|
|
|
userDisplay = this.me.user.name;
|
|
|
|
break;
|
|
|
|
case UserDisplay.email:
|
|
|
|
userDisplay = this.me.user.email || "";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
userDisplay = this.me.user.username;
|
|
|
|
}
|
|
|
|
return html`<div class="pf-c-page">
|
2023-03-23 13:05:14 +00:00
|
|
|
<div class="background-wrapper" style="${this.uiConfig.theme.background}"></div>
|
2023-02-04 17:30:22 +00:00
|
|
|
<header class="pf-c-page__header">
|
|
|
|
<div class="pf-c-page__header-brand">
|
|
|
|
<a href="#/" class="pf-c-page__header-brand-link">
|
|
|
|
<img
|
|
|
|
class="pf-c-brand"
|
2023-03-17 22:10:19 +00:00
|
|
|
src="${first(this.tenant?.brandingLogo, DefaultTenant.brandingLogo)}"
|
|
|
|
alt="${(this.tenant?.brandingTitle, DefaultTenant.brandingTitle)}"
|
2023-02-04 17:30:22 +00:00
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-page__header-tools">
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
2023-03-23 13:05:14 +00:00
|
|
|
${this.uiConfig.enabledFeatures.apiDrawer
|
2023-02-04 17:30:22 +00:00
|
|
|
? html`<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-lg"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
|
|
|
type="button"
|
|
|
|
@click=${() => {
|
|
|
|
this.apiDrawerOpen = !this.apiDrawerOpen;
|
|
|
|
updateURLParams({
|
|
|
|
apiDrawerOpen: this.apiDrawerOpen,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<i class="fas fa-code" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
</div>`
|
|
|
|
: html``}
|
2023-03-23 13:05:14 +00:00
|
|
|
${this.uiConfig.enabledFeatures.notificationDrawer
|
2023-02-04 17:30:22 +00:00
|
|
|
? html`<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-lg"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
|
|
|
type="button"
|
|
|
|
aria-label="${t`Unread notifications`}"
|
|
|
|
@click=${() => {
|
|
|
|
this.notificationDrawerOpen =
|
|
|
|
!this.notificationDrawerOpen;
|
|
|
|
updateURLParams({
|
|
|
|
notificationDrawerOpen: this.notificationDrawerOpen,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class="pf-c-notification-badge ${this.notificationsCount >
|
|
|
|
0
|
|
|
|
? "pf-m-unread"
|
|
|
|
: ""}"
|
2021-09-20 10:29:32 +00:00
|
|
|
>
|
2023-02-04 17:30:22 +00:00
|
|
|
<i class="pf-icon-bell" aria-hidden="true"></i>
|
|
|
|
<span class="pf-c-notification-badge__count"
|
|
|
|
>${this.notificationsCount}</span
|
2021-09-20 10:29:32 +00:00
|
|
|
>
|
2023-02-04 17:30:22 +00:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</div> `
|
|
|
|
: html``}
|
2023-03-23 13:05:14 +00:00
|
|
|
${this.uiConfig.enabledFeatures.settings
|
2023-02-04 17:30:22 +00:00
|
|
|
? html` <div class="pf-c-page__header-tools-item">
|
|
|
|
<a class="pf-c-button pf-m-plain" type="button" href="#/settings">
|
|
|
|
<i class="fas fa-cog" aria-hidden="true"></i>
|
|
|
|
</a>
|
|
|
|
</div>`
|
|
|
|
: html``}
|
|
|
|
<div class="pf-c-page__header-tools-item">
|
|
|
|
<a href="/flows/-/default/invalidation/" class="pf-c-button pf-m-plain">
|
|
|
|
<i class="fas fa-sign-out-alt" aria-hidden="true"></i>
|
|
|
|
</a>
|
2021-09-16 20:17:05 +00:00
|
|
|
</div>
|
2023-02-04 17:30:22 +00:00
|
|
|
${this.me.user.isSuperuser
|
|
|
|
? html`<a
|
|
|
|
class="pf-c-button pf-m-primary pf-m-small pf-u-display-none pf-u-display-block-on-md"
|
|
|
|
href="/if/admin"
|
|
|
|
>
|
|
|
|
${t`Admin interface`}
|
|
|
|
</a>`
|
|
|
|
: html``}
|
|
|
|
</div>
|
|
|
|
${this.me.original
|
|
|
|
? html`<div class="pf-c-page__header-tools">
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
|
|
|
<a
|
|
|
|
class="pf-c-button pf-m-warning pf-m-small"
|
|
|
|
href=${`/-/impersonation/end/?back=${encodeURIComponent(
|
|
|
|
`${window.location.pathname}#${window.location.hash}`,
|
|
|
|
)}`}
|
|
|
|
>
|
|
|
|
${t`Stop impersonation`}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>`
|
|
|
|
: html``}
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
|
|
|
<div class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-md">
|
|
|
|
${userDisplay}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<img class="pf-c-avatar" src=${this.me.user.avatar} alt="${t`Avatar image`}" />
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="pf-c-page__drawer">
|
|
|
|
<div
|
|
|
|
class="pf-c-drawer ${this.notificationDrawerOpen || this.apiDrawerOpen
|
|
|
|
? "pf-m-expanded"
|
|
|
|
: "pf-m-collapsed"}"
|
|
|
|
>
|
|
|
|
<div class="pf-c-drawer__main">
|
|
|
|
<div class="pf-c-drawer__content">
|
|
|
|
<div class="pf-c-drawer__body">
|
|
|
|
<main class="pf-c-page__main">
|
|
|
|
<ak-router-outlet
|
|
|
|
role="main"
|
|
|
|
class="pf-l-bullseye__item pf-c-page__main"
|
|
|
|
tabindex="-1"
|
|
|
|
id="main-content"
|
|
|
|
defaultUrl="/library"
|
|
|
|
.routes=${ROUTES}
|
|
|
|
>
|
|
|
|
</ak-router-outlet>
|
|
|
|
</main>
|
2021-09-16 15:30:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-04 17:30:22 +00:00
|
|
|
<ak-notification-drawer
|
|
|
|
class="pf-c-drawer__panel pf-m-width-33 ${this.notificationDrawerOpen
|
|
|
|
? ""
|
|
|
|
: "display-none"}"
|
|
|
|
?hidden=${!this.notificationDrawerOpen}
|
|
|
|
></ak-notification-drawer>
|
|
|
|
<ak-api-drawer
|
|
|
|
class="pf-c-drawer__panel pf-m-width-33 ${this.apiDrawerOpen
|
|
|
|
? ""
|
|
|
|
: "display-none"}"
|
|
|
|
?hidden=${!this.apiDrawerOpen}
|
|
|
|
></ak-api-drawer>
|
2021-09-16 15:30:16 +00:00
|
|
|
</div>
|
2023-02-04 17:30:22 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|