mirror of
https://github.com/goauthentik/authentik
synced 2026-04-25 17:15:26 +02:00
* web/admin: allow creating only binding for policies Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dont show type selector if only one is allowed Signed-off-by: Jens Langhammer <jens@goauthentik.io> * do the same for stage wizard Signed-off-by: Jens Langhammer <jens@goauthentik.io> * minor unrelated fix: alignment in table desc Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add option to bind existing policy Signed-off-by: Jens Langhammer <jens@goauthentik.io> * adjust labels? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Clean up post-type select state. Types. * Clean up brand form. * Flesh out parse. * Tidy textarea. * Fix table alignment when images are present. * Simplify radio. * Fix form group layout, styles. * Flesh out plural helper. * Flesh out formatted user display name. * Allow slotted HTML in page description. * Clean up transclusion types. * Allow null. * Flesh out user activation toggle. * Clean up activation labeling. --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Teffen Ellis <592134+GirlBossRush@users.noreply.github.com>
145 lines
5.1 KiB
TypeScript
145 lines
5.1 KiB
TypeScript
import "#elements/buttons/SpinnerButton/index";
|
|
import "#elements/entities/UsedByTable";
|
|
|
|
import { EVENT_REFRESH } from "#common/constants";
|
|
import { parseAPIResponseError, pluckErrorDetail } from "#common/errors/network";
|
|
import { MessageLevel } from "#common/messages";
|
|
|
|
import { ModalButton } from "#elements/buttons/ModalButton";
|
|
import { BulkDeleteMetadata } from "#elements/entities/UsedByTable";
|
|
import { showMessage } from "#elements/messages/MessageContainer";
|
|
|
|
import { UsedBy } from "@goauthentik/api";
|
|
|
|
import { msg, str } from "@lit/localize";
|
|
import { html, TemplateResult } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
@customElement("ak-forms-delete-bulk")
|
|
export class DeleteBulkForm<T> extends ModalButton {
|
|
@property({ attribute: false })
|
|
public objects: T[] = [];
|
|
|
|
@property({ type: String, attribute: "object-label" })
|
|
public objectLabel: string | null = null;
|
|
|
|
@property({ type: String, attribute: "submit-label" })
|
|
public submitLabel: string | null = null;
|
|
|
|
@property({ type: String, attribute: "action-subtext" })
|
|
public actionSubtext: string | null = null;
|
|
|
|
@property({ type: String, attribute: "button-label" })
|
|
public buttonLabel = msg("Delete");
|
|
|
|
/**
|
|
* Action shown in messages, for example `deleted` or `removed`
|
|
*/
|
|
@property({ type: String })
|
|
public action = msg("deleted");
|
|
|
|
@property({ attribute: false })
|
|
public metadata: (item: T) => BulkDeleteMetadata[] = (item: T) => {
|
|
const rec = item as Record<string, unknown>;
|
|
const meta: BulkDeleteMetadata[] = [];
|
|
|
|
if (Object.hasOwn(rec, "name")) {
|
|
meta.push({ key: msg("Name"), value: rec.name as string });
|
|
}
|
|
|
|
if (Object.hasOwn(rec, "pk")) {
|
|
meta.push({ key: msg("ID"), value: rec.pk as string });
|
|
}
|
|
|
|
return meta;
|
|
};
|
|
|
|
@property({ attribute: false })
|
|
public usedBy?: (item: T) => Promise<UsedBy[]>;
|
|
|
|
@property({ attribute: false })
|
|
public delete!: (item: T) => Promise<unknown>;
|
|
|
|
protected async confirm(): Promise<void> {
|
|
return Promise.all(this.objects.map((item) => this.delete(item)))
|
|
.then(() => {
|
|
showMessage({
|
|
message: msg(
|
|
str`Successfully deleted ${this.objects.length} ${this.objectLabel}`,
|
|
),
|
|
level: MessageLevel.success,
|
|
});
|
|
|
|
this.dispatchEvent(
|
|
new CustomEvent(EVENT_REFRESH, {
|
|
bubbles: true,
|
|
composed: true,
|
|
}),
|
|
);
|
|
this.open = false;
|
|
})
|
|
.catch((parsedError: unknown) => {
|
|
return parseAPIResponseError(parsedError).then(() => {
|
|
showMessage({
|
|
message: msg(str`Failed to delete ${this.objectLabel}`),
|
|
description: pluckErrorDetail(parsedError),
|
|
level: MessageLevel.error,
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
renderModalInner(): TemplateResult {
|
|
return html`<section class="pf-c-modal-box__header pf-c-page__main-section pf-m-light">
|
|
<div class="pf-c-content">
|
|
<h1 class="pf-c-title pf-m-2xl">
|
|
${this.submitLabel
|
|
? this.submitLabel
|
|
: msg(str`Delete ${this.objectLabel}`)}
|
|
</h1>
|
|
</div>
|
|
</section>
|
|
<section class="pf-c-modal-box__body pf-m-light">
|
|
<form class="pf-c-form pf-m-horizontal">
|
|
<p class="pf-c-title">
|
|
${this.actionSubtext
|
|
? this.actionSubtext
|
|
: msg(
|
|
str`Are you sure you want to delete ${this.objects.length} ${this.objectLabel}?`,
|
|
)}
|
|
</p>
|
|
<slot name="notice"></slot>
|
|
</form>
|
|
</section>
|
|
<section class="pf-c-modal-box__body pf-m-light">
|
|
<ak-used-by-table
|
|
.items=${this.objects}
|
|
.usedBy=${this.usedBy}
|
|
.metadata=${this.metadata}
|
|
>
|
|
</ak-used-by-table>
|
|
</section>
|
|
<fieldset class="pf-c-modal-box__footer">
|
|
<legend class="sr-only">${msg("Form actions")}</legend>
|
|
<ak-spinner-button
|
|
.callAction=${async () => {
|
|
this.open = false;
|
|
}}
|
|
class="pf-m-plain"
|
|
>
|
|
${msg("Cancel")}
|
|
</ak-spinner-button>
|
|
|
|
<ak-spinner-button .callAction=${() => this.confirm()} class="pf-m-danger">
|
|
${this.buttonLabel}
|
|
</ak-spinner-button>
|
|
</fieldset>`;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
"ak-forms-delete-bulk": DeleteBulkForm<object>;
|
|
}
|
|
}
|