web/admin: migrate stage forms to ModelForm

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-11 12:33:55 +02:00
parent ce1c400022
commit 59f339beda
19 changed files with 224 additions and 302 deletions

View File

@ -58,7 +58,7 @@ export class BoundStagesList extends Table<FlowStageBinding> {
<ak-proxy-form
slot="form"
.args=${{
"stageUUID": item.stage
"instancePk": item.stage
}}
type=${ifDefined(item.stageObj?.component)}>
</ak-proxy-form>

View File

@ -90,7 +90,7 @@ export class StageListPage extends TablePage<Stage> {
<ak-proxy-form
slot="form"
.args=${{
"stageUUID": item.pk
"instancePk": item.pk
}}
type=${ifDefined(item.component)}>
</ak-proxy-form>

View File

@ -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<AuthenticatorStaticStage> {
export class AuthenticatorStaticStageForm extends ModelForm<AuthenticatorStaticStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<AuthenticatorStaticStage> {
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<AuthenticatorStaticStage>
}
send = (data: AuthenticatorStaticStage): Promise<AuthenticatorStaticStage> => {
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<AuthenticatorStaticStage>
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -65,20 +60,20 @@ export class AuthenticatorStaticStageForm extends Form<AuthenticatorStaticStage>
label=${t`Token count`}
?required=${true}
name="tokenCount">
<input type="text" value="${first(this.stage?.tokenCount, 6)}" class="pf-c-form-control" required>
<input type="text" value="${first(this.instance?.tokenCount, 6)}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`Configuration flow`}
name="configureFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.configureFlow === undefined}>---------</option>
<option value="" ?selected=${this.instance?.configureFlow === undefined}>---------</option>
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
ordering: "pk",
designation: FlowDesignationEnum.StageConfiguration,
}).then(flows => {
return flows.results.map(flow => {
let selected = this.stage?.configureFlow === flow.pk;
if (!this.stage?.pk && !this.stage?.configureFlow && flow.slug === "default-otp-time-configure") {
let selected = this.instance?.configureFlow === flow.pk;
if (!this.instance?.pk && !this.instance?.configureFlow && flow.slug === "default-otp-time-configure") {
selected = true;
}
return html`<option value=${ifDefined(flow.pk)} ?selected=${selected}>${flow.name} (${flow.slug})</option>`;

View File

@ -1,30 +1,25 @@
import { FlowDesignationEnum, FlowsApi, AuthenticatorTOTPStage, 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 { ModelForm } from "../../../elements/forms/ModelForm";
@customElement("ak-stage-authenticator-totp-form")
export class AuthenticatorTOTPStageForm extends Form<AuthenticatorTOTPStage> {
export class AuthenticatorTOTPStageForm extends ModelForm<AuthenticatorTOTPStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<AuthenticatorTOTPStage> {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: AuthenticatorTOTPStage;
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 AuthenticatorTOTPStageForm extends Form<AuthenticatorTOTPStage> {
}
send = (data: AuthenticatorTOTPStage): Promise<AuthenticatorTOTPStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -53,7 +48,7 @@ export class AuthenticatorTOTPStageForm extends Form<AuthenticatorTOTPStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -65,10 +60,10 @@ export class AuthenticatorTOTPStageForm extends Form<AuthenticatorTOTPStage> {
?required=${true}
name="digits">
<select name="users" class="pf-c-form-control">
<option value="6" ?selected=${this.stage?.digits === 6}>
<option value="6" ?selected=${this.instance?.digits === 6}>
${t`6 digits, widely compatible`}
</option>
<option value="8" ?selected=${this.stage?.digits === 8}>
<option value="8" ?selected=${this.instance?.digits === 8}>
${t`8 digits, not compatible with apps like Google Authenticator`}
</option>
</select>
@ -77,14 +72,14 @@ export class AuthenticatorTOTPStageForm extends Form<AuthenticatorTOTPStage> {
label=${t`Configuration flow`}
name="configureFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.configureFlow === undefined}>---------</option>
<option value="" ?selected=${this.instance?.configureFlow === undefined}>---------</option>
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
ordering: "pk",
designation: FlowDesignationEnum.StageConfiguration,
}).then(flows => {
return flows.results.map(flow => {
let selected = this.stage?.configureFlow === flow.pk;
if (!this.stage?.pk && !this.stage?.configureFlow && flow.slug === "default-otp-time-configure") {
let selected = this.instance?.configureFlow === flow.pk;
if (!this.instance?.pk && !this.instance?.configureFlow && flow.slug === "default-otp-time-configure") {
selected = true;
}
return html`<option value=${ifDefined(flow.pk)} ?selected=${selected}>${flow.name} (${flow.slug})</option>`;

View File

@ -3,32 +3,29 @@ 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 { until } from "lit-html/directives/until";
import { ModelForm } from "../../../elements/forms/ModelForm";
@customElement("ak-stage-authenticator-validate-form")
export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateStage> {
export class AuthenticatorValidateStageForm extends ModelForm<AuthenticatorValidateStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorValidateRead({
stageUuid: value,
loadInstance(pk: string): Promise<AuthenticatorValidateStage> {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorValidateRead({
stageUuid: pk,
}).then(stage => {
this.stage = stage;
this.showConfigureFlow = stage.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Configure;
return stage;
});
}
@property({attribute: false})
stage?: AuthenticatorValidateStage;
@property({ type: Boolean })
showConfigureFlow = false;
getSuccessMessage(): string {
if (this.stage) {
if (this.instance) {
return t`Successfully updated stage.`;
} else {
return t`Successfully created stage.`;
@ -36,9 +33,9 @@ export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateSt
}
send = (data: AuthenticatorValidateStage): Promise<AuthenticatorValidateStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorValidateUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -49,7 +46,7 @@ export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateSt
};
isDeviceClassSelected(field: AuthenticatorValidateStageDeviceClassesEnum): boolean {
return (this.stage?.deviceClasses || []).filter(isField => {
return (this.instance?.deviceClasses || []).filter(isField => {
return field === isField;
}).length > 0;
}
@ -63,7 +60,7 @@ export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateSt
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -82,13 +79,13 @@ export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateSt
this.showConfigureFlow = false;
}
}}>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Configure} ?selected=${this.stage?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Configure}>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Configure} ?selected=${this.instance?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Configure}>
${t`Force the user to configure an authenticator`}
</option>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Deny} ?selected=${this.stage?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Deny}>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Deny} ?selected=${this.instance?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Deny}>
${t`Deny the user access`}
</option>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Skip} ?selected=${this.stage?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Skip}>
<option value=${AuthenticatorValidateStageNotConfiguredActionEnum.Skip} ?selected=${this.instance?.notConfiguredAction === AuthenticatorValidateStageNotConfiguredActionEnum.Skip}>
${t`Continue`}
</option>
</select>
@ -117,12 +114,12 @@ export class AuthenticatorValidateStageForm extends Form<AuthenticatorValidateSt
?required=${true}
name="configureFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.configurationStage === undefined}>---------</option>
<option value="" ?selected=${this.instance?.configurationStage === undefined}>---------</option>
${until(new StagesApi(DEFAULT_CONFIG).stagesAllList({
ordering: "pk",
}).then(stages => {
return stages.results.map(stage => {
const selected = this.stage?.configurationStage === stage.pk;
const selected = this.instance?.configurationStage === stage.pk;
return html`<option value=${ifDefined(stage.pk)} ?selected=${selected}>${stage.name} (${stage.verboseName})</option>`;
});
}), html`<option>${t`Loading...`}</option>`)}

View File

@ -1,28 +1,23 @@
import { AuthenticateWebAuthnStage, 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-authenticator-webauthn-form")
export class AuthenticateWebAuthnStageForm extends Form<AuthenticateWebAuthnStage> {
export class AuthenticateWebAuthnStageForm extends ModelForm<AuthenticateWebAuthnStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<AuthenticateWebAuthnStage> {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: AuthenticateWebAuthnStage;
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 AuthenticateWebAuthnStageForm extends Form<AuthenticateWebAuthnStag
}
send = (data: AuthenticateWebAuthnStage): Promise<AuthenticateWebAuthnStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -51,7 +46,7 @@ export class AuthenticateWebAuthnStageForm extends Form<AuthenticateWebAuthnStag
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}

View File

@ -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<CaptchaStage> {
export class CaptchaStageForm extends ModelForm<CaptchaStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesCaptchaRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<CaptchaStage> {
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<CaptchaStage> {
}
send = (data: CaptchaStage): Promise<CaptchaStage> => {
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<CaptchaStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -63,15 +58,15 @@ export class CaptchaStageForm extends Form<CaptchaStage> {
label=${t`Public Key`}
?required=${true}
name="publicKey">
<input type="text" value="${ifDefined(this.stage?.publicKey || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.publicKey || "")}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${t`Public key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}</p>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`Private Key`}
?required=${true}
?writeOnly=${this.stage !== undefined}
?writeOnly=${this.instance !== undefined}
name="privateKey">
<input type="text" value="${ifDefined(this.stage?.privateKey || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.privateKey || "")}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${t`Private key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}</p>
</ak-form-element-horizontal>
</div>

View File

@ -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<ConsentStage> {
export class ConsentStageForm extends ModelForm<ConsentStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesConsentRead({
stageUuid: value,
loadInstance(pk: string): Promise<ConsentStage> {
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<ConsentStage> {
}
send = (data: ConsentStage): Promise<ConsentStage> => {
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<ConsentStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -75,13 +72,13 @@ export class ConsentStageForm extends Form<ConsentStage> {
this.showExpiresIn = false;
}
}}>
<option value=${ConsentStageModeEnum.AlwaysRequire} ?selected=${this.stage?.mode === ConsentStageModeEnum.AlwaysRequire}>
<option value=${ConsentStageModeEnum.AlwaysRequire} ?selected=${this.instance?.mode === ConsentStageModeEnum.AlwaysRequire}>
${t`Always require consent`}
</option>
<option value=${ConsentStageModeEnum.Permanent} ?selected=${this.stage?.mode === ConsentStageModeEnum.Permanent}>
<option value=${ConsentStageModeEnum.Permanent} ?selected=${this.instance?.mode === ConsentStageModeEnum.Permanent}>
${t`Consent given last indefinitely`}
</option>
<option value=${ConsentStageModeEnum.Expiring} ?selected=${this.stage?.mode === ConsentStageModeEnum.Expiring}>
<option value=${ConsentStageModeEnum.Expiring} ?selected=${this.instance?.mode === ConsentStageModeEnum.Expiring}>
${t`Consent expires.`}
</option>
</select>
@ -91,7 +88,7 @@ export class ConsentStageForm extends Form<ConsentStage> {
label=${t`Consent expires in`}
?required=${true}
name="consentExpireIn">
<input type="text" value="${ifDefined(this.stage?.consentExpireIn || "weeks=4")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.consentExpireIn || "weeks=4")}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${t`Offset after which consent expires. (Format: hours=1;minutes=2;seconds=3).`}</p>
</ak-form-element-horizontal>
</div>

View File

@ -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<DenyStage> {
export class DenyStageForm extends ModelForm<DenyStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesDenyRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<DenyStage> {
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<DenyStage> {
}
send = (data: DenyStage): Promise<DenyStage> => {
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<DenyStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}

View File

@ -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<DummyStage> {
export class DummyStageForm extends ModelForm<DummyStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesDummyRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<DummyStage> {
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<DummyStage> {
}
send = (data: DummyStage): Promise<DummyStage> => {
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<DummyStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}

View File

@ -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<EmailStage> {
export class EmailStageForm extends ModelForm<EmailStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesEmailRead({
stageUuid: value,
loadInstance(pk: string): Promise<EmailStage> {
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<EmailStage> {
}
send = (data: EmailStage): Promise<EmailStage> => {
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<EmailStage> {
label=${t`SMTP Host`}
?required=${true}
name="host">
<input type="text" value="${ifDefined(this.stage?.host || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.host || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`SMTP Port`}
?required=${true}
name="port">
<input type="number" value="${first(this.stage?.port, 25)}" class="pf-c-form-control" required>
<input type="number" value="${first(this.instance?.port, 25)}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`SMTP Username`}
name="username">
<input type="text" value="${ifDefined(this.stage?.username || "")}" class="pf-c-form-control">
<input type="text" value="${ifDefined(this.instance?.username || "")}" class="pf-c-form-control">
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`SMTP Password`}
?writeOnly=${this.stage !== undefined}
?writeOnly=${this.instance !== undefined}
name="password">
<input type="text" value="${ifDefined(this.stage?.password || "")}" class="pf-c-form-control">
<input type="text" value="${ifDefined(this.instance?.password || "")}" class="pf-c-form-control">
</ak-form-element-horizontal>
<ak-form-element-horizontal name="useTls">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.useTls, true)}>
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.useTls, true)}>
<label class="pf-c-check__label">
${t`Use TLS`}
</label>
@ -90,7 +88,7 @@ export class EmailStageForm extends Form<EmailStage> {
</ak-form-element-horizontal>
<ak-form-element-horizontal name="useSsl">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.useSsl, false)}>
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.useSsl, false)}>
<label class="pf-c-check__label">
${t`Use SSL`}
</label>
@ -100,13 +98,13 @@ export class EmailStageForm extends Form<EmailStage> {
label=${t`Timeout`}
?required=${true}
name="timeout">
<input type="number" value="${first(this.stage?.timeout, 30)}" class="pf-c-form-control" required>
<input type="number" value="${first(this.instance?.timeout, 30)}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`From address`}
?required=${true}
name="fromAddress">
<input type="text" value="${ifDefined(this.stage?.fromAddress || "system@authentik.local")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.fromAddress || "system@authentik.local")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</div>
</ak-form-group>`;
@ -121,7 +119,7 @@ export class EmailStageForm extends Form<EmailStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -130,7 +128,7 @@ export class EmailStageForm extends Form<EmailStage> {
<div slot="body" class="pf-c-form">
<ak-form-element-horizontal name="useGlobalSettings">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.useGlobalSettings, true)} @change=${(ev: Event) => {
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.useGlobalSettings, true)} @change=${(ev: Event) => {
const target = ev.target as HTMLInputElement;
this.showConnectionSettings = !target.checked;
}}>
@ -144,14 +142,14 @@ export class EmailStageForm extends Form<EmailStage> {
label=${t`Token expiry`}
?required=${true}
name="tokenExpiry">
<input type="number" value="${first(this.stage?.tokenExpiry, 30)}" class="pf-c-form-control" required>
<input type="number" value="${first(this.instance?.tokenExpiry, 30)}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${t`Time in minutes the token sent is valid.`}</p>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`Subject`}
?required=${true}
name="subject">
<input type="text" value="${first(this.stage?.subject, "authentik")}" class="pf-c-form-control" required>
<input type="text" value="${first(this.instance?.subject, "authentik")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${t`Template`}
@ -160,7 +158,7 @@ export class EmailStageForm extends Form<EmailStage> {
<select name="users" class="pf-c-form-control">
${until(new StagesApi(DEFAULT_CONFIG).stagesEmailTemplates().then(templates => {
return templates.map(template => {
const selected = this.stage?.template === template.name;
const selected = this.instance?.template === template.name;
return html`<option value=${ifDefined(template.name)} ?selected=${selected}>
${template.description}
</option>`;

View File

@ -1,31 +1,26 @@
import { FlowDesignationEnum, FlowsApi, IdentificationStage, IdentificationStageUserFieldsEnum, 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-identification-form")
export class IdentificationStageForm extends Form<IdentificationStage> {
export class IdentificationStageForm extends ModelForm<IdentificationStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesIdentificationRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<IdentificationStage> {
return new StagesApi(DEFAULT_CONFIG).stagesIdentificationRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: IdentificationStage;
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 IdentificationStageForm extends Form<IdentificationStage> {
}
send = (data: IdentificationStage): Promise<IdentificationStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesIdentificationUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -46,7 +41,7 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
};
isUserFieldSelected(field: IdentificationStageUserFieldsEnum): boolean {
return (this.stage?.userFields || []).filter(isField => {
return (this.instance?.userFields || []).filter(isField => {
return field === isField;
}).length > 0;
}
@ -60,7 +55,7 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -83,7 +78,7 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
</ak-form-element-horizontal>
<ak-form-element-horizontal name="caseInsensitiveMatching">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.caseInsensitiveMatching, true)}>
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.caseInsensitiveMatching, true)}>
<label class="pf-c-check__label">
${t`Case insensitive matching`}
</label>
@ -92,7 +87,7 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
</ak-form-element-horizontal>
<ak-form-element-horizontal name="showMatchedUser">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.showMatchedUser, true)}>
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.showMatchedUser, true)}>
<label class="pf-c-check__label">
${t`Show matched user`}
</label>
@ -103,13 +98,13 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
label=${t`Enrollment flow`}
name="enrollmentFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.enrollmentFlow === undefined}>---------</option>
<option value="" ?selected=${this.instance?.enrollmentFlow === undefined}>---------</option>
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
ordering: "pk",
designation: FlowDesignationEnum.Enrollment,
}).then(flows => {
return flows.results.map(flow => {
const selected = this.stage?.enrollmentFlow === flow.pk;
const selected = this.instance?.enrollmentFlow === flow.pk;
return html`<option value=${ifDefined(flow.pk)} ?selected=${selected}>${flow.name} (${flow.slug})</option>`;
});
}), html`<option>${t`Loading...`}</option>`)}
@ -120,13 +115,13 @@ export class IdentificationStageForm extends Form<IdentificationStage> {
label=${t`Recovery flow`}
name="recoveryFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.recoveryFlow === undefined}>---------</option>
<option value="" ?selected=${this.instance?.recoveryFlow === undefined}>---------</option>
${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`<option value=${ifDefined(flow.pk)} ?selected=${selected}>${flow.name} (${flow.slug})</option>`;
});
}), html`<option>${t`Loading...`}</option>`)}

View File

@ -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<InvitationStage> {
export class InvitationStageForm extends ModelForm<InvitationStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesInvitationStagesRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<InvitationStage> {
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<InvitationStage> {
}
send = (data: InvitationStage): Promise<InvitationStage> => {
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<InvitationStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -62,7 +57,7 @@ export class InvitationStageForm extends Form<InvitationStage> {
<div slot="body" class="pf-c-form">
<ak-form-element-horizontal name="continueFlowWithoutInvitation">
<div class="pf-c-check">
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.stage?.continueFlowWithoutInvitation, true)}>
<input type="checkbox" class="pf-c-check__input" ?checked=${first(this.instance?.continueFlowWithoutInvitation, true)}>
<label class="pf-c-check__label">
${t`Continue flow without invitation`}
</label>

View File

@ -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<PasswordStage> {
export class PasswordStageForm extends ModelForm<PasswordStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesPasswordRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<PasswordStage> {
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<PasswordStage> {
}
send = (data: PasswordStage): Promise<PasswordStage> => {
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<PasswordStage> {
};
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<PasswordStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -87,14 +82,14 @@ export class PasswordStageForm extends Form<PasswordStage> {
?required=${true}
name="configureFlow">
<select class="pf-c-form-control">
<option value="" ?selected=${this.stage?.configureFlow === undefined}>---------</option>
<option value="" ?selected=${this.instance?.configureFlow === undefined}>---------</option>
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
ordering: "pk",
designation: FlowDesignationEnum.StageConfiguration,
}).then(flows => {
return flows.results.map(flow => {
let selected = this.stage?.configureFlow === flow.pk;
if (!this.stage?.pk && !this.stage?.configureFlow && flow.slug === "default-password-change") {
let selected = this.instance?.configureFlow === flow.pk;
if (!this.instance?.pk && !this.instance?.configureFlow && flow.slug === "default-password-change") {
selected = true;
}
return html`<option value=${ifDefined(flow.pk)} ?selected=${selected}>${flow.name} (${flow.slug})</option>`;
@ -107,7 +102,7 @@ export class PasswordStageForm extends Form<PasswordStage> {
label=${t`Failed attempts before cancel`}
?required=${true}
name="failedAttemptsBeforeCancel">
<input type="number" value="${first(this.stage?.failedAttemptsBeforeCancel, 5)}" class="pf-c-form-control" required>
<input type="number" value="${first(this.instance?.failedAttemptsBeforeCancel, 5)}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${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.`}</p>
</ak-form-element-horizontal>
</div>

View File

@ -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<PromptStage> {
export class PromptStageForm extends ModelForm<PromptStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesPromptStagesRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<PromptStage> {
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<PromptStage> {
}
send = (data: PromptStage): Promise<PromptStage> => {
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<PromptStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -71,7 +66,7 @@ export class PromptStageForm extends Form<PromptStage> {
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`<option value=${ifDefined(prompt.pk)} ?selected=${selected}>
@ -103,7 +98,7 @@ export class PromptStageForm extends Form<PromptStage> {
ordering: "name"
}).then(policies => {
return policies.results.map(policy => {
const selected = Array.from(this.stage?.validationPolicies || []).some(su => {
const selected = Array.from(this.instance?.validationPolicies || []).some(su => {
return su == policy.pk;
});
return html`<option value=${ifDefined(policy.pk)} ?selected=${selected}>

View File

@ -1,28 +1,23 @@
import { UserDeleteStage, 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-user-delete-form")
export class UserDeleteStageForm extends Form<UserDeleteStage> {
export class UserDeleteStageForm extends ModelForm<UserDeleteStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserDeleteRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<UserDeleteStage> {
return new StagesApi(DEFAULT_CONFIG).stagesUserDeleteRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: UserDeleteStage;
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 UserDeleteStageForm extends Form<UserDeleteStage> {
}
send = (data: UserDeleteStage): Promise<UserDeleteStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesUserDeleteUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -52,7 +47,7 @@ export class UserDeleteStageForm extends Form<UserDeleteStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}

View File

@ -1,29 +1,24 @@
import { UserLoginStage, 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 "../../../elements/forms/HorizontalFormElement";
import "../../../elements/forms/FormGroup";
import { first } from "../../../utils";
import { ModelForm } from "../../../elements/forms/ModelForm";
@customElement("ak-stage-user-login-form")
export class UserLoginStageForm extends Form<UserLoginStage> {
export class UserLoginStageForm extends ModelForm<UserLoginStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserLoginRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<UserLoginStage> {
return new StagesApi(DEFAULT_CONFIG).stagesUserLoginRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: UserLoginStage;
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 UserLoginStageForm extends Form<UserLoginStage> {
}
send = (data: UserLoginStage): Promise<UserLoginStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesUserLoginUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -52,7 +47,7 @@ export class UserLoginStageForm extends Form<UserLoginStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${first(this.stage?.name, "")}" class="pf-c-form-control" required>
<input type="text" value="${first(this.instance?.name, "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
<ak-form-group .expanded=${true}>
<span slot="header">
@ -63,7 +58,7 @@ export class UserLoginStageForm extends Form<UserLoginStage> {
label=${t`Session duration`}
?required=${true}
name="sessionDuration">
<input type="text" value="${first(this.stage?.sessionDuration, "seconds=0")}" class="pf-c-form-control" required>
<input type="text" value="${first(this.instance?.sessionDuration, "seconds=0")}" class="pf-c-form-control" required>
<p class="pf-c-form__helper-text">${t`Determines how long a session lasts. Default of 0 seconds means that the sessions lasts until the browser is closed.`}</p>
<p class="pf-c-form__helper-text">${t`(Format: hours=-1;minutes=-2;seconds=-3).`}</p>
</ak-form-element-horizontal>

View File

@ -1,28 +1,23 @@
import { UserLogoutStage, 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-user-logout-form")
export class UserLogoutStageForm extends Form<UserLogoutStage> {
export class UserLogoutStageForm extends ModelForm<UserLogoutStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserLogoutRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<UserLogoutStage> {
return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: UserLogoutStage;
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 UserLogoutStageForm extends Form<UserLogoutStage> {
}
send = (data: UserLogoutStage): Promise<UserLogoutStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -51,7 +46,7 @@ export class UserLogoutStageForm extends Form<UserLogoutStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}

View File

@ -1,28 +1,23 @@
import { UserWriteStage, 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-user-write-form")
export class UserWriteStageForm extends Form<UserWriteStage> {
export class UserWriteStageForm extends ModelForm<UserWriteStage, string> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserWriteRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
loadInstance(pk: string): Promise<UserWriteStage> {
return new StagesApi(DEFAULT_CONFIG).stagesUserWriteRead({
stageUuid: pk,
});
}
@property({attribute: false})
stage?: UserWriteStage;
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 UserWriteStageForm extends Form<UserWriteStage> {
}
send = (data: UserWriteStage): Promise<UserWriteStage> => {
if (this.stage) {
if (this.instance) {
return new StagesApi(DEFAULT_CONFIG).stagesUserWriteUpdate({
stageUuid: this.stage.pk || "",
stageUuid: this.instance.pk || "",
data: data
});
} else {
@ -52,7 +47,7 @@ export class UserWriteStageForm extends Form<UserWriteStage> {
label=${t`Name`}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
<input type="text" value="${ifDefined(this.instance?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}