Merge lp:~cjwatson/launchpad/no-team-admins-fallback into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18618
Proposed branch: lp:~cjwatson/launchpad/no-team-admins-fallback
Merge into: lp:launchpad
Diff against target: 96 lines (+32/-5)
4 files modified
lib/lp/registry/interfaces/person.py (+6/-1)
lib/lp/registry/model/person.py (+2/-0)
lib/lp/registry/tests/test_subscribers.py (+20/-1)
lib/lp/registry/tests/test_team.py (+4/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/no-team-admins-fallback
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+343363@code.launchpad.net

Commit message

Fall back to emailing the team owner if the team has no admins.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
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/interfaces/person.py'
2--- lib/lp/registry/interfaces/person.py 2017-06-01 12:58:53 +0000
3+++ lib/lp/registry/interfaces/person.py 2018-04-17 01:07:45 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Person interfaces."""
10@@ -1344,9 +1344,14 @@
11 member with admin privilege, or member of a team with such
12 privileges. It excludes teams which have been merged.
13 """
14+
15 def getTeamAdminsEmailAddresses():
16 """Return a set containing the email addresses of all administrators
17 of this team.
18+
19+ If the team has no administrators, fall back to the team owner.
20+ This shouldn't normally happen, but a team can end up in this state
21+ after deactivations, and there's no good way to prevent it entirely.
22 """
23
24 def getLatestApprovedMembershipsForPerson(limit=5):
25
26=== modified file 'lib/lp/registry/model/person.py'
27--- lib/lp/registry/model/person.py 2018-04-10 11:10:09 +0000
28+++ lib/lp/registry/model/person.py 2018-04-17 01:07:45 +0000
29@@ -1595,6 +1595,8 @@
30 to_addrs = set()
31 for admin in self.adminmembers:
32 to_addrs.update(get_contact_email_addresses(admin))
33+ if not to_addrs:
34+ to_addrs.update(get_contact_email_addresses(self.teamowner))
35 return sorted(to_addrs)
36
37 def addMember(self, person, reviewer, comment=None, force_team_add=False,
38
39=== modified file 'lib/lp/registry/tests/test_subscribers.py'
40--- lib/lp/registry/tests/test_subscribers.py 2017-12-19 17:15:21 +0000
41+++ lib/lp/registry/tests/test_subscribers.py 2018-04-17 01:07:45 +0000
42@@ -1,4 +1,4 @@
43-# Copyright 2012 Canonical Ltd. This software is licensed under the
44+# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
45 # GNU Affero General Public License version 3 (see the file LICENSE).
46
47 """Test subscruber classes and functions."""
48@@ -190,6 +190,25 @@
49 self.assertEqual(1, len(notifications))
50 self.assertEqual('admin@eg.dom,owner@eg.dom', notifications[0]['To'])
51
52+ def test_send_other_proprietary_no_team_admins_falls_back_to_owner(self):
53+ # If there are no team admins, an Other/Proprietary licence falls
54+ # back to sending email to the team owner.
55+ product, user = self.make_product_user([License.OTHER_PROPRIETARY])
56+ owner = self.factory.makePerson(email='owner@eg.dom')
57+ team = self.factory.makeTeam(
58+ owner=owner, membership_policy=TeamMembershipPolicy.RESTRICTED)
59+ with person_logged_in(team.teamowner):
60+ team.teamowner.leave(team)
61+ with person_logged_in(product.owner):
62+ product.owner = team
63+ pop_notifications()
64+ notification = LicenseNotification(product)
65+ result = notification.send()
66+ self.assertIs(True, result)
67+ notifications = pop_notifications()
68+ self.assertEqual(1, len(notifications))
69+ self.assertEqual('owner@eg.dom', notifications[0]['To'])
70+
71 def test_display_no_request(self):
72 # If there is no request, there is no reason to show a message in
73 # the browser.
74
75=== modified file 'lib/lp/registry/tests/test_team.py'
76--- lib/lp/registry/tests/test_team.py 2016-01-26 15:47:37 +0000
77+++ lib/lp/registry/tests/test_team.py 2018-04-17 01:07:45 +0000
78@@ -1,4 +1,4 @@
79-# Copyright 2010-2015 Canonical Ltd. This software is licensed under the
80+# Copyright 2010-2018 Canonical Ltd. This software is licensed under the
81 # GNU Affero General Public License version 3 (see the file LICENSE).
82
83 """Tests for PersonSet."""
84@@ -165,9 +165,10 @@
85 self.assertEqual([email], self.team.getTeamAdminsEmailAddresses())
86
87 def test_no_admins(self):
88- # A team without admins has no email addresses.
89+ # A team without admins falls back to the owner's email address.
90+ email = self.team.teamowner.preferredemail.email
91 self.team.teamowner.leave(self.team)
92- self.assertEqual([], self.team.getTeamAdminsEmailAddresses())
93+ self.assertEqual([email], self.team.getTeamAdminsEmailAddresses())
94
95 def test_admins_are_users_with_preferred_email_addresses(self):
96 # The team's admins are users, and they provide the email addresses.