Merge lp:~stevenk/launchpad/mute-when-not-allowed into lp:launchpad

Proposed by Steve Kowalik on 2012-09-19
Status: Merged
Approved by: Steve Kowalik on 2012-09-19
Approved revision: no longer in the source branch.
Merged at revision: 15982
Proposed branch: lp:~stevenk/launchpad/mute-when-not-allowed
Merge into: lp:launchpad
Diff against target: 70 lines (+28/-2)
2 files modified
lib/lp/bugs/model/bugsubscriptionfilter.py (+8/-0)
lib/lp/bugs/tests/test_structuralsubscription.py (+20/-2)
To merge this branch: bzr merge lp:~stevenk/launchpad/mute-when-not-allowed
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-09-19 Approve on 2012-09-19
Review via email: mp+125094@code.launchpad.net

Commit Message

MuteNotAllowed is now a bad request rather than an OOPS, and raise a specific error if team with a contact address calls BugSubscriptionFilter.mute().

Description of the Change

Currently if you call mute on a BugSubscriptionFilter for a team that has a contact address set over the API you get a generic error message, and an OOPS for your trouble.

I have decorated MuteNotAllowed to be a bad request, and raise an error with a hint if the team has a contact address.

To post a comment you must log in.
Ian Booth (wallyworld) wrote :

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/model/bugsubscriptionfilter.py'
2--- lib/lp/bugs/model/bugsubscriptionfilter.py 2012-08-02 04:46:31 +0000
3+++ lib/lp/bugs/model/bugsubscriptionfilter.py 2012-09-19 05:12:19 +0000
4@@ -12,7 +12,9 @@
5 ]
6
7 from itertools import chain
8+import httplib
9
10+from lazr.restful.declarations import error_status
11 import pytz
12 from storm.locals import (
13 Bool,
14@@ -44,6 +46,7 @@
15 from lp.services.database.stormbase import StormBase
16
17
18+@error_status(httplib.BAD_REQUEST)
19 class MuteNotAllowed(Exception):
20 """Raised when someone tries to mute a filter that can't be muted."""
21
22@@ -252,6 +255,11 @@
23
24 def mute(self, person):
25 """See `IBugSubscriptionFilter`."""
26+ subscriber = self.structural_subscription.subscriber
27+ if subscriber.is_team and subscriber.preferredemail:
28+ raise MuteNotAllowed(
29+ "This subscription cannot be muted because team %s has a "
30+ "contact address." % subscriber.name)
31 if not self.isMuteAllowed(person):
32 raise MuteNotAllowed(
33 "This subscription cannot be muted for %s" % person.name)
34
35=== modified file 'lib/lp/bugs/tests/test_structuralsubscription.py'
36--- lib/lp/bugs/tests/test_structuralsubscription.py 2012-08-08 11:48:29 +0000
37+++ lib/lp/bugs/tests/test_structuralsubscription.py 2012-09-19 05:12:19 +0000
38@@ -925,12 +925,30 @@
39 non_team_subscription = self.target.addBugSubscription(
40 person, person)
41 filter = non_team_subscription.bug_filters.one()
42+ expected = "This subscription cannot be muted for %s" % person.name
43 self.assertFalse(filter.isMuteAllowed(person))
44- self.assertRaises(MuteNotAllowed, filter.mute, person)
45+ self.assertRaisesWithContent(
46+ MuteNotAllowed, expected, filter.mute, person)
47
48 def test_mute_raises_error_for_non_team_members(self):
49 # BugSubscriptionFilter.mute() will raise an error if called on
50 # a subscription of which the calling person is not a member.
51 non_team_person = self.factory.makePerson()
52 self.assertFalse(self.filter.isMuteAllowed(non_team_person))
53- self.assertRaises(MuteNotAllowed, self.filter.mute, non_team_person)
54+ expected = "This subscription cannot be muted for %s" % (
55+ non_team_person.name,)
56+ self.assertRaisesWithContent(
57+ MuteNotAllowed, expected, self.filter.mute, non_team_person)
58+
59+ def test_mute_on_team_with_contact_address(self):
60+ # BugSubscriptionFilter.mute() will raise an error if called on
61+ # a subscription if the team has a contact address.
62+ person = self.factory.makePerson()
63+ team = self.factory.makeTeam(email='foo@example.com', owner=person)
64+ with person_logged_in(person):
65+ ss = self.target.addBugSubscription(team, person)
66+ filter = ss.bug_filters.one()
67+ expected = ("This subscription cannot be muted because team %s has a "
68+ "contact address." % team.name)
69+ self.assertRaisesWithContent(
70+ MuteNotAllowed, expected, filter.mute, person)