From 8f0485720c3167b8c280a3991d620e677d28cb33 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 21 Apr 2020 15:42:59 +0200 Subject: [PATCH 1/4] Use path in main site urls. refs: #9 --- nm2/urls.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/nm2/urls.py b/nm2/urls.py index c7ffb0f..1bdc102 100644 --- a/nm2/urls.py +++ b/nm2/urls.py @@ -1,4 +1,4 @@ -from django.urls import include, path, re_path +from django.urls import include, path from django.views.generic import TemplateView from backend.mixins import VisitorTemplateView from django.conf import settings @@ -24,43 +24,43 @@ django.conf.urls.handler500 = nmviews.Error500.as_view() urlpatterns = [ path('robots.txt', TemplateView.as_view( template_name='robots.txt', content_type="text/plain"), name="root_robots_txt"), - re_path(r'^i18n/', include('django.conf.urls.i18n')), - re_path(r'^$', VisitorTemplateView.as_view(template_name='index.html'), name="home"), - re_path(r'^license/$', VisitorTemplateView.as_view(template_name='license.html'), name="root_license"), - re_path(r'^faq/$', VisitorTemplateView.as_view(template_name='faq.html'), name="root_faq"), - re_path(r'^members/$', public_views.Members.as_view(), name="members"), - re_path(r'^legacy/', include("legacy.urls")), - re_path(r'^person/', include("person.urls")), - re_path(r'^public/', include("public.urls")), - re_path(r'^am/', include("restricted.urls")), - re_path(r'^fprs/', include("fprs.urls")), - re_path(r'^process/', include("process.urls")), - re_path(r'^dm/', include("dm.urls")), - re_path(r'^api/', include("api.urls")), - re_path(r'^apikeys/', include("apikeys.urls")), - re_path(r'^keyring/', include("keyring.urls")), - re_path(r'^wizard/', include("wizard.urls")), - re_path(r'^mia/', include("mia.urls")), - re_path(r'^minechangelogs/', include("minechangelogs.urls")), - re_path(r'^sitechecks/', include("sitechecks.urls")), - re_path(r'^deploy/', include("deploy.urls")), + path('i18n/', include('django.conf.urls.i18n')), + path(r'', VisitorTemplateView.as_view(template_name='index.html'), name="home"), + path('license/', VisitorTemplateView.as_view(template_name='license.html'), name="root_license"), + path('faq/', VisitorTemplateView.as_view(template_name='faq.html'), name="root_faq"), + path('members/', public_views.Members.as_view(), name="members"), + path('legacy/', include("legacy.urls")), + path('person/', include("person.urls")), + path('public/', include("public.urls")), + path('am/', include("restricted.urls")), + path('fprs/', include("fprs.urls")), + path('process/', include("process.urls")), + path('dm/', include("dm.urls")), + path('api/', include("api.urls")), + path('apikeys/', include("apikeys.urls")), + path('keyring/', include("keyring.urls")), + path('wizard/', include("wizard.urls")), + path('mia/', include("mia.urls")), + path('minechangelogs/', include("minechangelogs.urls")), + path('sitechecks/', include("sitechecks.urls")), + path('deploy/', include("deploy.urls")), - re_path(r'^rest/api/', include(router.urls)), + path('rest/api/', include(router.urls)), - path(r'signon/', include("signon.urls")), + path('signon/', include("signon.urls")), # Uncomment the admin/doc line below to enable admin documentation: - re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), + path('admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: - re_path(r'^admin/', admin.site.urls), + path('admin/', admin.site.urls), ] if settings.DEBUG: try: import debug_toolbar urlpatterns += [ - re_path(r'^__debug__/', include(debug_toolbar.urls)), + path('__debug__/', include(debug_toolbar.urls)), ] except ImportError: pass -- GitLab From 1758473fb34946381424ff0afb1caf8f60d8a1c9 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 21 Apr 2020 15:43:11 +0200 Subject: [PATCH 2/4] Use path in wizard urls. refs: #9 --- wizard/urls.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wizard/urls.py b/wizard/urls.py index b3abc44..4b90318 100644 --- a/wizard/urls.py +++ b/wizard/urls.py @@ -1,9 +1,9 @@ -from django.conf.urls import url +from django.urls import path from backend.mixins import VisitorTemplateView from . import views urlpatterns = [ - url(r'^$', VisitorTemplateView.as_view(template_name="wizard/home.html"), name="wizard_home"), - url(r'^advocate$', views.Advocate.as_view(), name="wizard_advocate"), - url(r'^process/(?P[^/]+)$', views.NewProcess.as_view(), name="wizard_newprocess"), + path("", VisitorTemplateView.as_view(template_name="wizard/home.html"), name="wizard_home"), + path("advocate/", views.Advocate.as_view(), name="wizard_advocate"), + path("process//", views.NewProcess.as_view(), name="wizard_newprocess"), ] -- GitLab From 0ba7ac2ac586b84fe22ec7b99a9350eba11e4522 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 21 Apr 2020 16:04:33 +0200 Subject: [PATCH 3/4] Reproduced in test suite. refs: #9 --- wizard/tests/test_newproc.py | 72 ++++++++++++++++++++++++++++++++++++ wizard/tests/test_whoami.py | 1 - 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 wizard/tests/test_newproc.py diff --git a/wizard/tests/test_newproc.py b/wizard/tests/test_newproc.py new file mode 100644 index 0000000..0dc1f29 --- /dev/null +++ b/wizard/tests/test_newproc.py @@ -0,0 +1,72 @@ +from __future__ import annotations +from django.test import TestCase +from django.urls import reverse +from backend.unittest import PersonFixtureMixin +from backend import const +from signon.models import Identity + + +class NewProcTests(PersonFixtureMixin, TestCase): + @classmethod + def __add_extra_tests__(cls): + targets = ["dm", "ga", "return", "invalid"] + targets.extend(const.ALL_STATUS_DESCS.keys()) + + for target in targets: + cls._add_method(cls._test_notlogged, target) + cls._add_method(cls._test_active_unbound, target) + + def _test_notlogged(self, target): + # Check that the new person is listed on the page + client = self.make_test_client(None) + response = client.get(reverse('wizard_newprocess', args=[target])) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "This wizard only works when you are logged into the site") + + def _test_active_unbound(self, target): + # Check that the new person is listed on the page + identity = Identity.objects.create( + issuer="debsso", subject="test@debian.org", + username="test@debian.org", audit_skip=True) + client = self.make_test_client(None, [identity]) + response = client.get(reverse('wizard_newprocess', args=[target])) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "This wizard only works when you are logged into the site") + + def test_dc_to_dm(self): + client = self.make_test_client(self.persons.dc) + response = client.get(reverse('wizard_newprocess', args=["dm"])) + self.assertEqual(response.status_code, 200) + self.assertTrue(response.context["allowed"]) + self.assertContains(response, "and follow the instructions") + + def test_dcga_to_dm(self): + client = self.make_test_client(self.persons.dc_ga) + response = client.get(reverse('wizard_newprocess', args=["dm"])) + self.assertEqual(response.status_code, 200) + self.assertTrue(response.context["allowed"]) + self.assertContains(response, "and follow the instructions") + + def test_dm_to_dm(self): + client = self.make_test_client(self.persons.dm) + response = client.get(reverse('wizard_newprocess', args=["dm"])) + self.assertEqual(response.status_code, 200) + self.assertFalse(response.context["allowed"]) + self.assertNotContains(response, "and follow the instructions") + self.assertContains(response, "You are already a Debian Maintainer") + + def test_dmga_to_dm(self): + client = self.make_test_client(self.persons.dm_ga) + response = client.get(reverse('wizard_newprocess', args=["dm"])) + self.assertEqual(response.status_code, 200) + self.assertFalse(response.context["allowed"]) + self.assertNotContains(response, "and follow the instructions") + self.assertContains(response, "You are already a Debian Maintainer") + + def test_ddnu_to_dm(self): + client = self.make_test_client(self.persons.dd_nu) + response = client.get(reverse('wizard_newprocess', args=["dm"])) + self.assertEqual(response.status_code, 200) + self.assertFalse(response.context["allowed"]) + self.assertNotContains(response, "and follow the instructions") + self.assertContains(response, "You are already") diff --git a/wizard/tests/test_whoami.py b/wizard/tests/test_whoami.py index eb263fc..3239c74 100644 --- a/wizard/tests/test_whoami.py +++ b/wizard/tests/test_whoami.py @@ -1,7 +1,6 @@ from __future__ import annotations from django.test import TestCase from django.urls import reverse -from backend import const from backend.unittest import PersonFixtureMixin from signon.models import Identity -- GitLab From b95be09cd464ebf999cebc90f14aa47612767e81 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Tue, 21 Apr 2020 16:05:02 +0200 Subject: [PATCH 4/4] Fixed templates. refs: #9 --- wizard/templates/wizard/newprocess.html | 30 ++++--------------------- wizard/templates/wizard/whoami.html | 5 +++++ 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/wizard/templates/wizard/newprocess.html b/wizard/templates/wizard/newprocess.html index db00c6d..e543ff4 100644 --- a/wizard/templates/wizard/newprocess.html +++ b/wizard/templates/wizard/newprocess.html @@ -6,35 +6,13 @@

