admin: remove user enable/disable views
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -17,10 +17,7 @@ export class DeleteForm extends ModalButton {
|
||||
|
||||
confirm(): void {
|
||||
this.delete().then(() => {
|
||||
showMessage({
|
||||
message: gettext(`Successfully deleted ${this.objectLabel} ${this.obj?.name}`),
|
||||
level_tag: "success",
|
||||
});
|
||||
this.onSuccess();
|
||||
this.open = false;
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("ak-refresh", {
|
||||
@ -29,10 +26,21 @@ export class DeleteForm extends ModalButton {
|
||||
})
|
||||
);
|
||||
}).catch((e) => {
|
||||
showMessage({
|
||||
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
|
||||
level_tag: "error",
|
||||
});
|
||||
this.onError(e);
|
||||
});
|
||||
}
|
||||
|
||||
onSuccess(): void {
|
||||
showMessage({
|
||||
message: gettext(`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`),
|
||||
level_tag: "success",
|
||||
});
|
||||
}
|
||||
|
||||
onError(e: Error): void {
|
||||
showMessage({
|
||||
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
|
||||
level_tag: "error",
|
||||
});
|
||||
}
|
||||
|
||||
|
66
web/src/pages/users/UserActiveForm.ts
Normal file
66
web/src/pages/users/UserActiveForm.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { gettext } from "django";
|
||||
import { customElement, html, TemplateResult } from "lit-element";
|
||||
import { DeleteForm } from "../../elements/forms/DeleteForm";
|
||||
import { showMessage } from "../../elements/messages/MessageContainer";
|
||||
|
||||
@customElement("ak-user-active-form")
|
||||
export class UserActiveForm extends DeleteForm {
|
||||
|
||||
onSuccess(): void {
|
||||
showMessage({
|
||||
message: gettext(`Successfully updated ${this.objectLabel} ${this.obj?.name}`),
|
||||
level_tag: "success",
|
||||
});
|
||||
}
|
||||
|
||||
onError(e: Error): void {
|
||||
showMessage({
|
||||
message: gettext(`Failed to update ${this.objectLabel}: ${e.toString()}`),
|
||||
level_tag: "error",
|
||||
});
|
||||
}
|
||||
|
||||
renderModalInner(): TemplateResult {
|
||||
return html`<section class="pf-c-page__main-section pf-m-light">
|
||||
<div class="pf-c-content">
|
||||
<h1 class="pf-c-title pf-m-2xl">
|
||||
${gettext(`Update ${this.objectLabel}`)}
|
||||
</h1>
|
||||
</div>
|
||||
</section>
|
||||
<section class="pf-c-page__main-section">
|
||||
<div class="pf-l-stack">
|
||||
<div class="pf-l-stack__item">
|
||||
<div class="pf-c-card">
|
||||
<div class="pf-c-card__body">
|
||||
<form class="pf-c-form pf-m-horizontal">
|
||||
<p>
|
||||
${gettext(
|
||||
`Are you sure you want to update ${this.objectLabel} '${this.obj?.name}'?`
|
||||
)}
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="pf-c-modal-box__footer">
|
||||
<ak-spinner-button
|
||||
.callAction=${() => {
|
||||
this.confirm();
|
||||
}}
|
||||
class="pf-m-warning">
|
||||
${gettext("Update")}
|
||||
</ak-spinner-button>
|
||||
<ak-spinner-button
|
||||
.callAction=${() => {
|
||||
this.open = false;
|
||||
}}
|
||||
class="pf-m-secondary">
|
||||
${gettext("Cancel")}
|
||||
</ak-spinner-button>
|
||||
</footer>`;
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import { CoreApi, User } from "authentik-api";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { AdminURLManager } from "../../api/legacy";
|
||||
import "../../elements/forms/DeleteForm";
|
||||
import "./UserActiveForm";
|
||||
|
||||
@customElement("ak-user-list")
|
||||
export class UserListPage extends TablePage<User> {
|
||||
@ -71,19 +72,23 @@ export class UserListPage extends TablePage<User> {
|
||||
</button>
|
||||
<ul class="pf-c-dropdown__menu" hidden>
|
||||
<li>
|
||||
${item.isActive ?
|
||||
html`<ak-modal-button href="${AdminURLManager.users(`${item.pk}/disable/`)}">
|
||||
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
||||
${gettext("Disable")}
|
||||
</button>
|
||||
<div slot="modal"></div>
|
||||
</ak-modal-button>`:
|
||||
html`<ak-modal-button href="${AdminURLManager.users(`${item.pk}/enable/`)}">
|
||||
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
||||
${gettext("Enable")}
|
||||
</button>
|
||||
<div slot="modal"></div>
|
||||
</ak-modal-button>`}
|
||||
<ak-user-active-form
|
||||
.obj=${item}
|
||||
objectLabel=${gettext("User")}
|
||||
.delete=${() => {
|
||||
return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({
|
||||
id: item.pk || 0,
|
||||
data: {
|
||||
username: item.username,
|
||||
name: item.name,
|
||||
isActive: !item.isActive,
|
||||
}
|
||||
});
|
||||
}}>
|
||||
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
||||
${item.isActive ? gettext("Disable") : gettext("Enable")}
|
||||
</button>
|
||||
</ak-user-active-form>
|
||||
</li>
|
||||
<li class="pf-c-divider" role="separator"></li>
|
||||
<li>
|
||||
@ -95,7 +100,7 @@ export class UserListPage extends TablePage<User> {
|
||||
id: item.pk || 0
|
||||
});
|
||||
}}>
|
||||
<button slot="trigger" class="pf-c-button pf-m-danger">
|
||||
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
||||
${gettext("Delete")}
|
||||
</button>
|
||||
</ak-forms-delete>
|
||||
|
Reference in New Issue
Block a user