Merge lp:~thumper/launchpad/new-code-import-owner into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Paul Hummer
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~thumper/launchpad/new-code-import-owner
Merge into: lp:launchpad
Diff against target: 151 lines (+76/-9)
3 files modified
lib/lp/code/browser/codeimport.py (+31/-9)
lib/lp/code/stories/codeimport/xx-create-codeimport.txt (+42/-0)
lib/lp/code/templates/codeimport-new.pt (+3/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/new-code-import-owner
Reviewer Review Type Date Requested Status
Paul Hummer (community) code Approve
Review via email: mp+23974@code.launchpad.net

Commit message

Allow the user to select the owner for a new code import.

Description of the change

Add the ability for the user to specify the owner for a new import branch.

Admins and bzr-experts can specify any branch owner, other people only get to choose from teams that they are a member of or themselves.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) :
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/codeimport.py'
2--- lib/lp/code/browser/codeimport.py 2010-03-18 17:30:14 +0000
3+++ lib/lp/code/browser/codeimport.py 2010-04-23 01:24:23 +0000
4@@ -38,7 +38,8 @@
5 from lp.code.interfaces.codeimport import (
6 ICodeImport, ICodeImportSet)
7 from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
8-from lp.code.interfaces.branch import BranchExists, IBranch
9+from lp.code.interfaces.branch import (
10+ BranchExists, IBranch, user_has_special_branch_access)
11 from lp.code.interfaces.branchtarget import IBranchTarget
12 from lp.registry.interfaces.product import IProduct
13 from canonical.launchpad.webapp import (
14@@ -202,6 +203,7 @@
15 class NewCodeImportForm(Interface):
16 """The fields presented on the form for editing a code import."""
17
18+ use_template(IBranch, ['owner'])
19 use_template(
20 ICodeImport,
21 ['rcs_type', 'cvs_root', 'cvs_module'])
22@@ -266,10 +268,13 @@
23
24 custom_widget('rcs_type', LaunchpadRadioWidget)
25
26- initial_values = {
27- 'rcs_type': RevisionControlSystems.BZR_SVN,
28- 'branch_name': 'trunk',
29- }
30+ @property
31+ def initial_values(self):
32+ return {
33+ 'owner': self.user,
34+ 'rcs_type': RevisionControlSystems.BZR_SVN,
35+ 'branch_name': 'trunk',
36+ }
37
38 @property
39 def context_is_product(self):
40@@ -292,6 +297,21 @@
41 if self.context_is_product:
42 self.form_fields = self.form_fields.omit('product')
43
44+ # If the user can administer branches, then they should be able to
45+ # assign the ownership of the branch to any valid person or team.
46+ if user_has_special_branch_access(self.user):
47+ owner_field = self.schema['owner']
48+ any_owner_choice = Choice(
49+ __name__='owner', title=owner_field.title,
50+ description = _("As an administrator you are able to reassign"
51+ " this branch to any person or team."),
52+ required=True, vocabulary='ValidPersonOrTeam')
53+ any_owner_field = form.Fields(
54+ any_owner_choice, render_context=self.render_context)
55+ # Replace the normal owner field with a more permissive vocab.
56+ self.form_fields = self.form_fields.omit('owner')
57+ self.form_fields = any_owner_field + self.form_fields
58+
59 def setUpWidgets(self):
60 CodeImportBaseView.setUpWidgets(self)
61
62@@ -334,6 +354,7 @@
63 cvs_root, cvs_module, url = self._getImportLocation(data)
64 return getUtility(ICodeImportSet).new(
65 registrant=self.user,
66+ owner=data['owner'],
67 target=IBranchTarget(product),
68 branch_name=data['branch_name'],
69 rcs_type=data['rcs_type'],
70@@ -410,12 +431,13 @@
71 """See `LaunchpadFormView`."""
72 # Make sure that the user is able to create branches for the specified
73 # namespace.
74- celebs = getUtility(ILaunchpadCelebrities)
75 product = self.getProduct(data)
76- if product is not None:
77- namespace = get_branch_namespace(celebs.vcs_imports, product)
78+ # 'owner' in data may be None if it failed validation.
79+ owner = data.get('owner')
80+ if product is not None and owner is not None:
81+ namespace = get_branch_namespace(owner, product)
82 policy = IBranchNamespacePolicy(namespace)
83- if not policy.canCreateBranches(celebs.vcs_imports):
84+ if not policy.canCreateBranches(self.user):
85 self.setFieldError(
86 'product',
87 "You are not allowed to register imports for %s."
88
89=== modified file 'lib/lp/code/stories/codeimport/xx-create-codeimport.txt'
90--- lib/lp/code/stories/codeimport/xx-create-codeimport.txt 2010-01-20 03:19:44 +0000
91+++ lib/lp/code/stories/codeimport/xx-create-codeimport.txt 2010-04-23 01:24:23 +0000
92@@ -247,3 +247,45 @@
93 ... print extract_text(message)
94 There is 1 error.
95 Invalid value
96+
97+
98+Specifying the owner of the branch when it is being created
99+===========================================================
100+
101+When a user is requesting a new code import, they are the owner of the new
102+import branch. sometimes the user may wish for the import branch to be owned
103+by a team rather than just themselves. There is a drop down choice shown for
104+the user for the teams that they are a member of.
105+
106+ >>> sample_browser = setupBrowser(auth='Basic test@canonical.com:test')
107+ >>> sample_browser.open("http://code.launchpad.dev/firefox/+new-import")
108+ >>> sample_browser.getControl('Owner').displayValue
109+ ['Sample Person (name12)']
110+
111+Change the owner to be a team that sample person is a member of.
112+
113+ >>> sample_browser.getControl('Owner').value = ['landscape-developers']
114+ >>> sample_browser.getControl('Owner').displayValue
115+ ['Landscape Developers (landscape-developers)']
116+ >>> sample_browser.getControl('Branch URL').value = (
117+ ... "http://svn.example.com/firefox-beta/trunk")
118+ >>> sample_browser.getControl('Request Import').click()
119+
120+ >>> print_tag_with_id(sample_browser.contents, 'registration')
121+ Created by Sample Person ...
122+ >>> print_tag_with_id(sample_browser.contents, 'owner')
123+ Owner: Landscape Developers
124+
125+Admins can specify any owner for a new code import.
126+
127+ >>> admin_browser = setupBrowser(auth='Basic admin@canonical.com:test')
128+ >>> admin_browser.open("http://code.launchpad.dev/firefox/+new-import")
129+ >>> admin_browser.getControl('Owner').value = 'mark'
130+ >>> admin_browser.getControl('Branch URL').value = (
131+ ... "http://svn.example.com/firefox-theta/trunk")
132+ >>> admin_browser.getControl('Request Import').click()
133+
134+ >>> print_tag_with_id(admin_browser.contents, 'registration')
135+ Created by Foo Bar ...
136+ >>> print_tag_with_id(admin_browser.contents, 'owner')
137+ Owner: Mark Shuttleworth
138
139=== modified file 'lib/lp/code/templates/codeimport-new.pt'
140--- lib/lp/code/templates/codeimport-new.pt 2010-01-20 03:19:44 +0000
141+++ lib/lp/code/templates/codeimport-new.pt 2010-04-23 01:24:23 +0000
142@@ -30,6 +30,9 @@
143
144 <table class="form">
145
146+ <tal:widget define="widget nocall:view/widgets/owner">
147+ <metal:block use-macro="context/@@launchpad_form/widget_row" />
148+ </tal:widget>
149 <tal:show-product condition="not: view/context_is_product">
150 <tal:widget define="widget nocall:view/widgets/product">
151 <metal:block use-macro="context/@@launchpad_form/widget_row" />