web/admin: unify rendering and sorting of user lists
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
b30ffd1318
commit
c363b1cfde
19
web/src/elements/user/utils.ts
Normal file
19
web/src/elements/user/utils.ts
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import { Application, CoreApi, PolicyTestResult } from "@goauthentik/api";
|
||||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import { Form } from "../../elements/forms/Form";
|
import { Form } from "../../elements/forms/Form";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
|
|
||||||
@customElement("ak-application-check-access-form")
|
@customElement("ak-application-check-access-form")
|
||||||
export class ApplicationCheckAccessForm extends Form<{ forUser: number }> {
|
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()}
|
?selected=${user.pk.toString() === this.request?.toString()}
|
||||||
value=${user.pk}
|
value=${user.pk}
|
||||||
>
|
>
|
||||||
${user.username}
|
${UserOption(user)}
|
||||||
</option>`;
|
</option>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -15,6 +15,7 @@ import "../../elements/chips/Chip";
|
||||||
import "../../elements/chips/ChipGroup";
|
import "../../elements/chips/ChipGroup";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
import { first } from "../../utils";
|
import { first } from "../../utils";
|
||||||
import "./MemberSelectModal";
|
import "./MemberSelectModal";
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ export class GroupForm extends ModelForm<Group, string> {
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
${user.username}
|
${UserOption(user)}
|
||||||
</ak-chip>`;
|
</ak-chip>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { CoreApi, PoliciesApi, Policy, PolicyBinding } from "@goauthentik/api";
|
||||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
import { first, groupBy } from "../../utils";
|
import { first, groupBy } from "../../utils";
|
||||||
|
|
||||||
enum target {
|
enum target {
|
||||||
|
@ -237,7 +238,7 @@ export class PolicyBindingForm extends ModelForm<PolicyBinding, string> {
|
||||||
${until(
|
${until(
|
||||||
new CoreApi(DEFAULT_CONFIG)
|
new CoreApi(DEFAULT_CONFIG)
|
||||||
.coreUsersList({
|
.coreUsersList({
|
||||||
ordering: "name",
|
ordering: "username",
|
||||||
})
|
})
|
||||||
.then((users) => {
|
.then((users) => {
|
||||||
return users.results.map((user) => {
|
return users.results.map((user) => {
|
||||||
|
@ -245,7 +246,7 @@ export class PolicyBindingForm extends ModelForm<PolicyBinding, string> {
|
||||||
value=${ifDefined(user.pk)}
|
value=${ifDefined(user.pk)}
|
||||||
?selected=${user.pk === this.instance?.user}
|
?selected=${user.pk === this.instance?.user}
|
||||||
>
|
>
|
||||||
${user.name}
|
${UserOption(user)}
|
||||||
</option>`;
|
</option>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import "../../elements/CodeMirror";
|
import "../../elements/CodeMirror";
|
||||||
import { Form } from "../../elements/forms/Form";
|
import { Form } from "../../elements/forms/Form";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
import { first } from "../../utils";
|
import { first } from "../../utils";
|
||||||
|
|
||||||
@customElement("ak-policy-test-form")
|
@customElement("ak-policy-test-form")
|
||||||
|
@ -90,7 +91,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
user.pk.toString()}
|
user.pk.toString()}
|
||||||
value=${user.pk}
|
value=${user.pk}
|
||||||
>
|
>
|
||||||
${user.username}
|
${UserOption(user)}
|
||||||
</option>`;
|
</option>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import "../../elements/CodeMirror";
|
import "../../elements/CodeMirror";
|
||||||
import { Form } from "../../elements/forms/Form";
|
import { Form } from "../../elements/forms/Form";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
import { first } from "../../utils";
|
import { first } from "../../utils";
|
||||||
|
|
||||||
@customElement("ak-property-mapping-test-form")
|
@customElement("ak-property-mapping-test-form")
|
||||||
|
@ -80,7 +81,7 @@ export class PolicyTestForm extends Form<PolicyTestRequest> {
|
||||||
user.pk.toString()}
|
user.pk.toString()}
|
||||||
value=${user.pk}
|
value=${user.pk}
|
||||||
>
|
>
|
||||||
${user.username}
|
${UserOption(user)}
|
||||||
</option>`;
|
</option>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import "../../elements/forms/FormGroup";
|
import "../../elements/forms/FormGroup";
|
||||||
import "../../elements/forms/HorizontalFormElement";
|
import "../../elements/forms/HorizontalFormElement";
|
||||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||||
|
import { UserOption } from "../../elements/user/utils";
|
||||||
import { dateTimeLocal, first } from "../../utils";
|
import { dateTimeLocal, first } from "../../utils";
|
||||||
|
|
||||||
@customElement("ak-token-form")
|
@customElement("ak-token-form")
|
||||||
|
@ -67,7 +68,7 @@ export class TokenForm extends ModelForm<Token, string> {
|
||||||
value=${user.pk}
|
value=${user.pk}
|
||||||
?selected=${this.instance?.user === user.pk}
|
?selected=${this.instance?.user === user.pk}
|
||||||
>
|
>
|
||||||
${user.username}
|
${UserOption(user)}
|
||||||
</option>`;
|
</option>`;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
Reference in a new issue