Merge lp:~wgrant/launchpad/mailman-deny-suspended into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 18000
Proposed branch: lp:~wgrant/launchpad/mailman-deny-suspended
Merge into: lp:launchpad
Diff against target: 66 lines (+18/-4)
2 files modified
lib/lp/registry/tests/test_mailinglistapi.py (+10/-2)
lib/lp/registry/xmlrpc/mailinglist.py (+8/-2)
To merge this branch: bzr merge lp:~wgrant/launchpad/mailman-deny-suspended
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+292147@code.launchpad.net

Commit message

Fix MailingListAPIView.isRegisteredInLaunchpad to reject suspended accounts.

Description of the change

Fix MailingListAPIView.isRegisteredInLaunchpad to reject suspended accounts.

Suspension should revoke all privileges, as it's often used as an anti-spam measure.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/tests/test_mailinglistapi.py'
2--- lib/lp/registry/tests/test_mailinglistapi.py 2012-09-28 06:15:58 +0000
3+++ lib/lp/registry/tests/test_mailinglistapi.py 2016-04-18 13:11:00 +0000
4@@ -31,10 +31,11 @@
5 MailingListAPIView,
6 )
7 from lp.services.config import config
8+from lp.services.identity.interfaces.account import AccountStatus
9 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
10 from lp.services.messages.interfaces.message import IMessageSet
11 from lp.testing import (
12- celebrity_logged_in,
13+ admin_logged_in,
14 person_logged_in,
15 TestCaseWithFactory,
16 )
17@@ -132,6 +133,13 @@
18 self.factory.makeTeam(email='me@fndor.dom')
19 self.assertFalse(self.api.isRegisteredInLaunchpad('me@fndor.dom'))
20
21+ def test_isRegisteredInLaunchpad_suspended(self):
22+ person = self.factory.makePerson(email='me@fndor.dom')
23+ self.assertTrue(self.api.isRegisteredInLaunchpad('me@fndor.dom'))
24+ with admin_logged_in():
25+ person.setAccountStatus(AccountStatus.SUSPENDED, None, 'Spammer!')
26+ self.assertFalse(self.api.isRegisteredInLaunchpad('me@fndor.dom'))
27+
28 def test_isTeamPublic(self):
29 self.factory.makeTeam(
30 name='team-b', visibility=PersonVisibility.PRIVATE)
31@@ -145,7 +153,7 @@
32 def test_inGoodStanding(self):
33 self.factory.makePerson(email='no@eg.dom')
34 yes_person = self.factory.makePerson(email='yes@eg.dom')
35- with celebrity_logged_in('admin'):
36+ with admin_logged_in():
37 yes_person.personal_standing = PersonalStanding.GOOD
38 self.assertIs(True, self.api.inGoodStanding('yes@eg.dom'))
39 self.assertIs(False, self.api.inGoodStanding('no@eg.dom'))
40
41=== modified file 'lib/lp/registry/xmlrpc/mailinglist.py'
42--- lib/lp/registry/xmlrpc/mailinglist.py 2015-07-08 16:05:11 +0000
43+++ lib/lp/registry/xmlrpc/mailinglist.py 2016-04-18 13:11:00 +0000
44@@ -29,6 +29,9 @@
45 )
46 from lp.services.config import config
47 from lp.services.encoding import escape_nonascii_uniquely
48+from lp.services.identity.interfaces.account import (
49+ INACTIVE_ACCOUNT_STATUSES,
50+ )
51 from lp.services.identity.interfaces.emailaddress import (
52 EmailAddressStatus,
53 IEmailAddressSet,
54@@ -223,8 +226,11 @@
55 # discarded.
56 return False
57 email_address = getUtility(IEmailAddressSet).getByEmail(address)
58- return (email_address is not None and
59- not email_address.person.is_team and
60+ if email_address is None:
61+ return False
62+ person = email_address.person
63+ return (not person.is_team and
64+ person.account_status not in INACTIVE_ACCOUNT_STATUSES and
65 email_address.status in (EmailAddressStatus.VALIDATED,
66 EmailAddressStatus.PREFERRED))
67