From 43f37e47766d269b7bb2419cfb9c51a7a4162d46 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Apr 2021 11:41:11 +0200 Subject: [PATCH] web: add first() to improve defaults Signed-off-by: Jens Langhammer --- web/src/pages/policies/PolicyBindingForm.ts | 4 ++-- web/src/pages/policies/dummy/DummyPolicyForm.ts | 5 +++-- .../pages/policies/hibp/HaveIBeenPwnedPolicyForm.ts | 3 ++- web/src/pages/policies/password/PasswordPolicyForm.ts | 9 +++++---- .../AuthenticatorStaticStageForm.ts | 3 ++- web/src/pages/stages/email/EmailStageForm.ts | 9 +++++---- web/src/pages/stages/password/PasswordStageForm.ts | 3 ++- web/src/utils.ts | 10 ++++++++++ 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/web/src/pages/policies/PolicyBindingForm.ts b/web/src/pages/policies/PolicyBindingForm.ts index eced5877c..645a6a678 100644 --- a/web/src/pages/policies/PolicyBindingForm.ts +++ b/web/src/pages/policies/PolicyBindingForm.ts @@ -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 { label=${gettext("Timeout")} ?required=${true} name="timeout"> - + `; } diff --git a/web/src/pages/policies/dummy/DummyPolicyForm.ts b/web/src/pages/policies/dummy/DummyPolicyForm.ts index fc7c4ed25..b1d18012f 100644 --- a/web/src/pages/policies/dummy/DummyPolicyForm.ts +++ b/web/src/pages/policies/dummy/DummyPolicyForm.ts @@ -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 { @@ -78,14 +79,14 @@ export class DummyPolicyForm extends Form { label=${gettext("Wait (min)")} ?required=${true} name="waitMin"> - +

${gettext("The policy takes a random time to execute. This controls the minimum time it will take.")}

- + diff --git a/web/src/pages/policies/hibp/HaveIBeenPwnedPolicyForm.ts b/web/src/pages/policies/hibp/HaveIBeenPwnedPolicyForm.ts index 2eeefe292..25c5aa0b5 100644 --- a/web/src/pages/policies/hibp/HaveIBeenPwnedPolicyForm.ts +++ b/web/src/pages/policies/hibp/HaveIBeenPwnedPolicyForm.ts @@ -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 { @@ -76,7 +77,7 @@ export class HaveIBeenPwnedPolicyForm extends Form { label=${gettext("Allowed count")} ?required=${true} name="allowedCount"> - +

${gettext("Allow up to N occurrences in the HIBP database.")}

diff --git a/web/src/pages/policies/password/PasswordPolicyForm.ts b/web/src/pages/policies/password/PasswordPolicyForm.ts index f3ad38ac7..628ecfdcc 100644 --- a/web/src/pages/policies/password/PasswordPolicyForm.ts +++ b/web/src/pages/policies/password/PasswordPolicyForm.ts @@ -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 { @@ -77,25 +78,25 @@ export class PasswordPolicyForm extends Form { label=${gettext("Minimum length")} ?required=${true} name="lengthMin"> - + - + - + - + { @@ -61,7 +62,7 @@ export class AuthenticatorStaticStageForm extends Form label=${gettext("Token count")} ?required=${true} name="tokenCount"> - + { @@ -65,7 +66,7 @@ export class EmailStageForm extends Form { label=${gettext("SMTP Port")} ?required=${true} name="port"> - + { label=${gettext("Timeout")} ?required=${true} name="timeout"> - + { label=${gettext("Token expiry")} ?required=${true} name="tokenExpiry"> - +

${gettext("Time in minutes the token sent is valid.")}

- + { @@ -103,7 +104,7 @@ export class PasswordStageForm extends Form { label=${gettext("Failed attempts before cancel")} ?required=${true} name="failedAttemptsBeforeCancel"> - +

${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.")}

diff --git a/web/src/utils.ts b/web/src/utils.ts index b36342dbd..4d79f52b2 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -69,3 +69,13 @@ export function groupBy(objects: T[], callback: (obj: T) => string): Array<[s }); return Array.from(m); } + +export function first(...args: Array): 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}`); +}