Merge ~twom/launchpad:codeimport-url-setters into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 35a3b8af62eacdf54766b10aa6049b9461d5b786
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:codeimport-url-setters
Merge into: launchpad:master
Diff against target: 81 lines (+22/-5)
5 files modified
lib/lp/code/browser/codeimport.py (+2/-3)
lib/lp/code/configure.zcml (+2/-1)
lib/lp/code/doc/codeimport.txt (+1/-1)
lib/lp/code/interfaces/codeimport.py (+11/-0)
lib/lp/code/model/codeimport.py (+6/-0)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+386241@code.launchpad.net

Commit message

Use a separate setter for URL that calls into updateFromData

Description of the change

We want to allow URL on a codeimport to be set by a user with lower permissions than the other attributes, but still keep the same code flow of notifications, format checks etc.

Add an extra setter for URL (and only URL) with the new permissions, then call updateFromData to ensure everything else is correct.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

makes sense to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/browser/codeimport.py b/lib/lp/code/browser/codeimport.py
2index 8516afe..dfee026 100644
3--- a/lib/lp/code/browser/codeimport.py
4+++ b/lib/lp/code/browser/codeimport.py
5@@ -570,9 +570,8 @@ def _makeEditAction(label, status, text):
6 'The code import has been ' + text + '.')
7 elif self._is_edit_user and "url" in data:
8 # Edit users can only change URL
9- new_url = data["url"]
10- if self.code_import.url != new_url:
11- self.code_import.url = new_url
12+ event = self.code_import.updateURL(data["url"], self.user)
13+ if event is not None:
14 self.request.response.addNotification(
15 'The code import URL has been updated.')
16 else:
17diff --git a/lib/lp/code/configure.zcml b/lib/lp/code/configure.zcml
18index 09d5011..898e645 100644
19--- a/lib/lp/code/configure.zcml
20+++ b/lib/lp/code/configure.zcml
21@@ -658,7 +658,8 @@
22 getImportDetailsForDisplay"/>
23 <require
24 permission="launchpad.Edit"
25- set_attributes="url"/>
26+ attributes="updateURL"/>
27+
28 <require
29 permission="launchpad.AnyPerson"
30 attributes="tryFailingImportAgain
31diff --git a/lib/lp/code/doc/codeimport.txt b/lib/lp/code/doc/codeimport.txt
32index 6d6dc3e..feea404 100644
33--- a/lib/lp/code/doc/codeimport.txt
34+++ b/lib/lp/code/doc/codeimport.txt
35@@ -497,7 +497,7 @@ The launchpad.Edit privilege is required to use CodeImport.updateFromData.
36 >>> svn_import.updateFromData({}, nopriv)
37 Traceback (most recent call last):
38 ...
39- Unauthorized: (<CodeImport ...>, 'updateFromData', 'launchpad.Edit')
40+ Unauthorized: (<CodeImport ...>, 'updateFromData', 'launchpad.Moderate')
41
42 We saw above how changes to SVN details are displayed in emails above.
43 CVS details are displayed in a similar way.
44diff --git a/lib/lp/code/interfaces/codeimport.py b/lib/lp/code/interfaces/codeimport.py
45index 7386e6b..3a54c3a 100644
46--- a/lib/lp/code/interfaces/codeimport.py
47+++ b/lib/lp/code/interfaces/codeimport.py
48@@ -192,6 +192,17 @@ class ICodeImport(Interface):
49 None if no changes were made.
50 """
51
52+ def updateURL(new_url, user):
53+ """Update the URL for this `CodeImport`.
54+
55+ A separate setter as it has lower permissions than updateFromData.
56+ :param new_url: string of the proposed new URL.
57+ :param user: user who made the change, to record in the
58+ `CodeImportEvent`. May be ``None``.
59+ :return: The MODIFY `CodeImportEvent`, if any changes were made, or
60+ None if no changes were made.
61+ """
62+
63 def tryFailingImportAgain(user):
64 """Try a failing import again.
65
66diff --git a/lib/lp/code/model/codeimport.py b/lib/lp/code/model/codeimport.py
67index eab7d42..95d0b99 100644
68--- a/lib/lp/code/model/codeimport.py
69+++ b/lib/lp/code/model/codeimport.py
70@@ -250,6 +250,12 @@ class CodeImport(StormBase):
71 code_import_updated(self, event, new_whiteboard, user)
72 return event
73
74+ def updateURL(self, new_url, user):
75+ if self.url != new_url:
76+ data = {"url": new_url}
77+ event = self.updateFromData(data, user)
78+ return event
79+
80 def __repr__(self):
81 return "<CodeImport for %s>" % self.target.unique_name
82

Subscribers

People subscribed via source and target branches

to status/vote changes: