From c363b1cfde52b1499cb0039762c49ca745e81971 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 18 Nov 2021 20:44:15 +0100 Subject: [PATCH] web/admin: unify rendering and sorting of user lists Signed-off-by: Jens Langhammer --- web/src/elements/user/utils.ts | 19 +++++++++++++++++++ .../ApplicationCheckAccessForm.ts | 3 ++- web/src/pages/groups/GroupForm.ts | 3 ++- web/src/pages/policies/PolicyBindingForm.ts | 5 +++-- web/src/pages/policies/PolicyTestForm.ts | 3 ++- .../PropertyMappingTestForm.ts | 3 ++- web/src/pages/tokens/TokenForm.ts | 3 ++- 7 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 web/src/elements/user/utils.ts diff --git a/web/src/elements/user/utils.ts b/web/src/elements/user/utils.ts new file mode 100644 index 000000000..99dfa4927 --- /dev/null +++ b/web/src/elements/user/utils.ts @@ -0,0 +1,19 @@ +import { User } from "@goauthentik/api"; + +export function UserOption(user: User): string { + let finalString = user.username; + if (user.name || user.email) { + finalString += " ("; + if (user.name) { + finalString += user.name; + if (user.email) { + finalString += ", "; + } + } + if (user.email) { + finalString += user.email; + } + finalString += ")"; + } + return finalString; +} diff --git a/web/src/pages/applications/ApplicationCheckAccessForm.ts b/web/src/pages/applications/ApplicationCheckAccessForm.ts index a3b455549..b8c0f233b 100644 --- a/web/src/pages/applications/ApplicationCheckAccessForm.ts +++ b/web/src/pages/applications/ApplicationCheckAccessForm.ts @@ -9,6 +9,7 @@ import { Application, CoreApi, PolicyTestResult } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import { Form } from "../../elements/forms/Form"; import "../../elements/forms/HorizontalFormElement"; +import { UserOption } from "../../elements/user/utils"; @customElement("ak-application-check-access-form") export class ApplicationCheckAccessForm extends Form<{ forUser: number }> { @@ -84,7 +85,7 @@ export class ApplicationCheckAccessForm extends Form<{ forUser: number }> { ?selected=${user.pk.toString() === this.request?.toString()} value=${user.pk} > - ${user.username} + ${UserOption(user)} `; }); }), diff --git a/web/src/pages/groups/GroupForm.ts b/web/src/pages/groups/GroupForm.ts index 743896cd9..ba19d6b44 100644 --- a/web/src/pages/groups/GroupForm.ts +++ b/web/src/pages/groups/GroupForm.ts @@ -15,6 +15,7 @@ import "../../elements/chips/Chip"; import "../../elements/chips/ChipGroup"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; +import { UserOption } from "../../elements/user/utils"; import { first } from "../../utils"; import "./MemberSelectModal"; @@ -138,7 +139,7 @@ export class GroupForm extends ModelForm { this.requestUpdate(); }} > - ${user.username} + ${UserOption(user)} `; }); }), diff --git a/web/src/pages/policies/PolicyBindingForm.ts b/web/src/pages/policies/PolicyBindingForm.ts index c2e1184f2..cc515ce97 100644 --- a/web/src/pages/policies/PolicyBindingForm.ts +++ b/web/src/pages/policies/PolicyBindingForm.ts @@ -14,6 +14,7 @@ import { CoreApi, PoliciesApi, Policy, PolicyBinding } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; +import { UserOption } from "../../elements/user/utils"; import { first, groupBy } from "../../utils"; enum target { @@ -237,7 +238,7 @@ export class PolicyBindingForm extends ModelForm { ${until( new CoreApi(DEFAULT_CONFIG) .coreUsersList({ - ordering: "name", + ordering: "username", }) .then((users) => { return users.results.map((user) => { @@ -245,7 +246,7 @@ export class PolicyBindingForm extends ModelForm { value=${ifDefined(user.pk)} ?selected=${user.pk === this.instance?.user} > - ${user.name} + ${UserOption(user)} `; }); }), diff --git a/web/src/pages/policies/PolicyTestForm.ts b/web/src/pages/policies/PolicyTestForm.ts index fa58b594f..024ed306f 100644 --- a/web/src/pages/policies/PolicyTestForm.ts +++ b/web/src/pages/policies/PolicyTestForm.ts @@ -18,6 +18,7 @@ import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/CodeMirror"; import { Form } from "../../elements/forms/Form"; import "../../elements/forms/HorizontalFormElement"; +import { UserOption } from "../../elements/user/utils"; import { first } from "../../utils"; @customElement("ak-policy-test-form") @@ -90,7 +91,7 @@ export class PolicyTestForm extends Form { user.pk.toString()} value=${user.pk} > - ${user.username} + ${UserOption(user)} `; }); }), diff --git a/web/src/pages/property-mappings/PropertyMappingTestForm.ts b/web/src/pages/property-mappings/PropertyMappingTestForm.ts index 4924242c5..4f0376e6e 100644 --- a/web/src/pages/property-mappings/PropertyMappingTestForm.ts +++ b/web/src/pages/property-mappings/PropertyMappingTestForm.ts @@ -19,6 +19,7 @@ import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/CodeMirror"; import { Form } from "../../elements/forms/Form"; import "../../elements/forms/HorizontalFormElement"; +import { UserOption } from "../../elements/user/utils"; import { first } from "../../utils"; @customElement("ak-property-mapping-test-form") @@ -80,7 +81,7 @@ export class PolicyTestForm extends Form { user.pk.toString()} value=${user.pk} > - ${user.username} + ${UserOption(user)} `; }); }), diff --git a/web/src/pages/tokens/TokenForm.ts b/web/src/pages/tokens/TokenForm.ts index 43f7db444..a0d521571 100644 --- a/web/src/pages/tokens/TokenForm.ts +++ b/web/src/pages/tokens/TokenForm.ts @@ -10,6 +10,7 @@ import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/FormGroup"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; +import { UserOption } from "../../elements/user/utils"; import { dateTimeLocal, first } from "../../utils"; @customElement("ak-token-form") @@ -67,7 +68,7 @@ export class TokenForm extends ModelForm { value=${user.pk} ?selected=${this.instance?.user === user.pk} > - ${user.username} + ${UserOption(user)} `; }); }),