diff --git a/authentik/admin/urls.py b/authentik/admin/urls.py index e661165e4..683604bc6 100644 --- a/authentik/admin/urls.py +++ b/authentik/admin/urls.py @@ -172,10 +172,6 @@ urlpatterns = [ # Users path("users/create/", users.UserCreateView.as_view(), name="user-create"), path("users//update/", users.UserUpdateView.as_view(), name="user-update"), - path( - "users//disable/", users.UserDisableView.as_view(), name="user-disable" - ), - path("users//enable/", users.UserEnableView.as_view(), name="user-enable"), path( "users//reset/", users.UserPasswordResetView.as_view(), diff --git a/authentik/admin/views/users.py b/authentik/admin/views/users.py index 541842b79..7d6f60e78 100644 --- a/authentik/admin/views/users.py +++ b/authentik/admin/views/users.py @@ -6,7 +6,6 @@ from django.contrib.auth.mixins import ( ) from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpRequest, HttpResponse -from django.http.response import HttpResponseRedirect from django.shortcuts import redirect from django.urls import reverse_lazy from django.utils.http import urlencode @@ -15,7 +14,6 @@ from django.views.generic import DetailView, UpdateView from guardian.mixins import PermissionRequiredMixin from authentik.admin.forms.users import UserForm -from authentik.admin.views.utils import DeleteMessageView from authentik.core.models import Token, User from authentik.lib.views import CreateAssignPermView @@ -56,48 +54,6 @@ class UserUpdateView( 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): """Get Password reset link for user""" diff --git a/authentik/core/urls.py b/authentik/core/urls.py index 637cd8c1b..bdf339319 100644 --- a/authentik/core/urls.py +++ b/authentik/core/urls.py @@ -17,11 +17,6 @@ urlpatterns = [ user.TokenUpdateView.as_view(), name="user-tokens-update", ), - path( - "-/user/tokens//delete/", - user.TokenDeleteView.as_view(), - name="user-tokens-delete", - ), # Impersonation path( "-/impersonation//", diff --git a/authentik/core/views/user.py b/authentik/core/views/user.py index 60286f2cb..6d630e922 100644 --- a/authentik/core/views/user.py +++ b/authentik/core/views/user.py @@ -14,7 +14,6 @@ from django.views.generic.base import TemplateView from guardian.mixins import PermissionRequiredMixin 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.users import UserDetailForm from authentik.core.models import Token, TokenIntents @@ -92,23 +91,3 @@ class TokenUpdateView( .filter(intent=TokenIntents.INTENT_API, identifier=identifier) .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() - ) diff --git a/web/src/elements/forms/DeleteForm.ts b/web/src/elements/forms/DeleteForm.ts index b54fe694d..93060b630 100644 --- a/web/src/elements/forms/DeleteForm.ts +++ b/web/src/elements/forms/DeleteForm.ts @@ -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", }); } diff --git a/web/src/pages/users/UserActiveForm.ts b/web/src/pages/users/UserActiveForm.ts new file mode 100644 index 000000000..ed7aa7b4d --- /dev/null +++ b/web/src/pages/users/UserActiveForm.ts @@ -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`
+
+

+ ${gettext(`Update ${this.objectLabel}`)} +

+
+
+
+
+
+
+
+
+

+ ${gettext( + `Are you sure you want to update ${this.objectLabel} '${this.obj?.name}'?` + )} +

+
+
+
+
+
+
+
+ { + this.confirm(); + }} + class="pf-m-warning"> + ${gettext("Update")} +   + { + this.open = false; + }} + class="pf-m-secondary"> + ${gettext("Cancel")} + +
`; + } + +} diff --git a/web/src/pages/users/UserListPage.ts b/web/src/pages/users/UserListPage.ts index 99373419c..98379ec09 100644 --- a/web/src/pages/users/UserListPage.ts +++ b/web/src/pages/users/UserListPage.ts @@ -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 { @@ -71,19 +72,23 @@ export class UserListPage extends TablePage {