{{target_desc}}

-{% if not request.sso_username %} -

{% blocktrans %}You are not currently logged in. See the -Single Sign-On page -for details.{% endblocktrans %}

-{% elif not visitor %} -

{% blocktrans with request_user_username=request.user.username %}You are -currently logged in with -SSO username {{request_user_username}}, but you cannot be matched -to any person in the site.{% endblocktrans %}

-

- {% url 'dm_claim' as dm_claim_url %} - {% blocktrans %}If you are already in the site, for example as a Debian -Maintainer, you can try to correct the situation using the -claim interface.{% endblocktrans %}

-

- {% url 'dm_claim' as dm_claim_url %} - {% blocktrans %}If you are already in the site, for example as a Debian -Maintainer, you can try to correct the situation using the -claim interface.{% endblocktrans %}

-

- {% url 'public_newnm' as public_newnm_url %} - {% blocktrans %}If you are not yet in the site, -visit the 'Join the NM process' page -to can create an entry for yourself.{% endblocktrans %}

+{% if not visitor %} +

{% trans "This wizard only works when you are logged into the site" %}

{% else %} - {% for c in comments %}

{{c}}

{% endfor %} + {% for c in comments %}

{{c}}

{% endfor %} {% if allowed %} -

+

{% url 'process_create' key=visitor.lookup_key as process_create_url %} {% blocktrans %}Just visit this page and follow the instructions.{% endblocktrans %} diff --git a/wizard/templates/wizard/whoami.html b/wizard/templates/wizard/whoami.html index 05eb78f..b7474eb 100644 --- a/wizard/templates/wizard/whoami.html +++ b/wizard/templates/wizard/whoami.html @@ -17,6 +17,11 @@ are currently logged in, but not mapped to any person in the site. If you are a Debian Maintainer, you can try to correct the situation using the claim interface.{% endblocktrans %} +{% url 'public_newnm' as public_newnm_url %} +{% blocktrans %}If you are not yet in the site, +visit the 'Join the NM process' page +to create an entry for yourself.{% endblocktrans %}

+

{% trans "You are logged in as:" %}

    -- GitLab