Merge lp:~mbp/launchpad/855150-mail-disabled into lp:launchpad

Proposed by Martin Pool
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 14050
Proposed branch: lp:~mbp/launchpad/855150-mail-disabled
Merge into: lp:launchpad
Diff against target: 92 lines (+43/-6)
2 files modified
lib/lp/registry/model/person.py (+10/-6)
lib/lp/registry/tests/test_person.py (+33/-0)
To merge this branch: bzr merge lp:~mbp/launchpad/855150-mail-disabled
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+76876@code.launchpad.net

Commit message

[r=sinzui] [bug=858605] don't send mail to individuals without an active account

Description of the change

This handles bug 858605 (split from bug 855150), which is that Launchpad sends mail to people who have deactivated accounts. I addressed this by changing get_recipients to check against the account table too, and adding a unit test for this. I also checked the uses of get_recipients and none seems like it would actually want to be mailing deactivated accounts - perhaps the only case for that would be if people wanted to reactivate them, and I think they have to log in first.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

W00t! Thank you very much.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/person.py'
2--- lib/lp/registry/model/person.py 2011-09-23 07:49:54 +0000
3+++ lib/lp/registry/model/person.py 2011-09-26 10:09:24 +0000
4@@ -4674,7 +4674,8 @@
5 If <person> has a preferred email, the set will contain only that
6 person. If <person> doesn't have a preferred email but is a team,
7 the set will contain the preferred email address of each member of
8- <person>, including indirect members.
9+ <person>, including indirect members, that has an active account and an
10+ preferred (active) address.
11
12 Finally, if <person> doesn't have a preferred email and is not a team,
13 the set will be empty.
14@@ -4682,7 +4683,7 @@
15 if person.preferredemail:
16 return [person]
17 elif person.is_team:
18- # Get transitive members of team without a preferred email.
19+ # Get transitive members of a team that does not itself have a preferred email.
20 return _get_recipients_for_team(person)
21 else:
22 return []
23@@ -4701,13 +4702,15 @@
24 And(
25 EmailAddress.person == Person.id,
26 EmailAddress.status ==
27- EmailAddressStatus.PREFERRED)))
28+ EmailAddressStatus.PREFERRED)),
29+ LeftJoin(Account,
30+ Person.accountID == Account.id))
31 pending_team_ids = [team.id]
32 recipient_ids = set()
33 seen = set()
34 while pending_team_ids:
35- # Find Persons that have a preferred email address, or are a
36- # team, or both.
37+ # Find Persons that have a preferred email address and an active
38+ # account, or are a team, or both.
39 intermediate_transitive_results = source.find(
40 (TeamMembership.personID, EmailAddress.personID),
41 In(TeamMembership.status,
42@@ -4715,7 +4718,8 @@
43 TeamMembershipStatus.APPROVED.value]),
44 In(TeamMembership.teamID, pending_team_ids),
45 Or(
46- EmailAddress.personID != None,
47+ And(EmailAddress.personID != None,
48+ Account.status == AccountStatus.ACTIVE),
49 Person.teamownerID != None)).config(distinct=True)
50 next_ids = []
51 for (person_id,
52
53=== modified file 'lib/lp/registry/tests/test_person.py'
54--- lib/lp/registry/tests/test_person.py 2011-09-23 07:49:54 +0000
55+++ lib/lp/registry/tests/test_person.py 2011-09-26 10:09:24 +0000
56@@ -1719,3 +1719,36 @@
57 super_team_member_person,
58 super_team_member_team]),
59 set(recipients))
60+
61+ def test_get_recipients_team_with_disabled_owner_account(self):
62+ """Mail is not sent to a team owner whose account is disabled.
63+
64+ See <https://bugs.launchpad.net/launchpad/+bug/855150>
65+ """
66+ owner = self.factory.makePerson(email='foo@bar.com')
67+ team = self.factory.makeTeam(owner)
68+ owner.account.status = AccountStatus.DEACTIVATED
69+ self.assertContentEqual([], get_recipients(team))
70+
71+ def test_get_recipients_team_with_disabled_member_account(self):
72+ """Mail is not sent to a team member whose account is disabled.
73+
74+ See <https://bugs.launchpad.net/launchpad/+bug/855150>
75+ """
76+ person = self.factory.makePerson(email='foo@bar.com')
77+ person.account.status = AccountStatus.DEACTIVATED
78+ team = self.factory.makeTeam(members=[person])
79+ self.assertContentEqual([team.teamowner], get_recipients(team))
80+
81+ def test_get_recipients_team_with_nested_disabled_member_account(self):
82+ """Mail is not sent to transitive team member with disabled account.
83+
84+ See <https://bugs.launchpad.net/launchpad/+bug/855150>
85+ """
86+ person = self.factory.makePerson(email='foo@bar.com')
87+ person.account.status = AccountStatus.DEACTIVATED
88+ team1 = self.factory.makeTeam(members=[person])
89+ team2 = self.factory.makeTeam(members=[team1])
90+ self.assertContentEqual(
91+ [team2.teamowner],
92+ get_recipients(team2))