From 4ff165480687539318ae07cc3c7c6f4446f68912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 29 Jan 2019 19:16:52 +0200 Subject: [PATCH] Don't create default projects for invited users. --- hc/accounts/tests/test_project.py | 2 ++ hc/accounts/views.py | 36 ++++++++++++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/hc/accounts/tests/test_project.py b/hc/accounts/tests/test_project.py index 5b3da446..b9804597 100644 --- a/hc/accounts/tests/test_project.py +++ b/hc/accounts/tests/test_project.py @@ -65,6 +65,8 @@ class ProfileTestCase(BaseTestCase): profile = member.user.profile self.assertEqual(profile.current_project, self.project) + # The new user should not have their own project + self.assertFalse(member.user.project_set.exists()) # And an email should have been sent subj = ('You have been invited to join' diff --git a/hc/accounts/views.py b/hc/accounts/views.py index c914b9c2..f06b4587 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -43,33 +43,35 @@ def _is_whitelisted(path): return match.url_name in NEXT_WHITELIST -def _make_user(email): +def _make_user(email, with_project=True): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.set_unusable_password() user.save() - project = Project(owner=user) - project.badge_key = user.username - project.save() + project = None + if with_project: + project = Project(owner=user) + project.badge_key = user.username + project.save() + + check = Check(project=project) + check.name = "My First Check" + check.save() + + channel = Channel(project=project) + channel.kind = "email" + channel.value = email + channel.email_verified = True + channel.save() + + channel.checks.add(check) # Ensure a profile gets created profile = Profile.objects.for_user(user) profile.current_project = project profile.save() - check = Check(project=project) - check.name = "My First Check" - check.save() - - channel = Channel(project=project) - channel.kind = "email" - channel.value = email - channel.email_verified = True - channel.save() - - channel.checks.add(check) - return user @@ -275,7 +277,7 @@ def project(request, code): try: user = User.objects.get(email=email) except User.DoesNotExist: - user = _make_user(email) + user = _make_user(email, with_project=False) project.invite(user) ctx["team_member_invited"] = email