2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG, tenant } 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";
|
|
|
|
import { UserDisplay, uiConfig } from "@goauthentik/common/ui/config";
|
|
|
|
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";
|
|
|
|
import { AKElement } from "@goauthentik/elements/Base";
|
|
|
|
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";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
import { until } from "lit/directives/until.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
import AKGlobal from "@goauthentik/common/styles/authentik.css";
|
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
|
|
|
|
2021-09-21 09:31:37 +00:00
|
|
|
import { CurrentTenant, EventsApi } from "@goauthentik/api";
|
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
autoDetectLanguage();
|
|
|
|
|
2021-09-16 15:30:16 +00:00
|
|
|
@customElement("ak-interface-user")
|
2022-09-14 22:05:21 +00:00
|
|
|
export class UserInterface extends AKElement {
|
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({ attribute: false })
|
|
|
|
tenant: CurrentTenant = DefaultTenant;
|
|
|
|
|
|
|
|
@property({ type: Number })
|
2022-06-18 11:36:18 +00:00
|
|
|
notificationsCount = 0;
|
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
|
|
|
AKGlobal,
|
|
|
|
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-16 20:17:05 +00:00
|
|
|
tenant().then((tenant) => (this.tenant = tenant));
|
2021-09-22 20:35:52 +00:00
|
|
|
configureSentry(true);
|
2021-09-19 19:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
firstUpdated(): void {
|
2022-05-14 20:31:13 +00:00
|
|
|
me().then((user) => {
|
|
|
|
new EventsApi(DEFAULT_CONFIG)
|
|
|
|
.eventsNotificationsList({
|
|
|
|
seen: false,
|
|
|
|
ordering: "-created",
|
|
|
|
pageSize: 1,
|
|
|
|
user: user.user.pk,
|
|
|
|
})
|
|
|
|
.then((r) => {
|
|
|
|
this.notificationsCount = r.pagination.count;
|
|
|
|
});
|
|
|
|
});
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): TemplateResult {
|
2021-09-20 10:29:32 +00:00
|
|
|
return html`${until(
|
|
|
|
uiConfig().then((config) => {
|
2022-04-05 21:47:15 +00:00
|
|
|
return html`<div class="pf-c-page">
|
|
|
|
<div class="background-wrapper" style="${config.theme.background}"></div>
|
2021-09-20 10:29:32 +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"
|
|
|
|
src="${first(
|
|
|
|
this.tenant.brandingLogo,
|
|
|
|
DefaultTenant.brandingLogo,
|
|
|
|
)}"
|
|
|
|
alt="${(this.tenant.brandingTitle,
|
|
|
|
DefaultTenant.brandingTitle)}"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="pf-c-page__header-tools">
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
|
|
|
${config.enabledFeatures.apiDrawer
|
|
|
|
? 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;
|
2021-11-18 20:40:34 +00:00
|
|
|
updateURLParams({
|
|
|
|
apiDrawerOpen: this.apiDrawerOpen,
|
|
|
|
});
|
2021-09-20 10:29:32 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<i class="fas fa-code" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
</div>`
|
|
|
|
: html``}
|
|
|
|
${config.enabledFeatures.notificationDrawer
|
2021-10-13 09:23:26 +00:00
|
|
|
? html`<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-lg"
|
|
|
|
>
|
2021-09-20 10:29:32 +00:00
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
|
|
|
type="button"
|
|
|
|
aria-label="${t`Unread notifications`}"
|
|
|
|
@click=${() => {
|
2021-11-18 20:40:34 +00:00
|
|
|
this.notificationDrawerOpen =
|
|
|
|
!this.notificationDrawerOpen;
|
|
|
|
updateURLParams({
|
|
|
|
notificationDrawerOpen:
|
|
|
|
this.notificationDrawerOpen,
|
|
|
|
});
|
2021-09-20 10:29:32 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class="pf-c-notification-badge ${this
|
|
|
|
.notificationsCount > 0
|
|
|
|
? "pf-m-unread"
|
|
|
|
: ""}"
|
|
|
|
>
|
|
|
|
<i class="pf-icon-bell" aria-hidden="true"></i>
|
|
|
|
<span class="pf-c-notification-badge__count"
|
|
|
|
>${this.notificationsCount}</span
|
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</button>
|
2021-10-13 09:23:26 +00:00
|
|
|
</div> `
|
2021-09-20 10:29:32 +00:00
|
|
|
: html``}
|
|
|
|
${config.enabledFeatures.settings
|
2021-10-13 09:23:26 +00:00
|
|
|
? html` <div class="pf-c-page__header-tools-item">
|
2021-09-20 10:29:32 +00:00
|
|
|
<a
|
|
|
|
class="pf-c-button pf-m-plain"
|
|
|
|
type="button"
|
|
|
|
href="#/settings"
|
|
|
|
>
|
|
|
|
<i class="fas fa-cog" aria-hidden="true"></i>
|
|
|
|
</a>
|
|
|
|
</div>`
|
|
|
|
: html``}
|
2021-10-13 09:23:26 +00:00
|
|
|
<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>
|
|
|
|
</div>
|
2021-09-20 10:29:32 +00:00
|
|
|
${until(
|
|
|
|
me().then((u) => {
|
|
|
|
if (!u.user.isSuperuser) return html``;
|
|
|
|
return html`
|
|
|
|
<a
|
2021-10-13 09:23:26 +00:00
|
|
|
class="pf-c-button pf-m-primary pf-m-small pf-u-display-none pf-u-display-block-on-md"
|
2021-09-20 10:29:32 +00:00
|
|
|
href="/if/admin"
|
2021-09-16 20:17:05 +00:00
|
|
|
>
|
2021-09-20 10:29:32 +00:00
|
|
|
${t`Admin interface`}
|
|
|
|
</a>
|
|
|
|
`;
|
|
|
|
}),
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
${until(
|
|
|
|
me().then((u) => {
|
|
|
|
if (u.original) {
|
|
|
|
return 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"
|
2021-11-18 20:33:49 +00:00
|
|
|
href=${`/-/impersonation/end/?back=${encodeURIComponent(
|
|
|
|
`${window.location.pathname}#${window.location.hash}`,
|
|
|
|
)}`}
|
2021-09-20 10:29:32 +00:00
|
|
|
>
|
|
|
|
${t`Stop impersonation`}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
2021-09-16 20:17:05 +00:00
|
|
|
return html``;
|
2021-09-20 10:29:32 +00:00
|
|
|
}),
|
|
|
|
)}
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
|
|
|
<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-md"
|
2021-09-16 20:17:05 +00:00
|
|
|
>
|
2021-09-20 10:29:32 +00:00
|
|
|
${until(
|
|
|
|
me().then((me) => {
|
|
|
|
switch (config.navbar.userDisplay) {
|
2021-10-09 13:52:36 +00:00
|
|
|
case UserDisplay.username:
|
2021-09-20 10:29:32 +00:00
|
|
|
return me.user.username;
|
2021-10-09 13:52:36 +00:00
|
|
|
case UserDisplay.name:
|
2021-09-20 10:29:32 +00:00
|
|
|
return me.user.name;
|
2021-10-09 13:52:36 +00:00
|
|
|
case UserDisplay.email:
|
2021-09-20 10:29:32 +00:00
|
|
|
return me.user.email;
|
|
|
|
default:
|
|
|
|
return me.user.username;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-17 08:04:47 +00:00
|
|
|
${until(
|
2021-09-20 10:29:32 +00:00
|
|
|
me().then((me) => {
|
|
|
|
return html`<img
|
|
|
|
class="pf-c-avatar"
|
|
|
|
src=${me.user.avatar}
|
|
|
|
alt="${t`Avatar image`}"
|
|
|
|
/>`;
|
2021-09-17 08:04:47 +00:00
|
|
|
}),
|
|
|
|
)}
|
2021-09-16 20:17:05 +00:00
|
|
|
</div>
|
2021-09-20 10:29:32 +00:00
|
|
|
</header>
|
|
|
|
<div class="pf-c-page__drawer">
|
|
|
|
<div
|
2021-11-18 20:40:34 +00:00
|
|
|
class="pf-c-drawer ${this.notificationDrawerOpen || this.apiDrawerOpen
|
2021-09-20 10:29:32 +00:00
|
|
|
? "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>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ak-notification-drawer
|
2021-11-18 20:40:34 +00:00
|
|
|
class="pf-c-drawer__panel pf-m-width-33 ${this
|
|
|
|
.notificationDrawerOpen
|
2021-09-20 10:29:32 +00:00
|
|
|
? ""
|
|
|
|
: "display-none"}"
|
2021-11-18 20:40:34 +00:00
|
|
|
?hidden=${!this.notificationDrawerOpen}
|
2021-09-20 10:29:32 +00:00
|
|
|
></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>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-20 10:29:32 +00:00
|
|
|
</div>`;
|
|
|
|
}),
|
|
|
|
)}`;
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|