From f0e661412aadf8234d4dc0b3cb0596aeb1de8aee Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 30 Nov 2023 13:03:47 +0100 Subject: [PATCH] Import sudo function from correct module --- python/nav/web/useradmin/views.py | 3 +-- tests/integration/web/useradmin_test.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/integration/web/useradmin_test.py diff --git a/python/nav/web/useradmin/views.py b/python/nav/web/useradmin/views.py index 1f18dc5266..bb9b63fcf7 100644 --- a/python/nav/web/useradmin/views.py +++ b/python/nav/web/useradmin/views.py @@ -31,7 +31,7 @@ from nav.models.manage import Organization from nav.models.api import APIToken -from nav.web.auth import sudo +from nav.web.auth.sudo import sudo from nav.web.useradmin import forms @@ -396,7 +396,6 @@ def group_detail(request, group_id=None): privilege_form = forms.PrivilegeForm() if request.method == 'POST': - if 'submit_group' in request.POST: group_form = forms.AccountGroupForm(request.POST, instance=group) diff --git a/tests/integration/web/useradmin_test.py b/tests/integration/web/useradmin_test.py new file mode 100644 index 0000000000..4fa8c4a75f --- /dev/null +++ b/tests/integration/web/useradmin_test.py @@ -0,0 +1,15 @@ +from django.urls import reverse + + +def test_operate_as_this_user_should_not_crash(db, client, admin_account): + url = reverse('useradmin-account_detail', args=(admin_account.pk,)) + response = client.post( + url, + follow=True, + data={ + "account": admin_account.pk, + "submit_sudo": "Operate+as+this+user", + }, + ) + + assert response.status_code == 200