web: add first() to improve defaults
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
42cb55d78a
commit
43f37e4776
|
@ -6,7 +6,7 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
|||
import { Form } from "../../elements/forms/Form";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import { groupBy } from "../../utils";
|
||||
import { first, groupBy } from "../../utils";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
|
||||
@customElement("ak-policy-binding-form")
|
||||
|
@ -130,7 +130,7 @@ export class PolicyBindingForm extends Form<PolicyBinding> {
|
|||
label=${gettext("Timeout")}
|
||||
?required=${true}
|
||||
name="timeout">
|
||||
<input type="number" value="${this.binding?.timeout || 30}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.binding?.timeout, 30)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
</form>`;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ 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";
|
||||
|
||||
@customElement("ak-policy-dummy-form")
|
||||
export class DummyPolicyForm extends Form<DummyPolicy> {
|
||||
|
@ -78,14 +79,14 @@ export class DummyPolicyForm extends Form<DummyPolicy> {
|
|||
label=${gettext("Wait (min)")}
|
||||
?required=${true}
|
||||
name="waitMin">
|
||||
<input type="number" value="${this.policy?.waitMin || 1}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.waitMin, 1)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${gettext("The policy takes a random time to execute. This controls the minimum time it will take.")}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Wait (max)")}
|
||||
?required=${true}
|
||||
name="waitMax">
|
||||
<input type="number" value="${this.policy?.waitMax || 5}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.waitMax, 5)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
</ak-form-group>
|
||||
|
|
|
@ -7,6 +7,7 @@ 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";
|
||||
|
||||
@customElement("ak-policy-hibp-form")
|
||||
export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> {
|
||||
|
@ -76,7 +77,7 @@ export class HaveIBeenPwnedPolicyForm extends Form<HaveIBeenPwendPolicy> {
|
|||
label=${gettext("Allowed count")}
|
||||
?required=${true}
|
||||
name="allowedCount">
|
||||
<input type="number" value="${ifDefined(this.policy?.allowedCount || 0)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.allowedCount, 0)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${gettext("Allow up to N occurrences in the HIBP database.")}</p>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
|
|
|
@ -7,6 +7,7 @@ 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";
|
||||
|
||||
@customElement("ak-policy-password-form")
|
||||
export class PasswordPolicyForm extends Form<PasswordPolicy> {
|
||||
|
@ -77,25 +78,25 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> {
|
|||
label=${gettext("Minimum length")}
|
||||
?required=${true}
|
||||
name="lengthMin">
|
||||
<input type="number" value="${ifDefined(this.policy?.lengthMin || 10)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.lengthMin, 10)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Minimum amount of Uppercase Characters")}
|
||||
?required=${true}
|
||||
name="amountUppercase">
|
||||
<input type="number" value="${ifDefined(this.policy?.amountUppercase || 2)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.amountUppercase, 2)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Minimum amount of Lowercase Characters")}
|
||||
?required=${true}
|
||||
name="amountLowercase">
|
||||
<input type="number" value="${ifDefined(this.policy?.amountLowercase || 2)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.amountLowercase, 2)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Minimum amount of Symbols Characters")}
|
||||
?required=${true}
|
||||
name="amountSymbols">
|
||||
<input type="number" value="${ifDefined(this.policy?.amountSymbols || 2)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.policy?.amountSymbols, 2)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Error message")}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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";
|
||||
|
||||
@customElement("ak-stage-authenticator-static-form")
|
||||
export class AuthenticatorStaticStageForm extends Form<AuthenticatorStaticStage> {
|
||||
|
@ -61,7 +62,7 @@ export class AuthenticatorStaticStageForm extends Form<AuthenticatorStaticStage>
|
|||
label=${gettext("Token count")}
|
||||
?required=${true}
|
||||
name="tokenCount">
|
||||
<input type="text" value="${ifDefined(this.stage?.tokenCount || 6)}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${first(this.stage?.tokenCount, 6)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Configuration flow")}
|
||||
|
|
|
@ -7,6 +7,7 @@ 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";
|
||||
|
||||
@customElement("ak-stage-email-form")
|
||||
export class EmailStageForm extends Form<EmailStage> {
|
||||
|
@ -65,7 +66,7 @@ export class EmailStageForm extends Form<EmailStage> {
|
|||
label=${gettext("SMTP Port")}
|
||||
?required=${true}
|
||||
name="port">
|
||||
<input type="number" value="${ifDefined(this.stage?.port || 25)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.stage?.port, 25)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("SMTP Username")}
|
||||
|
@ -99,7 +100,7 @@ export class EmailStageForm extends Form<EmailStage> {
|
|||
label=${gettext("Timeout")}
|
||||
?required=${true}
|
||||
name="timeout">
|
||||
<input type="number" value="${ifDefined(this.stage?.timeout || 30)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.stage?.timeout, 30)}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("From address")}
|
||||
|
@ -140,14 +141,14 @@ export class EmailStageForm extends Form<EmailStage> {
|
|||
label=${gettext("Token expiry")}
|
||||
?required=${true}
|
||||
name="tokenExpiry">
|
||||
<input type="number" value="${ifDefined(this.stage?.tokenExpiry || 30)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.stage?.tokenExpiry, 30)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${gettext("Time in minutes the token sent is valid.")}</p>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Subject")}
|
||||
?required=${true}
|
||||
name="subject">
|
||||
<input type="text" value="${ifDefined(this.stage?.subject || "authentik")}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${first(this.stage?.subject, "authentik")}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Template")}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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";
|
||||
|
||||
@customElement("ak-stage-password-form")
|
||||
export class PasswordStageForm extends Form<PasswordStage> {
|
||||
|
@ -103,7 +104,7 @@ export class PasswordStageForm extends Form<PasswordStage> {
|
|||
label=${gettext("Failed attempts before cancel")}
|
||||
?required=${true}
|
||||
name="failedAttemptsBeforeCancel">
|
||||
<input type="number" value="${ifDefined(this.stage?.failedAttemptsBeforeCancel || 5)}" class="pf-c-form-control" required>
|
||||
<input type="number" value="${first(this.stage?.failedAttemptsBeforeCancel, 5)}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${gettext("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>
|
||||
|
|
|
@ -69,3 +69,13 @@ export function groupBy<T>(objects: T[], callback: (obj: T) => string): Array<[s
|
|||
});
|
||||
return Array.from(m);
|
||||
}
|
||||
|
||||
export function first<T>(...args: Array<T | undefined | null>): T {
|
||||
for (let index = 0; index < args.length; index++) {
|
||||
const element = args[index];
|
||||
if (element !== undefined && element !== null) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
throw new Error(`No compatible arg given: ${args}`);
|
||||
}
|
||||
|
|
Reference in New Issue