From 2612c818770edb273a4494d1f49bb9ec1e3e1fba Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Mon, 2 May 2022 10:41:17 +0200 Subject: [PATCH] Set HIJACK_ENABLE to true in test.py settings. Readd conditional add of become path. --- hypha/apply/users/tests/test_views.py | 2 +- hypha/apply/users/urls.py | 7 ++++++- hypha/apply/users/views.py | 2 +- hypha/settings/test.py | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hypha/apply/users/tests/test_views.py b/hypha/apply/users/tests/test_views.py index 190ee006d..52f70dbc6 100644 --- a/hypha/apply/users/tests/test_views.py +++ b/hypha/apply/users/tests/test_views.py @@ -61,7 +61,7 @@ class TestPasswordReset(BaseViewTestCase): self.assertIn('https://testserver/account/password/reset/confirm', mail.outbox[0].body) -@override_settings(ROOT_URLCONF='hypha.apply.urls', HIJACK_ENABLE=True) +@override_settings(ROOT_URLCONF='hypha.apply.urls') class TestBecome(TestCase): def setUp(self): self.staff = StaffFactory() diff --git a/hypha/apply/users/urls.py b/hypha/apply/users/urls.py index 94bc9bb2f..53273023e 100644 --- a/hypha/apply/users/urls.py +++ b/hypha/apply/users/urls.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib.auth import views as auth_views from django.urls import include, path, reverse_lazy @@ -37,7 +38,6 @@ public_urlpatterns = [ urlpatterns = [ path('account/', include([ path('', AccountView.as_view(), name='account'), - path('become/', become, name='become'), path('password/', include([ path('', EmailChangePasswordView.as_view(), name='email_change_confirm_password'), path( @@ -94,3 +94,8 @@ urlpatterns = [ path('oauth', oauth, name='oauth'), ])), ] + +if settings.HIJACK_ENABLE: + urlpatterns += [ + path('account/become/', become, name='become'), + ] diff --git a/hypha/apply/users/views.py b/hypha/apply/users/views.py index d8e85fa04..1cf30f527 100644 --- a/hypha/apply/users/views.py +++ b/hypha/apply/users/views.py @@ -160,7 +160,7 @@ class EmailChangeDoneView(TemplateView): @login_required() def become(request): if not settings.HIJACK_ENABLE: - raise PermissionDenied() + raise Http404(_('Hijack feature is not enabled.')) if not request.user.is_superuser: raise PermissionDenied() diff --git a/hypha/settings/test.py b/hypha/settings/test.py index 1d913795a..e4936bbfb 100644 --- a/hypha/settings/test.py +++ b/hypha/settings/test.py @@ -9,6 +9,8 @@ logging.disable(logging.CRITICAL) SECRET_KEY = 'NOT A SECRET' +HIJACK_ENABLE = True + PROJECTS_ENABLED = True PROJECTS_AUTO_CREATE = True -- GitLab