2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:19:26 +00:00
|
|
|
import { html, TemplateResult } from "lit";
|
|
|
|
import { customElement, property } from "lit/decorators";
|
2021-03-20 15:37:31 +00:00
|
|
|
import { AKResponse } from "../../api/Client";
|
|
|
|
import { Table, TableColumn } from "../table/Table";
|
|
|
|
|
2021-08-12 20:03:13 +00:00
|
|
|
import "../forms/DeleteBulkForm";
|
2021-03-20 15:37:31 +00:00
|
|
|
import { PAGE_SIZE } from "../../constants";
|
2021-08-15 19:32:28 +00:00
|
|
|
import { CoreApi, UserConsent } from "@goauthentik/api";
|
2021-03-20 15:37:31 +00:00
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
|
|
|
|
@customElement("ak-user-consent-list")
|
|
|
|
export class UserConsentList extends Table<UserConsent> {
|
2021-05-16 16:52:27 +00:00
|
|
|
@property({ type: Number })
|
2021-05-16 16:09:53 +00:00
|
|
|
userId?: number;
|
2021-03-20 15:37:31 +00:00
|
|
|
|
|
|
|
apiEndpoint(page: number): Promise<AKResponse<UserConsent>> {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUserConsentList({
|
|
|
|
user: this.userId,
|
2021-05-29 23:02:20 +00:00
|
|
|
ordering: this.order,
|
2021-03-20 15:37:31 +00:00
|
|
|
page: page,
|
|
|
|
pageSize: PAGE_SIZE,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
checkbox = true;
|
2021-03-20 15:37:31 +00:00
|
|
|
order = "-expires";
|
|
|
|
|
|
|
|
columns(): TableColumn[] {
|
|
|
|
return [
|
2021-04-04 14:56:16 +00:00
|
|
|
new TableColumn(t`Application`, "application"),
|
|
|
|
new TableColumn(t`Expires`, "expires"),
|
2021-03-20 15:37:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
renderToolbarSelected(): TemplateResult {
|
2021-08-12 20:03:13 +00:00
|
|
|
const disabled = this.selectedElements.length < 1;
|
|
|
|
return html`<ak-forms-delete-bulk
|
|
|
|
objectLabel=${t`Consent(s)`}
|
|
|
|
.objects=${this.selectedElements}
|
|
|
|
.usedBy=${(item: UserConsent) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUserConsentUsedByList({
|
|
|
|
id: item.pk,
|
|
|
|
});
|
|
|
|
}}
|
2021-08-12 20:03:13 +00:00
|
|
|
.delete=${(item: UserConsent) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUserConsentDestroy({
|
|
|
|
id: item.pk,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
2021-08-12 20:03:13 +00:00
|
|
|
${t`Delete`}
|
2021-08-05 10:30:43 +00:00
|
|
|
</button>
|
2021-08-12 20:03:13 +00:00
|
|
|
</ak-forms-delete-bulk>`;
|
2021-08-05 10:30:43 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 15:37:31 +00:00
|
|
|
row(item: UserConsent): TemplateResult[] {
|
2021-08-05 10:30:43 +00:00
|
|
|
return [html`${item.application.name}`, html`${item.expires?.toLocaleString()}`];
|
2021-03-20 15:37:31 +00:00
|
|
|
}
|
|
|
|
}
|