From d4493c0ee9b243b42d752996dbd5479fb6c64cdd Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 9 May 2021 12:59:00 +0200 Subject: [PATCH 01/10] web/admin: add new base form to handle refresh events Signed-off-by: Jens Langhammer --- web/src/elements/forms/Form.ts | 7 +++++++ web/src/elements/forms/ModelForm.ts | 32 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 web/src/elements/forms/ModelForm.ts diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 57297f1f5..786c4cf03 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -15,6 +15,7 @@ import { MessageLevel } from "../messages/Message"; import { IronFormElement } from "@polymer/iron-form/iron-form"; import { camelToSnake, convertToSlug } from "../../utils"; import { ValidationError } from "authentik-api/src"; +import { EVENT_REFRESH } from "../../constants"; export class APIError extends Error { @@ -140,6 +141,12 @@ export class Form extends LitElement { level: MessageLevel.success, message: this.getSuccessMessage() }); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); return r; }).catch((ex: Response) => { if (ex.status > 399 && ex.status < 500) { diff --git a/web/src/elements/forms/ModelForm.ts b/web/src/elements/forms/ModelForm.ts new file mode 100644 index 000000000..612fcab48 --- /dev/null +++ b/web/src/elements/forms/ModelForm.ts @@ -0,0 +1,32 @@ +import { property } from "lit-element"; +import { EVENT_REFRESH } from "../../constants"; +import { Form } from "./Form"; + +export abstract class ModelForm extends Form { + + abstract loadInstance(pk: PKT): Promise; + + @property() + set instancePk(value: PKT) { + this._instancePk = value; + this.loadInstance(value).then(instance => { + this.instance = instance; + }); + } + + private _instancePk?: PKT; + + @property({ attribute: false }) + instance?: T; + + constructor() { + super(); + this.addEventListener(EVENT_REFRESH, () => { + if (!this._instancePk) return; + this.loadInstance(this._instancePk).then(instance => { + this.instance = instance; + }); + }); + } + +} From b4d750174f6d384f873055bdfe7b30af72ff7157 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 11 May 2021 11:48:34 +0200 Subject: [PATCH 02/10] web/admin: add modelform as base, start migrating Signed-off-by: Jens Langhammer --- web/src/elements/forms/ModelForm.ts | 4 +- web/src/pages/applications/ApplicationForm.ts | 36 ++++---- .../pages/applications/ApplicationListPage.ts | 2 +- web/src/pages/outposts/OutpostForm.ts | 35 ++++---- web/src/pages/outposts/OutpostListPage.ts | 2 +- .../PropertyMappingLDAPForm.ts | 27 +++--- .../PropertyMappingSAMLForm.ts | 30 +++---- .../PropertyMappingScopeForm.ts | 29 +++---- web/src/pages/providers/ProviderListPage.ts | 2 +- .../pages/providers/ldap/LDAPProviderForm.ts | 31 +++---- .../providers/ldap/LDAPProviderViewPage.ts | 2 +- .../providers/oauth2/OAuth2ProviderForm.ts | 65 +++++++------- .../oauth2/OAuth2ProviderViewPage.ts | 2 +- .../providers/proxy/ProxyProviderForm.ts | 43 +++++----- .../providers/proxy/ProxyProviderViewPage.ts | 2 +- .../pages/providers/saml/SAMLProviderForm.ts | 76 ++++++++-------- .../providers/saml/SAMLProviderViewPage.ts | 2 +- web/src/pages/sources/SourcesListPage.ts | 2 +- web/src/pages/sources/ldap/LDAPSourceForm.ts | 67 +++++++-------- .../pages/sources/ldap/LDAPSourceViewPage.ts | 2 +- .../pages/sources/oauth/OAuthSourceForm.ts | 71 ++++++++------- .../sources/oauth/OAuthSourceViewPage.ts | 2 +- web/src/pages/sources/plex/PlexSourceForm.ts | 56 ++++++------ .../pages/sources/plex/PlexSourceViewPage.ts | 2 +- web/src/pages/sources/saml/SAMLSourceForm.ts | 86 +++++++++---------- .../pages/sources/saml/SAMLSourceViewPage.ts | 2 +- 26 files changed, 320 insertions(+), 360 deletions(-) diff --git a/web/src/elements/forms/ModelForm.ts b/web/src/elements/forms/ModelForm.ts index 612fcab48..e5fd7fdef 100644 --- a/web/src/elements/forms/ModelForm.ts +++ b/web/src/elements/forms/ModelForm.ts @@ -2,11 +2,11 @@ import { property } from "lit-element"; import { EVENT_REFRESH } from "../../constants"; import { Form } from "./Form"; -export abstract class ModelForm extends Form { +export abstract class ModelForm extends Form { abstract loadInstance(pk: PKT): Promise; - @property() + @property({attribute: false}) set instancePk(value: PKT) { this._instancePk = value; this.loadInstance(value).then(instance => { diff --git a/web/src/pages/applications/ApplicationForm.ts b/web/src/pages/applications/ApplicationForm.ts index a169e0d94..74e117041 100644 --- a/web/src/pages/applications/ApplicationForm.ts +++ b/web/src/pages/applications/ApplicationForm.ts @@ -13,18 +13,22 @@ import "../../elements/forms/ModalForm"; import "../../elements/forms/HorizontalFormElement"; import "../../elements/forms/FormGroup"; import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css"; +import { ModelForm } from "../../elements/forms/ModelForm"; @customElement("ak-application-form") -export class ApplicationForm extends Form { +export class ApplicationForm extends ModelForm { - @property({ attribute: false }) - application?: Application; + loadInstance(pk: string): Promise { + return new CoreApi(DEFAULT_CONFIG).coreApplicationsRead({ + slug: pk + }); + } @property({ attribute: false }) provider?: number; getSuccessMessage(): string { - if (this.application) { + if (this.instance) { return t`Successfully updated application.`; } else { return t`Successfully created application.`; @@ -37,9 +41,9 @@ export class ApplicationForm extends Form { send = (data: Application): Promise => { let writeOp: Promise; - if (this.application) { + if (this.instance) { writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ - slug: this.application.slug, + slug: this.instance.slug, data: data }); } else { @@ -72,7 +76,7 @@ export class ApplicationForm extends Form { ${Array.from(m).map(([group, providers]) => { return html` ${providers.map(p => { - const selected = (this.application?.provider === p.pk) || (this.provider === p.pk); + const selected = (this.instance?.provider === p.pk) || (this.provider === p.pk); return html``; })} `; @@ -86,21 +90,21 @@ export class ApplicationForm extends Form { label=${t`Name`} ?required=${true} name="name"> - +

${t`Application's display Name.`}

- +

${t`Internal application name, used in URLs.`}

- - @@ -158,23 +162,23 @@ export class ApplicationForm extends Form { - +

${t`If left empty, authentik will try to extract the launch URL based on the selected provider.`}

- + - + - + diff --git a/web/src/pages/applications/ApplicationListPage.ts b/web/src/pages/applications/ApplicationListPage.ts index 66177438d..3bdebecc8 100644 --- a/web/src/pages/applications/ApplicationListPage.ts +++ b/web/src/pages/applications/ApplicationListPage.ts @@ -89,7 +89,7 @@ export class ApplicationListPage extends TablePage { ${t`Update Application`} - +