diff --git a/web/src/pages/flows/BoundStagesList.ts b/web/src/pages/flows/BoundStagesList.ts index f1a1d9615..cc602929a 100644 --- a/web/src/pages/flows/BoundStagesList.ts +++ b/web/src/pages/flows/BoundStagesList.ts @@ -58,7 +58,7 @@ export class BoundStagesList extends Table { diff --git a/web/src/pages/stages/StageListPage.ts b/web/src/pages/stages/StageListPage.ts index 4b82fcb4e..17f62e267 100644 --- a/web/src/pages/stages/StageListPage.ts +++ b/web/src/pages/stages/StageListPage.ts @@ -90,7 +90,7 @@ export class StageListPage extends TablePage { diff --git a/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts b/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts index b160d5056..243583d59 100644 --- a/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts +++ b/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts @@ -1,31 +1,26 @@ import { FlowDesignationEnum, FlowsApi, AuthenticatorStaticStage, StagesApi } 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 { until } from "lit-html/directives/until"; import { first } from "../../../utils"; +import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-authenticator-static-form") -export class AuthenticatorStaticStageForm extends Form { +export class AuthenticatorStaticStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: AuthenticatorStaticStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -33,9 +28,9 @@ export class AuthenticatorStaticStageForm extends Form } send = (data: AuthenticatorStaticStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -54,7 +49,7 @@ export class AuthenticatorStaticStageForm extends Form label=${t`Name`} ?required=${true} name="name"> - + @@ -65,20 +60,20 @@ export class AuthenticatorStaticStageForm extends Form label=${t`Token count`} ?required=${true} name="tokenCount"> - + + @@ -65,10 +60,10 @@ export class AuthenticatorTOTPStageForm extends Form { ?required=${true} name="digits"> @@ -77,14 +72,14 @@ export class AuthenticatorTOTPStageForm extends Form { label=${t`Configuration flow`} name="configureFlow"> + @@ -82,13 +79,13 @@ export class AuthenticatorValidateStageForm extends Form - - - @@ -117,12 +114,12 @@ export class AuthenticatorValidateStageForm extends Form + `; } diff --git a/web/src/pages/stages/captcha/CaptchaStageForm.ts b/web/src/pages/stages/captcha/CaptchaStageForm.ts index 970fd1f70..8d84252c2 100644 --- a/web/src/pages/stages/captcha/CaptchaStageForm.ts +++ b/web/src/pages/stages/captcha/CaptchaStageForm.ts @@ -1,29 +1,24 @@ import { CaptchaStage, StagesApi } 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 { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-captcha-form") -export class CaptchaStageForm extends Form { +export class CaptchaStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesCaptchaRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesCaptchaRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: CaptchaStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -31,9 +26,9 @@ export class CaptchaStageForm extends Form { } send = (data: CaptchaStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesCaptchaPartialUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -52,7 +47,7 @@ export class CaptchaStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + @@ -63,15 +58,15 @@ export class CaptchaStageForm extends Form { label=${t`Public Key`} ?required=${true} name="publicKey"> - +

${t`Public key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}

- +

${t`Private key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}

diff --git a/web/src/pages/stages/consent/ConsentStageForm.ts b/web/src/pages/stages/consent/ConsentStageForm.ts index c33810525..c1776f77b 100644 --- a/web/src/pages/stages/consent/ConsentStageForm.ts +++ b/web/src/pages/stages/consent/ConsentStageForm.ts @@ -3,31 +3,28 @@ import { t } from "@lingui/macro"; import { customElement, property } 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 { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-consent-form") -export class ConsentStageForm extends Form { +export class ConsentStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesConsentRead({ - stageUuid: value, + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesConsentRead({ + stageUuid: pk, }).then(stage => { - this.stage = stage; this.showExpiresIn = stage.name === ConsentStageModeEnum.Expiring; + return stage; }); } - @property({attribute: false}) - stage?: ConsentStage; - @property({type: Boolean}) showExpiresIn = false; getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -35,9 +32,9 @@ export class ConsentStageForm extends Form { } send = (data: ConsentStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesConsentUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -56,7 +53,7 @@ export class ConsentStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + @@ -75,13 +72,13 @@ export class ConsentStageForm extends Form { this.showExpiresIn = false; } }}> - - - @@ -91,7 +88,7 @@ export class ConsentStageForm extends Form { label=${t`Consent expires in`} ?required=${true} name="consentExpireIn"> - +

${t`Offset after which consent expires. (Format: hours=1;minutes=2;seconds=3).`}

diff --git a/web/src/pages/stages/deny/DenyStageForm.ts b/web/src/pages/stages/deny/DenyStageForm.ts index 0f585a576..9b261a25c 100644 --- a/web/src/pages/stages/deny/DenyStageForm.ts +++ b/web/src/pages/stages/deny/DenyStageForm.ts @@ -1,28 +1,23 @@ import { DenyStage, StagesApi } 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 { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-deny-form") -export class DenyStageForm extends Form { +export class DenyStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesDenyRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesDenyRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: DenyStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -30,9 +25,9 @@ export class DenyStageForm extends Form { } send = (data: DenyStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesDenyUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -51,7 +46,7 @@ export class DenyStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + `; } diff --git a/web/src/pages/stages/dummy/DummyStageForm.ts b/web/src/pages/stages/dummy/DummyStageForm.ts index bd0f6f22c..b753efec5 100644 --- a/web/src/pages/stages/dummy/DummyStageForm.ts +++ b/web/src/pages/stages/dummy/DummyStageForm.ts @@ -1,28 +1,23 @@ import { DummyStage, StagesApi } 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 { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-dummy-form") -export class DummyStageForm extends Form { +export class DummyStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesDummyRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesDummyRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: DummyStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -30,9 +25,9 @@ export class DummyStageForm extends Form { } send = (data: DummyStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesDummyUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -51,7 +46,7 @@ export class DummyStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + `; } diff --git a/web/src/pages/stages/email/EmailStageForm.ts b/web/src/pages/stages/email/EmailStageForm.ts index 176e533c3..d7d82a424 100644 --- a/web/src/pages/stages/email/EmailStageForm.ts +++ b/web/src/pages/stages/email/EmailStageForm.ts @@ -3,32 +3,30 @@ import { t } from "@lingui/macro"; import { customElement, property } 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 { until } from "lit-html/directives/until"; +import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-email-form") -export class EmailStageForm extends Form { +export class EmailStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesEmailRead({ - stageUuid: value, + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesEmailRead({ + stageUuid: pk, }).then(stage => { - this.stage = stage; + this.showConnectionSettings = !stage.useGlobalSettings; + return stage; }); } - @property({attribute: false}) - stage?: EmailStage; - @property({type: Boolean}) showConnectionSettings = false; getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -36,9 +34,9 @@ export class EmailStageForm extends Form { } send = (data: EmailStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesEmailPartialUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -61,28 +59,28 @@ export class EmailStageForm extends Form { label=${t`SMTP Host`} ?required=${true} name="host"> - + - + - + - +
- + @@ -90,7 +88,7 @@ export class EmailStageForm extends Form {
- + @@ -100,13 +98,13 @@ export class EmailStageForm extends Form { label=${t`Timeout`} ?required=${true} name="timeout"> - + - +
`; @@ -121,7 +119,7 @@ export class EmailStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - +
@@ -130,7 +128,7 @@ export class EmailStageForm extends Form {
- { + { const target = ev.target as HTMLInputElement; this.showConnectionSettings = !target.checked; }}> @@ -144,14 +142,14 @@ export class EmailStageForm extends Form { label=${t`Token expiry`} ?required=${true} name="tokenExpiry"> - +

${t`Time in minutes the token sent is valid.`}

- + { + @@ -83,7 +78,7 @@ export class IdentificationStageForm extends Form {
- + @@ -92,7 +87,7 @@ export class IdentificationStageForm extends Form {
- + @@ -103,13 +98,13 @@ export class IdentificationStageForm extends Form { label=${t`Enrollment flow`} name="enrollmentFlow"> - + ${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({ ordering: "pk", designation: FlowDesignationEnum.Recovery, }).then(flows => { return flows.results.map(flow => { - const selected = this.stage?.recoveryFlow === flow.pk; + const selected = this.instance?.recoveryFlow === flow.pk; return html``; }); }), html``)} diff --git a/web/src/pages/stages/invitation/InvitationStageForm.ts b/web/src/pages/stages/invitation/InvitationStageForm.ts index b9917ac78..659758134 100644 --- a/web/src/pages/stages/invitation/InvitationStageForm.ts +++ b/web/src/pages/stages/invitation/InvitationStageForm.ts @@ -1,30 +1,25 @@ import { InvitationStage, StagesApi } 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-stage-invitation-form") -export class InvitationStageForm extends Form { +export class InvitationStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: InvitationStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -32,9 +27,9 @@ export class InvitationStageForm extends Form { } send = (data: InvitationStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -53,7 +48,7 @@ export class InvitationStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + @@ -62,7 +57,7 @@ export class InvitationStageForm extends Form {
- + diff --git a/web/src/pages/stages/password/PasswordStageForm.ts b/web/src/pages/stages/password/PasswordStageForm.ts index 149effb44..4b8981eba 100644 --- a/web/src/pages/stages/password/PasswordStageForm.ts +++ b/web/src/pages/stages/password/PasswordStageForm.ts @@ -1,31 +1,26 @@ import { FlowDesignationEnum, FlowsApi, PasswordStage, PasswordStageBackendsEnum, StagesApi } 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 { until } from "lit-html/directives/until"; import { first } from "../../../utils"; +import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-password-form") -export class PasswordStageForm extends Form { +export class PasswordStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesPasswordRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesPasswordRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: PasswordStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -33,9 +28,9 @@ export class PasswordStageForm extends Form { } send = (data: PasswordStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesPasswordUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -46,7 +41,7 @@ export class PasswordStageForm extends Form { }; isBackendSelected(field: PasswordStageBackendsEnum): boolean { - return (this.stage?.backends || []).filter(isField => { + return (this.instance?.backends || []).filter(isField => { return field === isField; }).length > 0; } @@ -60,7 +55,7 @@ export class PasswordStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - + @@ -87,14 +82,14 @@ export class PasswordStageForm extends Form { ?required=${true} name="configureFlow"> +

${t`How many attempts a user has before the flow is canceled. To lock the user out, use a reputation policy and a user_write stage.`}

diff --git a/web/src/pages/stages/prompt/PromptStageForm.ts b/web/src/pages/stages/prompt/PromptStageForm.ts index c18963165..89711f639 100644 --- a/web/src/pages/stages/prompt/PromptStageForm.ts +++ b/web/src/pages/stages/prompt/PromptStageForm.ts @@ -1,32 +1,27 @@ import { PoliciesApi, PromptStage, StagesApi } 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 "../../../elements/forms/ModalForm"; import "./PromptForm"; import { until } from "lit-html/directives/until"; +import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-stage-prompt-form") -export class PromptStageForm extends Form { +export class PromptStageForm extends ModelForm { - set stageUUID(value: string) { - new StagesApi(DEFAULT_CONFIG).stagesPromptStagesRead({ - stageUuid: value, - }).then(stage => { - this.stage = stage; + loadInstance(pk: string): Promise { + return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesRead({ + stageUuid: pk, }); } - @property({attribute: false}) - stage?: PromptStage; - getSuccessMessage(): string { - if (this.stage) { + if (this.instance) { return t`Successfully updated stage.`; } else { return t`Successfully created stage.`; @@ -34,9 +29,9 @@ export class PromptStageForm extends Form { } send = (data: PromptStage): Promise => { - if (this.stage) { + if (this.instance) { return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesUpdate({ - stageUuid: this.stage.pk || "", + stageUuid: this.instance.pk || "", data: data }); } else { @@ -55,7 +50,7 @@ export class PromptStageForm extends Form { label=${t`Name`} ?required=${true} name="name"> - +
@@ -71,7 +66,7 @@ export class PromptStageForm extends Form { ordering: "field_name" }).then(prompts => { return prompts.results.map(prompt => { - const selected = Array.from(this.stage?.fields || []).some(su => { + const selected = Array.from(this.instance?.fields || []).some(su => { return su == prompt.pk; }); return html`