diff --git a/hc/accounts/models.py b/hc/accounts/models.py index b605a431..682dfca8 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -180,13 +180,13 @@ class Profile(models.Model): return self.member_set.count() < self.team_limit def invite(self, user): - for project in self.user.project_set.all(): - member = Member(team=self, user=user, project=project) - member.save() + project = self.get_own_project() + Member.objects.create(team=self, user=user, project=project) # Switch the invited user over to the new team so they # notice the new team on next visit: user.profile.current_team = self + user.profile.current_project = project user.profile.save() user.profile.send_instant_login_link(self) diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 8aa822a1..7281dd7b 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -142,13 +142,11 @@ class ProfileTestCase(BaseTestCase): members = self.project.member_set.all() self.assertEqual(members.count(), 2) - frank_found = False - for member in members.all(): - self.assertEqual(member.project, self.project) - if member.user.email == "frank@example.org": - frank_found = True + member = Member.objects.get(project=self.project, + user__email="frank@example.org") - self.assertTrue(frank_found) + profile = member.user.profile + self.assertEqual(profile.current_project, self.project) # And an email should have been sent subj = ('You have been invited to join'