From 4a577decc23672c87ab8607e45f9ed7430b67241 Mon Sep 17 00:00:00 2001 From: Jens L Date: Mon, 28 Aug 2023 00:52:11 +0200 Subject: [PATCH] web/admin: only show token expiry when token is set to expire (#6643) Signed-off-by: Jens Langhammer --- web/src/admin/tokens/TokenForm.ts | 35 +++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/web/src/admin/tokens/TokenForm.ts b/web/src/admin/tokens/TokenForm.ts index 766667070..88023488c 100644 --- a/web/src/admin/tokens/TokenForm.ts +++ b/web/src/admin/tokens/TokenForm.ts @@ -8,16 +8,21 @@ import "@goauthentik/elements/forms/SearchSelect"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; -import { customElement } from "lit/decorators.js"; +import { customElement, state } from "lit/decorators.js"; import { CoreApi, CoreUsersListRequest, IntentEnum, Token, User } from "@goauthentik/api"; @customElement("ak-token-form") export class TokenForm extends ModelForm { - loadInstance(pk: string): Promise { - return new CoreApi(DEFAULT_CONFIG).coreTokensRetrieve({ + @state() + showExpiry = true; + + async loadInstance(pk: string): Promise { + const token = await new CoreApi(DEFAULT_CONFIG).coreTokensRetrieve({ identifier: pk, }); + this.showExpiry = token.expiring || true; + return token; } getSuccessMessage(): string { @@ -41,6 +46,17 @@ export class TokenForm extends ModelForm { } } + renderExpiry(): TemplateResult { + return html` + + `; + } + renderForm(): TemplateResult { return html`
{ class="pf-c-switch__input" type="checkbox" ?checked=${first(this.instance?.expiring, true)} + @change=${(ev: Event) => { + const el = ev.target as HTMLInputElement; + this.showExpiry = el.checked; + }} /> @@ -131,14 +151,7 @@ export class TokenForm extends ModelForm { )}

- - - + ${this.showExpiry ? this.renderExpiry() : html``}
`; } }