Repository: ephios-dev/ephios

Issue:
Nutzer löschen
Als Manager möchte ich einen Nutzer löschen können. Dafür soll es in der Liste der Nutzer sowie auf der Bearbeitungsseite eines Nutzers eine entsprechende Schaltfläche geben.


Discussion:

Resolving patch:
diff --git a/ephios/user_management/forms.py b/ephios/user_management/forms.py
--- a/ephios/user_management/forms.py
+++ b/ephios/user_management/forms.py
@@ -149,6 +149,8 @@ def save(self, commit=True):
             for target_group in Group.objects.all():
                 remove_perm("publish_event_for_group", group, target_group)
 
+        return group
+
 
 class UserProfileForm(ModelForm):
     groups = ModelMultipleChoiceField(
diff --git a/ephios/user_management/urls.py b/ephios/user_management/urls.py
--- a/ephios/user_management/urls.py
+++ b/ephios/user_management/urls.py
@@ -19,6 +19,11 @@
         views.UserProfileUpdateView.as_view(),
         name="userprofile_edit",
     ),
+    path(
+        "users/<int:pk>/delete",
+        views.UserProfileDeleteView.as_view(),
+        name="userprofile_delete",
+    ),
     path(
         "users/create/",
         views.UserProfileCreateView.as_view(),
diff --git a/ephios/user_management/views.py b/ephios/user_management/views.py
--- a/ephios/user_management/views.py
+++ b/ephios/user_management/views.py
@@ -49,7 +49,12 @@ def post(self, request, *args, **kwargs):
             userprofile = userprofile_form.save()
             qualification_formset.instance = userprofile
             qualification_formset.save()
-            messages.success(self.request, _("User added successfully."))
+            messages.success(
+                self.request,
+                _("User {name} ({user}) added successfully.").format(
+                    name=userprofile.get_full_name(), user=userprofile
+                ),
+            )
             if userprofile.is_active:
                 mail.send_account_creation_info(userprofile)
             return redirect(reverse("user_management:userprofile_list"))
@@ -91,7 +96,12 @@ def post(self, request, *args, **kwargs):
         if all((userprofile_form.is_valid(), qualification_formset.is_valid())):
             userprofile = userprofile_form.save()
             qualification_formset.save()
-            messages.success(self.request, _("User updated successfully."))
+            messages.success(
+                self.request,
+                _("User {name} ({user}) updated successfully.").format(
+                    name=self.object.get_full_name(), user=self.object
+                ),
+            )
             if userprofile.is_active:
                 mail.send_account_update_info(userprofile)
             return redirect(reverse("user_management:userprofile_list"))
@@ -103,6 +113,21 @@ def post(self, request, *args, **kwargs):
             )
 
 
+class UserProfileDeleteView(PermissionRequiredMixin, DeleteView):
+    model = UserProfile
+    permission_required = "user_management.delete_userprofile"
+    template_name = "user_management/userprofile_confirm_delete.html"
+
+    def get_success_url(self):
+        messages.info(
+            self.request,
+            _("The user {name} ({user}) was deleted.").format(
+                name=self.object.get_full_name(), user=self.object
+            ),
+        )
+        return reverse("user_management:userprofile_list")
+
+
 class GroupListView(PermissionRequiredMixin, ListView):
     model = Group
     permission_required = "auth.view_group"
@@ -125,7 +150,9 @@ def get_form_kwargs(self):
         return kwargs
 
     def get_success_url(self):
-        messages.success(self.request, _("Group created successfully."))
+        messages.success(
+            self.request, _('Group "{group}" created successfully.').format(group=self.object)
+        )
         return reverse("user_management:group_list")
 
 
@@ -150,7 +177,9 @@ def get_form_kwargs(self):
         return kwargs
 
     def get_success_url(self):
-        messages.success(self.request, _("Group updated successfully."))
+        messages.success(
+            self.request, _('Group "{group}" updated successfully.').format(group=self.object)
+        )
         return reverse("user_management:group_list")
 
 
@@ -160,4 +189,5 @@ class GroupDeleteView(PermissionRequiredMixin, DeleteView):
     template_name = "user_management/group_confirm_delete.html"
 
     def get_success_url(self):
+        messages.info(self.request, _('The group "{group}" was deleted.').format(group=self.object))
         return reverse("user_management:group_list")


Test patch: