Merge lp:~stevenk/launchpad/fix-branch-subscribe-open-team into lp:launchpad

Proposed by Steve Kowalik on 2012-06-13
Status: Superseded
Proposed branch: lp:~stevenk/launchpad/fix-branch-subscribe-open-team
Merge into: lp:launchpad
Diff against target: 51 lines (+15/-12)
1 file modified
lib/lp/code/browser/branchsubscription.py (+15/-12)
To merge this branch: bzr merge lp:~stevenk/launchpad/fix-branch-subscribe-open-team
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code 2012-06-13 Approve on 2012-06-13
Review via email: mp+109960@code.launchpad.net

This proposal has been superseded by a proposal from 2012-06-21.

Description of the Change

This branch is a follow-up to some of the behaviour introduced in https://code.launchpad.net/~stevenk/launchpad/branch-subscribe-aag/+merge/108881. That branch changed Branch.subscribe() to raise an exception if an open or delegated team was trying to be subscribed to a private branch. I had changed the browser code to catch the exception and call setFieldError(), but since next_url was unilaterally set, Zope happily redirected back to Branch:+index, and it looked like nothing happened.

I have changed how next_url is set up for the parent class of the view in question, and will only set it if the exception wasn't raised.

To post a comment you must log in.
Curtis Hovey (sinzui) wrote :

Thank you.

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/code/browser/branchsubscription.py'
2--- lib/lp/code/browser/branchsubscription.py 2012-06-06 05:58:44 +0000
3+++ lib/lp/code/browser/branchsubscription.py 2012-06-21 01:45:30 +0000
4@@ -20,7 +20,6 @@
5 LaunchpadEditFormView,
6 LaunchpadFormView,
7 )
8-from lp.app.errors import SubscriptionPrivacyViolation
9 from lp.code.enums import BranchSubscriptionNotificationLevel
10 from lp.code.interfaces.branchsubscription import IBranchSubscription
11 from lp.services.webapp import (
12@@ -212,6 +211,14 @@
13
14 page_title = label = "Subscribe to branch"
15
16+ def validate(self, data):
17+ person = data['person']
18+ subscription = self.context.getSubscription(person)
19+ if (subscription is None and person.is_team and
20+ person.anyone_can_join()):
21+ self.setFieldError('person', "Open and delegated teams cannot "
22+ "be subscribed to private branches.")
23+
24 @action("Subscribe", name="subscribe_action")
25 def subscribe_action(self, action, data):
26 """Subscribe the specified user to the branch.
27@@ -227,17 +234,13 @@
28 person = data['person']
29 subscription = self.context.getSubscription(person)
30 if subscription is None:
31- try:
32- self.context.subscribe(
33- person, notification_level, max_diff_lines, review_level,
34- self.user)
35- except SubscriptionPrivacyViolation as error:
36- self.setFieldError('person', unicode(error))
37- else:
38- self.add_notification_message(
39- '%s has been subscribed to this branch with: '
40- % person.displayname, notification_level, max_diff_lines,
41- review_level)
42+ self.context.subscribe(
43+ person, notification_level, max_diff_lines, review_level,
44+ self.user)
45+ self.add_notification_message(
46+ '%s has been subscribed to this branch with: '
47+ % person.displayname, notification_level, max_diff_lines,
48+ review_level)
49 else:
50 self.add_notification_message(
51 '%s was already subscribed to this branch with: '