diff --git a/web/src/pages/groups/GroupForm.ts b/web/src/pages/groups/GroupForm.ts index f4d5edc4e..d20b77a3a 100644 --- a/web/src/pages/groups/GroupForm.ts +++ b/web/src/pages/groups/GroupForm.ts @@ -13,15 +13,19 @@ import "../../elements/chips/Chip"; import "./MemberSelectModal"; import YAML from "yaml"; import { first } from "../../utils"; +import { ModelForm } from "../../elements/forms/ModelForm"; @customElement("ak-group-form") -export class GroupForm extends Form { +export class GroupForm extends ModelForm { - @property({attribute: false}) - group?: Group; + loadInstance(pk: string): Promise { + return new CoreApi(DEFAULT_CONFIG).coreGroupsRead({ + groupUuid: pk + }); + } getSuccessMessage(): string { - if (this.group) { + if (this.instance) { return t`Successfully updated group.`; } else { return t`Successfully created group.`; @@ -29,13 +33,13 @@ export class GroupForm extends Form { } send = (data: Group): Promise => { - if (this.group?.pk) { + if (this.instance?.pk) { return new CoreApi(DEFAULT_CONFIG).coreGroupsUpdate({ - groupUuid: this.group.pk || "", + groupUuid: this.instance.pk || "", data: data }); } else { - data.users = Array.from(this.group?.users || []) as unknown as Set; + data.users = Array.from(this.instance?.users || []) as unknown as Set; return new CoreApi(DEFAULT_CONFIG).coreGroupsCreate({ data: data }); @@ -48,11 +52,11 @@ export class GroupForm extends Form { label=${t`Name`} ?required=${true} name="name"> - +
- + @@ -63,10 +67,10 @@ export class GroupForm extends Form { label=${t`Parent`} name="parent"> @@ -79,8 +83,8 @@ export class GroupForm extends Form { .confirm=${(items: User[]) => { // Because the model only has the IDs, map the user list to IDs const ids = items.map(u => u.pk || 0); - if (!this.group) this.group = {} as Group; - this.group.users = new Set(Array.from(this.group?.users || []).concat(ids)); + if (!this.instance) this.instance = {} as Group; + this.instance.users = new Set(Array.from(this.instance?.users || []).concat(ids)); this.requestUpdate(); return Promise.resolve(); }}> @@ -94,7 +98,7 @@ export class GroupForm extends Form { ordering: "username", }).then(users => { return users.results.map(user => { - const selected = Array.from(this.group?.users || []).some(su => { + const selected = Array.from(this.instance?.users || []).some(su => { return su == user.pk; }); if (!selected) return; @@ -102,11 +106,11 @@ export class GroupForm extends Form { .removable=${true} value=${ifDefined(user.pk)} @remove=${() => { - if (!this.group) return; - const users = Array.from(this.group?.users || []); + if (!this.instance) return; + const users = Array.from(this.instance?.users || []); const idx = users.indexOf(user.pk || 0); users.splice(idx, 1); - this.group.users = new Set(users); + this.instance.users = new Set(users); this.requestUpdate(); }}> ${user.username} @@ -122,7 +126,7 @@ export class GroupForm extends Form { label=${t`Attributes`} ?required=${true} name="attributes"> - +

${t`Set custom attributes using YAML or JSON.`}

diff --git a/web/src/pages/groups/GroupListPage.ts b/web/src/pages/groups/GroupListPage.ts index 2caa7e7d0..9c2d71bec 100644 --- a/web/src/pages/groups/GroupListPage.ts +++ b/web/src/pages/groups/GroupListPage.ts @@ -63,7 +63,7 @@ export class GroupListPage extends TablePage { ${t`Update Group`} - +
- +
- + @@ -213,7 +210,7 @@ export class PolicyBindingForm extends Form { label=${t`Timeout`} ?required=${true} name="timeout"> - + `; } diff --git a/web/src/pages/policies/PolicyListPage.ts b/web/src/pages/policies/PolicyListPage.ts index 69dc15ac0..3acf2f101 100644 --- a/web/src/pages/policies/PolicyListPage.ts +++ b/web/src/pages/policies/PolicyListPage.ts @@ -82,7 +82,7 @@ export class PolicyListPage extends TablePage { diff --git a/web/src/pages/policies/dummy/DummyPolicyForm.ts b/web/src/pages/policies/dummy/DummyPolicyForm.ts index 9caa2f07f..cef3bf67e 100644 --- a/web/src/pages/policies/dummy/DummyPolicyForm.ts +++ b/web/src/pages/policies/dummy/DummyPolicyForm.ts @@ -1,30 +1,25 @@ import { DummyPolicy, PoliciesApi } from "authentik-api"; import { t } from "@lingui/macro"; -import { customElement, property } from "lit-element"; +import { customElement } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../../api/Config"; -import { Form } from "../../../elements/forms/Form"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../../elements/forms/HorizontalFormElement"; import "../../../elements/forms/FormGroup"; import { first } from "../../../utils"; +import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-policy-dummy-form") -export class DummyPolicyForm extends Form { +export class DummyPolicyForm extends ModelForm { - set policyUUID(value: string) { - new PoliciesApi(DEFAULT_CONFIG).policiesDummyRead({ - policyUuid: value, - }).then(policy => { - this.policy = policy; + loadInstance(pk: string): Promise { + return new PoliciesApi(DEFAULT_CONFIG).policiesDummyRead({ + policyUuid: pk, }); } - @property({attribute: false}) - policy?: DummyPolicy; - getSuccessMessage(): string { - if (this.policy) { + if (this.instance) { return t`Successfully updated policy.`; } else { return t`Successfully created policy.`; @@ -32,9 +27,9 @@ export class DummyPolicyForm extends Form { } send = (data: DummyPolicy): Promise => { - if (this.policy) { + if (this.instance) { return new PoliciesApi(DEFAULT_CONFIG).policiesDummyUpdate({ - policyUuid: this.policy.pk || "", + policyUuid: this.instance.pk || "", data: data }); } else { @@ -53,11 +48,11 @@ export class DummyPolicyForm extends Form { label=${t`Name`} ?required=${true} name="name"> - +
- + @@ -73,7 +68,7 @@ export class DummyPolicyForm extends Form {
- + @@ -83,14 +78,14 @@ export class DummyPolicyForm extends Form { label=${t`Wait (min)`} ?required=${true} name="waitMin"> - +

${t`The policy takes a random time to execute. This controls the minimum time it will take.`}

- +