admin: remove user enable/disable views
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
db9aa5d9dc
commit
93bd95436f
|
@ -172,10 +172,6 @@ urlpatterns = [
|
||||||
# Users
|
# Users
|
||||||
path("users/create/", users.UserCreateView.as_view(), name="user-create"),
|
path("users/create/", users.UserCreateView.as_view(), name="user-create"),
|
||||||
path("users/<int:pk>/update/", users.UserUpdateView.as_view(), name="user-update"),
|
path("users/<int:pk>/update/", users.UserUpdateView.as_view(), name="user-update"),
|
||||||
path(
|
|
||||||
"users/<int:pk>/disable/", users.UserDisableView.as_view(), name="user-disable"
|
|
||||||
),
|
|
||||||
path("users/<int:pk>/enable/", users.UserEnableView.as_view(), name="user-enable"),
|
|
||||||
path(
|
path(
|
||||||
"users/<int:pk>/reset/",
|
"users/<int:pk>/reset/",
|
||||||
users.UserPasswordResetView.as_view(),
|
users.UserPasswordResetView.as_view(),
|
||||||
|
|
|
@ -6,7 +6,6 @@ from django.contrib.auth.mixins import (
|
||||||
)
|
)
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.http.response import HttpResponseRedirect
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
|
@ -15,7 +14,6 @@ from django.views.generic import DetailView, UpdateView
|
||||||
from guardian.mixins import PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
|
|
||||||
from authentik.admin.forms.users import UserForm
|
from authentik.admin.forms.users import UserForm
|
||||||
from authentik.admin.views.utils import DeleteMessageView
|
|
||||||
from authentik.core.models import Token, User
|
from authentik.core.models import Token, User
|
||||||
from authentik.lib.views import CreateAssignPermView
|
from authentik.lib.views import CreateAssignPermView
|
||||||
|
|
||||||
|
@ -56,48 +54,6 @@ class UserUpdateView(
|
||||||
success_message = _("Successfully updated User")
|
success_message = _("Successfully updated User")
|
||||||
|
|
||||||
|
|
||||||
class UserDisableView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView):
|
|
||||||
"""Disable user"""
|
|
||||||
|
|
||||||
object: User
|
|
||||||
|
|
||||||
model = User
|
|
||||||
permission_required = "authentik_core.update_user"
|
|
||||||
|
|
||||||
# By default the object's name is user which is used by other checks
|
|
||||||
context_object_name = "object"
|
|
||||||
template_name = "administration/user/disable.html"
|
|
||||||
success_url = reverse_lazy("authentik_core:shell")
|
|
||||||
success_message = _("Successfully disabled User")
|
|
||||||
|
|
||||||
def delete(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
|
||||||
self.object: User = self.get_object()
|
|
||||||
success_url = self.get_success_url()
|
|
||||||
self.object.is_active = False
|
|
||||||
self.object.save()
|
|
||||||
return HttpResponseRedirect(success_url)
|
|
||||||
|
|
||||||
|
|
||||||
class UserEnableView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
|
||||||
"""Enable user"""
|
|
||||||
|
|
||||||
object: User
|
|
||||||
|
|
||||||
model = User
|
|
||||||
permission_required = "authentik_core.update_user"
|
|
||||||
|
|
||||||
# By default the object's name is user which is used by other checks
|
|
||||||
context_object_name = "object"
|
|
||||||
success_url = reverse_lazy("authentik_core:shell")
|
|
||||||
success_message = _("Successfully enabled User")
|
|
||||||
|
|
||||||
def get(self, request: HttpRequest, *args, **kwargs):
|
|
||||||
self.object: User = self.get_object()
|
|
||||||
self.object.is_active = True
|
|
||||||
self.object.save()
|
|
||||||
return HttpResponseRedirect(self.success_url)
|
|
||||||
|
|
||||||
|
|
||||||
class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
||||||
"""Get Password reset link for user"""
|
"""Get Password reset link for user"""
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,6 @@ urlpatterns = [
|
||||||
user.TokenUpdateView.as_view(),
|
user.TokenUpdateView.as_view(),
|
||||||
name="user-tokens-update",
|
name="user-tokens-update",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"-/user/tokens/<slug:identifier>/delete/",
|
|
||||||
user.TokenDeleteView.as_view(),
|
|
||||||
name="user-tokens-delete",
|
|
||||||
),
|
|
||||||
# Impersonation
|
# Impersonation
|
||||||
path(
|
path(
|
||||||
"-/impersonation/<int:user_id>/",
|
"-/impersonation/<int:user_id>/",
|
||||||
|
|
|
@ -14,7 +14,6 @@ from django.views.generic.base import TemplateView
|
||||||
from guardian.mixins import PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
|
|
||||||
from authentik.admin.views.utils import DeleteMessageView
|
|
||||||
from authentik.core.forms.token import UserTokenForm
|
from authentik.core.forms.token import UserTokenForm
|
||||||
from authentik.core.forms.users import UserDetailForm
|
from authentik.core.forms.users import UserDetailForm
|
||||||
from authentik.core.models import Token, TokenIntents
|
from authentik.core.models import Token, TokenIntents
|
||||||
|
@ -92,23 +91,3 @@ class TokenUpdateView(
|
||||||
.filter(intent=TokenIntents.INTENT_API, identifier=identifier)
|
.filter(intent=TokenIntents.INTENT_API, identifier=identifier)
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TokenDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView):
|
|
||||||
"""Delete token"""
|
|
||||||
|
|
||||||
model = Token
|
|
||||||
permission_required = "authentik_core.delete_token"
|
|
||||||
template_name = "generic/delete.html"
|
|
||||||
success_url = "/"
|
|
||||||
success_message = _("Successfully deleted Token")
|
|
||||||
|
|
||||||
def get_object(self) -> Token:
|
|
||||||
identifier = self.kwargs.get("identifier")
|
|
||||||
return (
|
|
||||||
get_objects_for_user(
|
|
||||||
self.request.user, self.permission_required, self.model
|
|
||||||
)
|
|
||||||
.filter(intent=TokenIntents.INTENT_API, identifier=identifier)
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
|
|
|
@ -17,10 +17,7 @@ export class DeleteForm extends ModalButton {
|
||||||
|
|
||||||
confirm(): void {
|
confirm(): void {
|
||||||
this.delete().then(() => {
|
this.delete().then(() => {
|
||||||
showMessage({
|
this.onSuccess();
|
||||||
message: gettext(`Successfully deleted ${this.objectLabel} ${this.obj?.name}`),
|
|
||||||
level_tag: "success",
|
|
||||||
});
|
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent("ak-refresh", {
|
new CustomEvent("ak-refresh", {
|
||||||
|
@ -29,11 +26,22 @@ export class DeleteForm extends ModalButton {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
|
this.onError(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSuccess(): void {
|
||||||
|
showMessage({
|
||||||
|
message: gettext(`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`),
|
||||||
|
level_tag: "success",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onError(e: Error): void {
|
||||||
showMessage({
|
showMessage({
|
||||||
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
|
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
|
||||||
level_tag: "error",
|
level_tag: "error",
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderModalInner(): TemplateResult {
|
renderModalInner(): TemplateResult {
|
||||||
|
|
|
@ -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 { DEFAULT_CONFIG } from "../../api/Config";
|
||||||
import { AdminURLManager } from "../../api/legacy";
|
import { AdminURLManager } from "../../api/legacy";
|
||||||
import "../../elements/forms/DeleteForm";
|
import "../../elements/forms/DeleteForm";
|
||||||
|
import "./UserActiveForm";
|
||||||
|
|
||||||
@customElement("ak-user-list")
|
@customElement("ak-user-list")
|
||||||
export class UserListPage extends TablePage<User> {
|
export class UserListPage extends TablePage<User> {
|
||||||
|
@ -71,19 +72,23 @@ export class UserListPage extends TablePage<User> {
|
||||||
</button>
|
</button>
|
||||||
<ul class="pf-c-dropdown__menu" hidden>
|
<ul class="pf-c-dropdown__menu" hidden>
|
||||||
<li>
|
<li>
|
||||||
${item.isActive ?
|
<ak-user-active-form
|
||||||
html`<ak-modal-button href="${AdminURLManager.users(`${item.pk}/disable/`)}">
|
.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">
|
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
||||||
${gettext("Disable")}
|
${item.isActive ? gettext("Disable") : gettext("Enable")}
|
||||||
</button>
|
</button>
|
||||||
<div slot="modal"></div>
|
</ak-user-active-form>
|
||||||
</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>`}
|
|
||||||
</li>
|
</li>
|
||||||
<li class="pf-c-divider" role="separator"></li>
|
<li class="pf-c-divider" role="separator"></li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -95,7 +100,7 @@ export class UserListPage extends TablePage<User> {
|
||||||
id: item.pk || 0
|
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")}
|
${gettext("Delete")}
|
||||||
</button>
|
</button>
|
||||||
</ak-forms-delete>
|
</ak-forms-delete>
|
||||||
|
|
Reference in New Issue