web/admin: show matching user reputation scores in user details (#10276)

Co-authored-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Marc 'risson' Schmitt
2024-06-28 14:18:38 +02:00
committed by GitHub
parent 8915904cc7
commit 98c8402f11
4 changed files with 126 additions and 1 deletions

View File

@ -0,0 +1,83 @@
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { uiConfig } from "@goauthentik/common/ui/config";
import { getRelativeTime } from "@goauthentik/common/utils";
import "@goauthentik/elements/forms/DeleteBulkForm";
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
import getUnicodeFlagIcon from "country-flag-icons/unicode";
import { msg } from "@lit/localize";
import { TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { PoliciesApi, Reputation } from "@goauthentik/api";
@customElement("ak-user-reputation-list")
export class UserReputationList extends Table<Reputation> {
@property()
targetUsername!: string;
@property()
targetEmail!: string | undefined;
async apiEndpoint(page: number): Promise<PaginatedResponse<Reputation>> {
const identifiers = [this.targetUsername];
if (this.targetEmail !== undefined) {
identifiers.push(this.targetEmail);
}
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresList({
identifierIn: identifiers,
ordering: this.order,
page: page,
pageSize: (await uiConfig()).pagination.perPage,
});
}
checkbox = true;
clearOnRefresh = true;
order = "identifier";
columns(): TableColumn[] {
return [
new TableColumn(msg("Identifier"), "identifier"),
new TableColumn(msg("IP"), "ip"),
new TableColumn(msg("Score"), "score"),
new TableColumn(msg("Updated"), "updated"),
];
}
renderToolbarSelected(): TemplateResult {
const disabled = this.selectedElements.length < 1;
return html`<ak-forms-delete-bulk
objectLabel=${msg("Reputation score(s)")}
.objects=${this.selectedElements}
.usedBy=${(item: Reputation) => {
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresUsedByList({
reputationUuid: item.pk || "",
});
}}
.delete=${(item: Reputation) => {
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresDestroy({
reputationUuid: item.pk || "",
});
}}
>
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
${msg("Delete")}
</button>
</ak-forms-delete-bulk>`;
}
row(item: Reputation): TemplateResult[] {
return [
html`${item.identifier}`,
html`${item.ipGeoData?.country
? html` ${getUnicodeFlagIcon(item.ipGeoData.country)} `
: html``}
${item.ip}`,
html`${item.score}`,
html`<div>${getRelativeTime(item.updated)}</div>
<small>${item.updated.toLocaleString()}</small>`,
];
}
}