Merge ~lgp171188/launchpad:allow-distribution-bug-supervisor-to-create-structural-subscriptions into launchpad:master

Proposed by Guruprasad
Status: Merged
Approved by: Guruprasad
Approved revision: 9c4c541781b9178e0d8834e67b747033b1338743
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~lgp171188/launchpad:allow-distribution-bug-supervisor-to-create-structural-subscriptions
Merge into: launchpad:master
Diff against target: 62 lines (+23/-4)
2 files modified
lib/lp/bugs/model/structuralsubscription.py (+2/-2)
lib/lp/bugs/tests/test_structuralsubscriptiontarget.py (+21/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Ines Almeida Approve
William Grant Abstain
Review via email: mp+452490@code.launchpad.net

Commit message

Allow the distribution bug supervisor to add structural subscriptions

LP: #2037777

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

The intent of that additional check is to prevent random people from accidentally subscribing themselves to the flood of mail that is Ubuntu's bugs. I don't think we want to change that, and I don't think we want to relax the rule that people can't subscribe other unrelated people or teams -- ~ubuntu-bugcontrol is a fairly broad set of people.

review: Needs Fixing (code)
Revision history for this message
William Grant (wgrant) wrote :

Though reading further I see that that check would still be implemented in userCanAlterSubscription. Never mind me.

review: Abstain
Revision history for this message
Guruprasad (lgp171188) wrote :

William,

> The intent of that additional check is to prevent random people from accidentally subscribing themselves to the flood of mail that is Ubuntu's bugs. I don't think we want to change that, and I don't think we want to relax the rule that people can't subscribe other unrelated people or teams -- ~ubuntu-bugcontrol is a fairly broad set of people.

In https://git.launchpad.net/launchpad/tree/lib/lp/bugs/model/structuralsubscription.py#n425, the comment explains exactly what I have implemented in this MP even though the current implementation doesn't match it - it checks the 'subscribed' person instead of the 'subscribed_by' person.

I implemented this change based on the feedback from Colin in comment #3 of https://answers.launchpad.net/launchpad/+question/707908.

Please let me know if I misunderstood something here.

Revision history for this message
Colin Watson (cjwatson) wrote :

Right, I think this is largely simple confusion between `subscriber` and `subscribed_by` - I don't feel that "only the bug supervisor or its members can be subscribed to the distribution's bugs" is a rule that's coherent with the rest of Launchpad, as opposed to "only the bug supervisor or its members can subscribe anyone to the distribution's bugs" which is what the comment says but not what the implementation does. Ironically, the person who asked the question that prompted this wrote this code to start with.

I don't like the location of the tests here, though. Looking through `tig blame` for the original code, I find that it came along with the addition of `lp.bugs.tests.test_structuralsubscriptiontarget.TestStructuralSubscriptionForDistro`, which still has several tests that overlap with the test cases you've added here (they just unfortunately didn't keep as clear a distinction between the subscriber and the person doing the subscribing as might have helped to avoid this problem). Could you move your tests there and rework them so that they use the same style as those existing tests?

review: Needs Fixing
Revision history for this message
Guruprasad (lgp171188) wrote (last edit ):

Colin, while trying to port my existing tests to the `TestStructuralSubscriptionForDistro` test class, I found that fixing the checks in `userCanAlterBugSubscription()` like I have done is insufficient to allow the subscription mentioned in the linked question to happen. This is because, `addBugSubscription()` calls `userCanAlterBugSubscription()` and that returns `True` because of my changes in this MP. It then calls `addSubscription()` which, in turn, calls `userCanAlterSubscription()` and that doesn't allow this subscription to happen.

I am unsure of tweaking `userCanAlterSubscription()` since that _could_ violate the restriction that William mentioned in his first comment. So what can I do here?

Revision history for this message
Ines Almeida (ines-almeida) wrote :

Reading through the thread and the related question, I think the change makes sense and seems quite contained. Just a very minor comment on one of the tests

review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
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
1diff --git a/lib/lp/bugs/model/structuralsubscription.py b/lib/lp/bugs/model/structuralsubscription.py
2index 1694f09..37e8be2 100644
3--- a/lib/lp/bugs/model/structuralsubscription.py
4+++ b/lib/lp/bugs/model/structuralsubscription.py
5@@ -430,8 +430,8 @@ class StructuralSubscriptionTargetMixin:
6 if subscriber is None or subscribed_by is None:
7 return False
8 elif (
9- subscriber != self.bug_supervisor
10- and not subscriber.inTeam(self.bug_supervisor)
11+ subscribed_by != self.bug_supervisor
12+ and not subscribed_by.inTeam(self.bug_supervisor)
13 and not subscribed_by.inTeam(admins)
14 ):
15 return False
16diff --git a/lib/lp/bugs/tests/test_structuralsubscriptiontarget.py b/lib/lp/bugs/tests/test_structuralsubscriptiontarget.py
17index 9eb6933..985df25 100644
18--- a/lib/lp/bugs/tests/test_structuralsubscriptiontarget.py
19+++ b/lib/lp/bugs/tests/test_structuralsubscriptiontarget.py
20@@ -12,6 +12,7 @@ from zope.component import getUtility
21 from zope.security.interfaces import Unauthorized
22 from zope.security.proxy import ProxyFactory, removeSecurityProxy
23
24+from lp.app.interfaces.launchpad import ILaunchpadCelebrities
25 from lp.bugs.interfaces.bug import CreateBugParams
26 from lp.bugs.interfaces.structuralsubscription import (
27 IStructuralSubscriptionTarget,
28@@ -228,14 +229,32 @@ class TestStructuralSubscriptionForDistro(
29 StructuralSubscription,
30 )
31
32- def test_distribution_subscription_by_bug_supervisor_team(self):
33- # team admins can subscribe team if team is bug supervisor
34+ def test_distribution_bug_supervisor_admin_can_subscribe_owned_teams(self):
35+ # bug supervisor team admin can subscribe any owned team including
36+ # the bug supervisor team itself.
37 removeSecurityProxy(self.target).bug_supervisor = self.team
38+ another_team = self.factory.makeTeam(owner=self.team_owner)
39 login_person(self.team_owner)
40 self.assertIsInstance(
41 self.target.addBugSubscription(self.team, self.team_owner),
42 StructuralSubscription,
43 )
44+ self.assertIsInstance(
45+ self.target.addBugSubscription(another_team, self.team_owner),
46+ StructuralSubscription,
47+ )
48+
49+ def test_admin_can_subscribe_anyone_to_the_distribution(self):
50+ admin = getUtility(ILaunchpadCelebrities).admin.teamowner
51+ login_person(admin)
52+ self.assertIsInstance(
53+ self.target.addBugSubscription(self.team_owner, admin),
54+ StructuralSubscription,
55+ )
56+ self.assertIsInstance(
57+ self.target.addBugSubscription(self.team, admin),
58+ StructuralSubscription,
59+ )
60
61 def test_distribution_unsubscription_by_bug_supervisor_team(self):
62 # team admins can unsubscribe team if team is bug supervisor

Subscribers

People subscribed via source and target branches

to status/vote changes: