From 737b6828557bdfd1378d029fccf4bd9553464d70 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 17 Mar 2020 16:13:00 +0100 Subject: [PATCH] Add comments, clean up code --- server/registration/mutations_public.py | 5 ++++- server/registration/tests/test_registration_proxy.py | 4 ++-- server/registration/view.py | 6 +----- server/users/models.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/server/registration/mutations_public.py b/server/registration/mutations_public.py index 6b5c7605..2cd26c9c 100644 --- a/server/registration/mutations_public.py +++ b/server/registration/mutations_public.py @@ -36,6 +36,9 @@ class Registration(relay.ClientIDMutation): try: hep_client.customer_activate(confirmation_key, user_id) user_data = hep_client.customers_by_id(admin_token, user_id) + + # double check if user has verified his email. If the "confirmation" field is present, the email address + # is not verified. Note that the user should not be able to see this page without verified email. if 'confirmation' in user_data: return cls.return_registration_msg('invalid_key') except HepClientException: @@ -53,7 +56,7 @@ class Registration(relay.ClientIDMutation): @classmethod def return_registration_msg(cls, message): - # even if the user has no valid license treat it like a success + # even if the user has no valid license on the hep server treat it like a success as registration has succeeded if message == UNKNOWN_ERROR: raise Exception(message) diff --git a/server/registration/tests/test_registration_proxy.py b/server/registration/tests/test_registration_proxy.py index d8d3b0f5..36e1ca8c 100644 --- a/server/registration/tests/test_registration_proxy.py +++ b/server/registration/tests/test_registration_proxy.py @@ -74,7 +74,7 @@ class ProxyTest(TestCase): @patch.object(HepClient, 'customer_create', return_value=RESPONSE) def test_proxy_filters_confirmation_key(self, create_mock): - response = self.client.post(reverse('api:registration:proxy'), DATA) + response = self.client.post(reverse('api:registration:proxy'), json.dumps(DATA), content_type="application/json") found = 'confirmation' in response.json().keys() self.assertFalse(found) @@ -82,5 +82,5 @@ class ProxyTest(TestCase): data={'message': 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.'})) def test_handles_400(self, create_mock): - response = self.client.post(reverse('api:registration:proxy'), DATA) + response = self.client.post(reverse('api:registration:proxy'), json.dumps(DATA), content_type="application/json") self.assertEquals(response.json()['message'], 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.') diff --git a/server/registration/view.py b/server/registration/view.py index 19db6b1a..433b7e24 100644 --- a/server/registration/view.py +++ b/server/registration/view.py @@ -19,11 +19,7 @@ class RegistrationProxyView(View): def post(self, request, *args, **kwargs): hep_client = HepClient() - - if request.POST: - data = request.POST - else: - data = json.loads(request.body) + data = json.loads(request.body) try: hep_data = hep_client.customer_create(data) diff --git a/server/users/models.py b/server/users/models.py index bd435216..6da15944 100644 --- a/server/users/models.py +++ b/server/users/models.py @@ -225,4 +225,4 @@ class License(models.Model): self.for_role.key) def __str__(self): - return 'License for role: %s' % self.for_role + return f'License for role: {self.for_role}'