Merge ~ilasc/launchpad:fix-expose-send-notifications into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 71b6233906a05d56db93eedfa44550af6321a165
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:fix-expose-send-notifications
Merge into: launchpad:master
Diff against target: 117 lines (+39/-16)
5 files modified
lib/lp/bugs/browser/bugtarget.py (+1/-1)
lib/lp/bugs/interfaces/bug.py (+5/-0)
lib/lp/bugs/model/bug.py (+31/-12)
lib/lp/bugs/model/tests/test_bug.py (+1/-1)
lib/lp/bugs/tests/test_bug_messages_webservice.py (+1/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+429828@code.launchpad.net

Commit message

Separate Bug.newMessage into internal and API methods

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
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/browser/bugtarget.py b/lib/lp/bugs/browser/bugtarget.py
2index e59af36..e7b3dc6 100644
3--- a/lib/lp/bugs/browser/bugtarget.py
4+++ b/lib/lp/bugs/browser/bugtarget.py
5@@ -648,7 +648,7 @@ class FileBugViewBase(LaunchpadFormView):
6 attachment = self.request.form.get(self.widgets["filecontent"].name)
7 if attachment or extra_data.attachments:
8 # Attach all the comments to a single empty comment.
9- attachment_comment = bug.newMessage(
10+ attachment_comment = bug.newMessage_internal(
11 owner=self.user,
12 subject=bug.followup_subject(),
13 content=None,
14diff --git a/lib/lp/bugs/interfaces/bug.py b/lib/lp/bugs/interfaces/bug.py
15index ab4e2fc..9697660 100644
16--- a/lib/lp/bugs/interfaces/bug.py
17+++ b/lib/lp/bugs/interfaces/bug.py
18@@ -1045,6 +1045,11 @@ class IBugAppend(Interface):
19 def newMessage(owner, subject, content, send_notifications=True):
20 """Create a new message, and link it to this object."""
21
22+ def newMessage_internal(owner, subject, content, send_notifications=True):
23+ """Create a new message, and link it to this object.
24+ This method is used internally mostly by the UI.
25+ """
26+
27 @operation_parameters(
28 person=Reference(IPerson, title=_("Person"), required=True),
29 level=Choice(
30diff --git a/lib/lp/bugs/model/bug.py b/lib/lp/bugs/model/bug.py
31index 7685c10..5b1465c 100644
32--- a/lib/lp/bugs/model/bug.py
33+++ b/lib/lp/bugs/model/bug.py
34@@ -1487,6 +1487,37 @@ class Bug(SQLBase, InformationTypeMixin):
35 remote_comment_id=None,
36 send_notifications=True,
37 ):
38+ # Admins, commercial admins, registry experts, pillar owners,
39+ # pillar drivers, and pillar bug supervisors should be able
40+ # to disable email notifications
41+ if not send_notifications:
42+ authz = getAdapter(self, IAuthorization, "launchpad.Moderate")
43+ if not authz.checkAuthenticated(IPersonRoles(owner)):
44+ raise CannotDisableNotifications(
45+ "Email notifications can only "
46+ "be disabled by admins, commercial admins, "
47+ "registry experts, or bug supervisors."
48+ )
49+ return self.newMessage_internal(
50+ owner=owner,
51+ subject=subject,
52+ content=content,
53+ parent=parent,
54+ bugwatch=bugwatch,
55+ remote_comment_id=remote_comment_id,
56+ send_notifications=send_notifications,
57+ )
58+
59+ def newMessage_internal(
60+ self,
61+ owner=None,
62+ subject=None,
63+ content=None,
64+ parent=None,
65+ bugwatch=None,
66+ remote_comment_id=None,
67+ send_notifications=True,
68+ ):
69 """Create a new Message and link it to this bug."""
70 if subject is None:
71 subject = self.followup_subject()
72@@ -1504,18 +1535,6 @@ class Bug(SQLBase, InformationTypeMixin):
73 if not bugmsg:
74 return
75
76- # Admins, commercial admins, registry experts, pillar owners,
77- # pillar drivers, and pillar bug supervisors should be able
78- # to disable email notifications
79- authz = getAdapter(self, IAuthorization, "launchpad.Moderate")
80- if not authz.checkAuthenticated(IPersonRoles(owner)):
81- raise CannotDisableNotifications(
82- "Email notifications can only "
83- "be disabled by admins, commercial admins, "
84- "registry experts, pillar owners, pillar drivers "
85- "or pillar bug supervisors."
86- )
87-
88 if send_notifications:
89 notify(ObjectCreatedEvent(bugmsg, user=owner))
90
91diff --git a/lib/lp/bugs/model/tests/test_bug.py b/lib/lp/bugs/model/tests/test_bug.py
92index 1ce81f9..75921da 100644
93--- a/lib/lp/bugs/model/tests/test_bug.py
94+++ b/lib/lp/bugs/model/tests/test_bug.py
95@@ -645,7 +645,7 @@ class TestBug(TestCaseWithFactory):
96 bug = self.factory.makeBug()
97 login_person(bug.owner)
98 with EventRecorder() as recorder:
99- bug.newMessage(owner=bug.owner, send_notifications=False)
100+ bug.newMessage_internal(owner=bug.owner, send_notifications=False)
101 self.assertEqual(0, len(recorder.events))
102
103 def test_vulnerabilities_property(self):
104diff --git a/lib/lp/bugs/tests/test_bug_messages_webservice.py b/lib/lp/bugs/tests/test_bug_messages_webservice.py
105index 39153bf..d8a77a1 100644
106--- a/lib/lp/bugs/tests/test_bug_messages_webservice.py
107+++ b/lib/lp/bugs/tests/test_bug_messages_webservice.py
108@@ -150,8 +150,7 @@ class TestBugMessage(TestCaseWithFactory):
109 self.assertEqual(400, response.status)
110 self.assertEqual(
111 b"Email notifications can only be disabled by admins, "
112- b"commercial admins, registry experts, pillar owners, "
113- b"pillar drivers or pillar bug supervisors.",
114+ b"commercial admins, registry experts, or bug supervisors.",
115 response.body,
116 )
117 self.assertFalse(self._email_sent())

Subscribers

People subscribed via source and target branches

to status/vote changes: