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 { 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";
|
2023-07-07 14:23:10 +00:00
|
|
|
import "@goauthentik/elements/ak-locale-context";
|
2023-07-17 15:57:08 +00:00
|
|
|
import "@goauthentik/elements/buttons/ActionButton";
|
|
|
|
import "@goauthentik/elements/enterprise/EnterpriseStatusBanner";
|
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
|
|
|
|
web: Replace lingui.js with lit-localize (#5761)
* \#\# Details
web: replace lingui with lit/localize
\#\# Changes
This rather massive shift replaces the lingui and `t()` syntax with lit-localize, XLIFF, and the `msg()`
syntax used by lit-localize. 90% of this work was mechanized; simple perl scripts found and replaced
all uses of `t()` with the appropriate corresponding syntax for `msg()` and `msg(str())`.
The XLIFF files were auto-generated from the PO files. They have not been audited, and they should be
checked over by professional translators. The actual _strings_ have not been changed, but as this was
a mechanized change there is always the possibility of mis-translation-- not by the translator, but by
the script.
* web: revise lit/localize: fix two installation issues.
* web: revise localization
TL;DR:
- Replaced all of Lingui's `t()` syntax with `msg()` syntax.
- Mechanically (i.e with a script) converted all of the PO files to XLIFF files
- Refactored the localization code to be a bit smarter:
- the function `getBestMatchLocale` takes the locale lists and a requested locale, and returns the
first match of:
- The locale's code exactly matches the requested locale
- The locale code exactly matches the prefix of the requested locale (i.e the "en" part of "en-US")
- the locale code's prefix exactly matches the prefix of the requested locale
This function is passed to lit-locate's `loadLocale()`.
- `activateLocale()` just calls `loadLocale()` now.
- `autodetectLanguage` searches the following, and picks the first that returns a valid locale
object, before passing it to `loadLocale()`:
- The User's settings
- A `?locale=` component found in `window.location.search`
- The `window.navigator.language` field
- English
The `msg()` only runs when it's run. This seems obvious, but it means that you cannot cache
strings at load time; they must be kept inside functions that are re-run so that the `msg()` engine
can look up the strings in the preferred language of the user at that moment.
You can use thunks-of-strings if you really need them that way.
* Including the 'xliff-converter' in case anyone wants to review it.
* The xliff-converter is tagged as 'xliff-converter', but has been
deleted.
\#\# Details
- Resolves #5171
\#\# Changes
\#\#\# New Features
- Adds a "Add an Application" to the LibraryView if there are no applications and the user is an administrator.
\#\#\# Breaking Changes
- Adds breaking change which causes \<issue\>.
\#\# Checklist
- [ ] Local tests pass (`ak test authentik/`)
- [ ] The code has been formatted (`make lint-fix`)
If an API change has been made
- [ ] The API schema has been updated (`make gen-build`)
If changes to the frontend have been made
- [ ] The code has been formatted (`make web`)
- [ ] The translation files have been updated (`make i18n-extract`)
If applicable
- [ ] The documentation has been updated
- [ ] The documentation has been formatted (`make website`)
* web: fix redundant locales for zh suite.
* web: prettier pass for locale update
* web: localization moderization
Changed the names of the lit-localize commands to make it clear they're
part of the localization effort, and not just "build" and "extract".
* update transifex config
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
* fix package lock?
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
* use build not compile
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
* web: conversion to lit-localize
The CI produced a list of problems that I hadn't caught earlier,
due to a typo ("localize build" is correct, "localize compile" is
not) I had left in package.json. They were minor and linty, but
it was still wise to fix them.
* web: replace lingui with lit/locale
This commit fixes some minor linting issues that were hidden by a typo in package.json. The
issues were not apparently problematic from a Javascript point of view, but they pointed
to sloppy thinking in the progression of types through the system, so I cleaned them
up and formalized the types from LocaleModule to AkLocale.
* web: replace lingui with lit/localize
One problem that has repeatedly come up is that localize's templates do not produce
JavaScript that conforms with our shop style. I've replaced `build-locale` with
a two-step that builds the locale *and* ensures that it conforms to the shop style
via `prettier` every time.
* web: replace lingui with lit-locale
This commit applies the most recent bundle of translations to the
new lit-locale aspect component. It also revises the algorithm
for *finding* the correct locale, replacing the complex fall-back
with some rather straightforward regular expressions.
In the case of Chinese, the fallback comes at the end of the
selection list, which may not be, er, politically valuable
(since Taiwan and Hong Kong come before, being exceptions that
need to be tested). If we need a different order for presentation,
that'll be a future feature.
* web: replace lingui with lit/locale
Well, that was embarassing.
---------
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
2023-06-02 15:08:36 +00:00
|
|
|
import { msg } from "@lit/localize";
|
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-07-17 15:57:08 +00:00
|
|
|
import { CoreApi, EventsApi, SessionUser } from "@goauthentik/api";
|
2022-09-14 22:05:21 +00:00
|
|
|
|
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 {
|
2023-07-07 10:23:22 +00:00
|
|
|
min-height: 32px;
|
|
|
|
height: 32px;
|
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;
|
|
|
|
}
|
2023-07-07 14:23:10 +00:00
|
|
|
return html` <ak-locale-context>
|
2023-07-17 15:57:08 +00:00
|
|
|
<ak-enterprise-status interface="user"></ak-enterprise-status>
|
2023-07-07 14:23:10 +00:00
|
|
|
<div class="pf-c-page">
|
|
|
|
<div class="background-wrapper" style="${this.uiConfig.theme.background}"></div>
|
|
|
|
<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">
|
|
|
|
${this.uiConfig.enabledFeatures.apiDrawer
|
|
|
|
? html`<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-lg"
|
2023-02-04 17:30:22 +00:00
|
|
|
>
|
2023-07-07 14:23:10 +00:00
|
|
|
<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``}
|
|
|
|
${this.uiConfig.enabledFeatures.notificationDrawer
|
|
|
|
? html`<div
|
|
|
|
class="pf-c-page__header-tools-item pf-m-hidden pf-m-visible-on-lg"
|
2023-02-04 17:30:22 +00:00
|
|
|
>
|
2023-07-07 14:23:10 +00:00
|
|
|
<button
|
|
|
|
class="pf-c-button pf-m-plain"
|
|
|
|
type="button"
|
|
|
|
aria-label="${msg("Unread notifications")}"
|
|
|
|
@click=${() => {
|
|
|
|
this.notificationDrawerOpen =
|
|
|
|
!this.notificationDrawerOpen;
|
|
|
|
updateURLParams({
|
|
|
|
notificationDrawerOpen:
|
|
|
|
this.notificationDrawerOpen,
|
|
|
|
});
|
|
|
|
}}
|
2021-09-20 10:29:32 +00:00
|
|
|
>
|
2023-07-07 14:23:10 +00:00
|
|
|
<span
|
|
|
|
class="pf-c-notification-badge ${this
|
|
|
|
.notificationsCount > 0
|
|
|
|
? "pf-m-unread"
|
|
|
|
: ""}"
|
2021-09-20 10:29:32 +00:00
|
|
|
>
|
2023-07-07 14:23:10 +00:00
|
|
|
<i class="pf-icon-bell" aria-hidden="true"></i>
|
|
|
|
<span class="pf-c-notification-badge__count"
|
|
|
|
>${this.notificationsCount}</span
|
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</div> `
|
|
|
|
: html``}
|
|
|
|
${this.uiConfig.enabledFeatures.settings
|
|
|
|
? 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>
|
|
|
|
</div>
|
|
|
|
${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"
|
|
|
|
>
|
|
|
|
${msg("Admin interface")}
|
|
|
|
</a>`
|
|
|
|
: html``}
|
2021-09-16 20:17:05 +00:00
|
|
|
</div>
|
2023-07-07 14:23:10 +00:00
|
|
|
${this.me.original
|
2023-07-17 15:57:08 +00:00
|
|
|
? html`
|
|
|
|
<div class="pf-c-page__header-tools">
|
|
|
|
<div class="pf-c-page__header-tools-group">
|
|
|
|
<ak-action-button
|
|
|
|
class="pf-m-warning pf-m-small"
|
|
|
|
.apiRequest=${() => {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG)
|
|
|
|
.coreUsersImpersonateEndRetrieve()
|
|
|
|
.then(() => {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
${msg("Stop impersonation")}
|
|
|
|
</ak-action-button>
|
|
|
|
</div>
|
|
|
|
</div>`
|
2023-07-07 14:23:10 +00:00
|
|
|
: 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>
|
2023-02-04 17:30:22 +00:00
|
|
|
</div>
|
2023-07-07 14:23:10 +00:00
|
|
|
<img
|
|
|
|
class="pf-c-avatar"
|
|
|
|
src=${this.me.user.avatar}
|
|
|
|
alt="${msg("Avatar image")}"
|
|
|
|
/>
|
2023-02-04 17:30:22 +00:00
|
|
|
</div>
|
2023-07-07 14:23:10 +00:00
|
|
|
</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>
|
|
|
|
</div>
|
2021-09-16 15:30:16 +00:00
|
|
|
</div>
|
2023-07-07 14:23:10 +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>
|
|
|
|
</div>
|
2023-02-04 17:30:22 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-07 14:23:10 +00:00
|
|
|
</ak-locale-context>`;
|
2021-09-16 15:30:16 +00:00
|
|
|
}
|
|
|
|
}
|