From d48badbca3136f7503f819c911e8ce510b203970 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 5 Apr 2021 20:36:31 +0200 Subject: [PATCH] web/admin: show ldap sync status on overview page Signed-off-by: Jens Langhammer --- web/src/elements/cards/AggregateCard.ts | 3 ++ web/src/locales/en.po | 32 +++++++++---- web/src/locales/pseudo-LOCALE.po | 32 +++++++++---- .../pages/admin-overview/AdminOverviewPage.ts | 4 ++ .../cards/LDAPSyncStatusCard.ts | 48 +++++++++++++++++++ .../cards/LDAPSyncStatusCardContainer.ts | 30 ++++++++++++ 6 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 web/src/pages/admin-overview/cards/LDAPSyncStatusCard.ts create mode 100644 web/src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts diff --git a/web/src/elements/cards/AggregateCard.ts b/web/src/elements/cards/AggregateCard.ts index 11898b415..dbfcdc640 100644 --- a/web/src/elements/cards/AggregateCard.ts +++ b/web/src/elements/cards/AggregateCard.ts @@ -21,6 +21,9 @@ export class AggregateCard extends LitElement { .pf-c-card.pf-c-card-aggregate { height: 100%; } + .pf-c-card__header { + flex-wrap: nowrap; + } .center-value { font-size: var(--pf-global--icon--FontSize--lg); text-align: center; diff --git a/web/src/locales/en.po b/web/src/locales/en.po index 8245b128a..ff627e5f5 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -168,7 +168,7 @@ msgstr "Application's display Name." msgid "Applications" msgstr "Applications" -#: src/pages/admin-overview/AdminOverviewPage.ts:39 +#: src/pages/admin-overview/AdminOverviewPage.ts:40 msgid "Apps with most usage" msgstr "Apps with most usage" @@ -356,11 +356,11 @@ msgstr "Build hash: {0}" msgid "CA which the endpoint's Certificate is verified against. Can be left empty for no validation." msgstr "CA which the endpoint's Certificate is verified against. Can be left empty for no validation." -#: src/pages/admin-overview/AdminOverviewPage.ts:54 +#: src/pages/admin-overview/AdminOverviewPage.ts:55 msgid "Cached Flows" msgstr "Cached Flows" -#: src/pages/admin-overview/AdminOverviewPage.ts:52 +#: src/pages/admin-overview/AdminOverviewPage.ts:53 msgid "Cached Policies" msgstr "Cached Policies" @@ -1539,6 +1539,10 @@ msgstr "Kubeconfig" msgid "LDAP Source {0}" msgstr "LDAP Source {0}" +#: src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts:24 +msgid "LDAP Sync status {0}" +msgstr "LDAP Sync status {0}" + #: src/pages/stages/prompt/PromptForm.ts:90 #: src/pages/stages/prompt/PromptListPage.ts:47 msgid "Label" @@ -1661,7 +1665,7 @@ msgstr "Login to continue to {0}." msgid "Logins" msgstr "Logins" -#: src/pages/admin-overview/AdminOverviewPage.ts:36 +#: src/pages/admin-overview/AdminOverviewPage.ts:37 #: src/pages/applications/ApplicationViewPage.ts:71 msgid "Logins over the last 24 hours" msgstr "Logins over the last 24 hours" @@ -1922,6 +1926,10 @@ msgstr "Not found" msgid "Not synced in the last hour, check System tasks." msgstr "Not synced in the last hour, check System tasks." +#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:28 +msgid "Not synced." +msgstr "Not synced." + #: src/flows/stages/authenticator_static/AuthenticatorStaticStage.ts:58 #: src/flows/stages/authenticator_totp/AuthenticatorTOTPStage.ts:48 #: src/flows/stages/authenticator_validate/AuthenticatorValidateStageCode.ts:45 @@ -2142,7 +2150,7 @@ msgid "Please enter your password" msgstr "Please enter your password" #: src/interfaces/AdminInterface.ts:26 -#: src/pages/admin-overview/AdminOverviewPage.ts:44 +#: src/pages/admin-overview/AdminOverviewPage.ts:45 #: src/pages/flows/FlowListPage.ts:50 #: src/pages/policies/PolicyListPage.ts:38 msgid "Policies" @@ -2292,7 +2300,7 @@ msgid "Provider type" msgstr "Provider type" #: src/interfaces/AdminInterface.ts:20 -#: src/pages/admin-overview/AdminOverviewPage.ts:42 +#: src/pages/admin-overview/AdminOverviewPage.ts:43 #: src/pages/outposts/OutpostForm.ts:82 #: src/pages/outposts/OutpostListPage.ts:50 msgid "Providers" @@ -3073,7 +3081,11 @@ msgstr "Sync users" msgid "Sync users' passwords" msgstr "Sync users' passwords" -#: src/pages/admin-overview/AdminOverviewPage.ts:31 +#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:34 +msgid "Synced {0}:{1}:{2}" +msgstr "Synced {0}:{1}:{2}" + +#: src/pages/admin-overview/AdminOverviewPage.ts:32 msgid "System Overview" msgstr "System Overview" @@ -3513,7 +3525,7 @@ msgid "Username: Same as Text input, but checks for and prevents duplicate usern msgstr "Username: Same as Text input, but checks for and prevents duplicate usernames." #: src/interfaces/AdminInterface.ts:32 -#: src/pages/admin-overview/AdminOverviewPage.ts:46 +#: src/pages/admin-overview/AdminOverviewPage.ts:47 #: src/pages/users/UserListPage.ts:31 msgid "Users" msgstr "Users" @@ -3546,7 +3558,7 @@ msgstr "Validity days" msgid "Verification Certificate" msgstr "Verification Certificate" -#: src/pages/admin-overview/AdminOverviewPage.ts:48 +#: src/pages/admin-overview/AdminOverviewPage.ts:49 msgid "Version" msgstr "Version" @@ -3646,7 +3658,7 @@ msgstr "Whoops!" msgid "Windows" msgstr "Windows" -#: src/pages/admin-overview/AdminOverviewPage.ts:50 +#: src/pages/admin-overview/AdminOverviewPage.ts:51 msgid "Workers" msgstr "Workers" diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index 539a8bf84..162300bd4 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -168,7 +168,7 @@ msgstr "" msgid "Applications" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:39 +#: src/pages/admin-overview/AdminOverviewPage.ts:40 msgid "Apps with most usage" msgstr "" @@ -352,11 +352,11 @@ msgstr "" msgid "CA which the endpoint's Certificate is verified against. Can be left empty for no validation." msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:54 +#: src/pages/admin-overview/AdminOverviewPage.ts:55 msgid "Cached Flows" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:52 +#: src/pages/admin-overview/AdminOverviewPage.ts:53 msgid "Cached Policies" msgstr "" @@ -1535,6 +1535,10 @@ msgstr "" msgid "LDAP Source {0}" msgstr "" +#: src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts:24 +msgid "LDAP Sync status {0}" +msgstr "" + #: src/pages/stages/prompt/PromptForm.ts:90 #: src/pages/stages/prompt/PromptListPage.ts:47 msgid "Label" @@ -1657,7 +1661,7 @@ msgstr "" msgid "Logins" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:36 +#: src/pages/admin-overview/AdminOverviewPage.ts:37 #: src/pages/applications/ApplicationViewPage.ts:71 msgid "Logins over the last 24 hours" msgstr "" @@ -1918,6 +1922,10 @@ msgstr "" msgid "Not synced in the last hour, check System tasks." msgstr "" +#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:28 +msgid "Not synced." +msgstr "" + #: src/flows/stages/authenticator_static/AuthenticatorStaticStage.ts:58 #: src/flows/stages/authenticator_totp/AuthenticatorTOTPStage.ts:48 #: src/flows/stages/authenticator_validate/AuthenticatorValidateStageCode.ts:45 @@ -2138,7 +2146,7 @@ msgid "Please enter your password" msgstr "" #: src/interfaces/AdminInterface.ts:26 -#: src/pages/admin-overview/AdminOverviewPage.ts:44 +#: src/pages/admin-overview/AdminOverviewPage.ts:45 #: src/pages/flows/FlowListPage.ts:50 #: src/pages/policies/PolicyListPage.ts:38 msgid "Policies" @@ -2288,7 +2296,7 @@ msgid "Provider type" msgstr "" #: src/interfaces/AdminInterface.ts:20 -#: src/pages/admin-overview/AdminOverviewPage.ts:42 +#: src/pages/admin-overview/AdminOverviewPage.ts:43 #: src/pages/outposts/OutpostForm.ts:82 #: src/pages/outposts/OutpostListPage.ts:50 msgid "Providers" @@ -3069,7 +3077,11 @@ msgstr "" msgid "Sync users' passwords" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:31 +#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:34 +msgid "Synced {0}:{1}:{2}" +msgstr "" + +#: src/pages/admin-overview/AdminOverviewPage.ts:32 msgid "System Overview" msgstr "" @@ -3507,7 +3519,7 @@ msgid "Username: Same as Text input, but checks for and prevents duplicate usern msgstr "" #: src/interfaces/AdminInterface.ts:32 -#: src/pages/admin-overview/AdminOverviewPage.ts:46 +#: src/pages/admin-overview/AdminOverviewPage.ts:47 #: src/pages/users/UserListPage.ts:31 msgid "Users" msgstr "" @@ -3540,7 +3552,7 @@ msgstr "" msgid "Verification Certificate" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:48 +#: src/pages/admin-overview/AdminOverviewPage.ts:49 msgid "Version" msgstr "" @@ -3640,7 +3652,7 @@ msgstr "" msgid "Windows" msgstr "" -#: src/pages/admin-overview/AdminOverviewPage.ts:50 +#: src/pages/admin-overview/AdminOverviewPage.ts:51 msgid "Workers" msgstr "" diff --git a/web/src/pages/admin-overview/AdminOverviewPage.ts b/web/src/pages/admin-overview/AdminOverviewPage.ts index 9bb87791b..a35249526 100644 --- a/web/src/pages/admin-overview/AdminOverviewPage.ts +++ b/web/src/pages/admin-overview/AdminOverviewPage.ts @@ -4,8 +4,10 @@ import { CSSResult, customElement, html, LitElement, TemplateResult } from "lit- import "../../elements/charts/AdminLoginsChart"; import "../../elements/cards/AggregatePromiseCard"; import "./TopApplicationsTable"; + import "./cards/AdminStatusCard"; import "./cards/FlowCacheStatusCard"; +import "./cards/LDAPSyncStatusCardContainer"; import "./cards/PolicyCacheStatusCard"; import "./cards/PolicyUnboundStatusCard"; import "./cards/ProviderStatusCard"; @@ -53,6 +55,8 @@ export class AdminOverviewPage extends LitElement { + + `; } diff --git a/web/src/pages/admin-overview/cards/LDAPSyncStatusCard.ts b/web/src/pages/admin-overview/cards/LDAPSyncStatusCard.ts new file mode 100644 index 000000000..690eb2d64 --- /dev/null +++ b/web/src/pages/admin-overview/cards/LDAPSyncStatusCard.ts @@ -0,0 +1,48 @@ +import { t } from "@lingui/macro"; +import { customElement, html, property, TemplateResult } from "lit-element"; +import { AdminStatus, AdminStatusCard } from "./AdminStatusCard"; +import { SourcesApi } from "authentik-api"; +import { DEFAULT_CONFIG } from "../../../api/Config"; +import "../../../elements/forms/ConfirmationForm"; + +@customElement("ak-admin-status-card-ldap-sync") +export class LDAPSyncStatusCard extends AdminStatusCard { + + @property() + slug!: string; + + getPrimaryValue(): Promise { + return new SourcesApi(DEFAULT_CONFIG).sourcesLdapSyncStatus({ + slug: this.slug + }).then((value) => { + return value.lastSync; + }); + } + + renderValue(): TemplateResult { + return html`${t`Last sync: ${this.value?.toLocaleTimeString()}`}`; + } + + getStatus(value: Date | undefined): Promise { + const now = new Date().getTime(); + const maxDelta = 3600000; // 1 hour + if (!value || (now - value.getTime()) > maxDelta) { + // No sync or last sync was over maxDelta ago + return Promise.resolve({ + icon: "fa fa-exclamation-triangle pf-m-warning", + message: t`Not synced.`, + }); + } else { + return Promise.resolve({ + icon: "fa fa-check-circle pf-m-success", + }); + } + } + + renderHeaderLink(): TemplateResult { + return html` + + `; + } + +} diff --git a/web/src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts b/web/src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts new file mode 100644 index 000000000..00adf63dc --- /dev/null +++ b/web/src/pages/admin-overview/cards/LDAPSyncStatusCardContainer.ts @@ -0,0 +1,30 @@ +import { SourcesApi } from "authentik-api"; +import { customElement, html, LitElement, TemplateResult } from "lit-element"; +import { until } from "lit-html/directives/until"; +import "./LDAPSyncStatusCard"; +import { t } from "@lingui/macro"; +import { DEFAULT_CONFIG } from "../../../api/Config"; + +@customElement("ak-admin-status-card-ldap-sync-container") +export class LDAPSyncStatusCardContainer extends LitElement { + + createRenderRoot(): Element | ShadowRoot { + return this; + } + + render(): TemplateResult { + return html` + ${until(new SourcesApi(DEFAULT_CONFIG).sourcesLdapList({}).then(sources => { + return sources.results.map(source => { + return html` + `; + }); + }))} + `; + } + +}