manager: record then execute user deletion (#51671)
This commit is contained in:
parent
898105f7ed
commit
534df33bbd
|
@ -19,7 +19,7 @@ import datetime
|
|||
import collections
|
||||
import operator
|
||||
|
||||
from django.db import models
|
||||
from django.db import models, transaction
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _, pgettext_lazy, ugettext
|
||||
from django.utils.html import format_html
|
||||
|
@ -707,11 +707,12 @@ class UserDeleteView(BaseDeleteView):
|
|||
template_name = 'authentic2/manager/user_delete.html'
|
||||
success_url = reverse_lazy('a2-manager-users')
|
||||
|
||||
@transaction.atomic
|
||||
def delete(self, request, *args, **kwargs):
|
||||
request.journal.record('manager.user.deletion', target_user=self.object)
|
||||
response = super().delete(request, *args, **kwargs)
|
||||
hooks.call_hooks('event', name='manager-delete-user', user=request.user,
|
||||
instance=self.object)
|
||||
request.journal.record('manager.user.deletion', target_user=self.object)
|
||||
return response
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ from authentic2.a2_rbac.utils import get_default_ou
|
|||
from authentic2.a2_rbac.utils import get_view_user_perm
|
||||
from authentic2.manager import user_import
|
||||
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
|
||||
from authentic2.apps.journal.models import Event
|
||||
|
||||
|
||||
from .utils import login, get_link_from_mail, logout
|
||||
|
@ -1125,3 +1126,19 @@ def test_manager_create_user_duplicates(admin, app, ou1, settings):
|
|||
# Not a duplicate this time. Simply submitting again creates user
|
||||
resp = resp.form.submit().follow()
|
||||
assert User.objects.filter(first_name='Alexa').count() == 1
|
||||
|
||||
|
||||
def test_delete_user(app, superuser, simple_user):
|
||||
assert User.objects.count() == 2
|
||||
assert Event.objects.filter(user=simple_user, type__name='manager.user.deletion').count() == 0
|
||||
|
||||
response = login(app, superuser, '/manage/users/')
|
||||
response = response.click('Jôhn Dôe')
|
||||
response = response.click('Delete')
|
||||
response = response.form.submit(value='Delete')
|
||||
|
||||
assert User.objects.count() == 1
|
||||
assert (
|
||||
Event.objects.filter(user=superuser, type__name='manager.user.deletion')
|
||||
.which_references(simple_user).count() == 1
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue