Merge lp:~sinzui/launchpad/api-bug-tracker-0 into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Edwin Grubbs
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~sinzui/launchpad/api-bug-tracker-0
Merge into: lp:launchpad
Diff against target: 164 lines (+106/-1)
3 files modified
lib/canonical/launchpad/security.py (+5/-0)
lib/lp/bugs/interfaces/bugtracker.py (+24/-1)
lib/lp/bugs/stories/webservice/xx-bug-tracker.txt (+77/-0)
To merge this branch: bzr merge lp:~sinzui/launchpad/api-bug-tracker-0
Reviewer Review Type Date Requested Status
Edwin Grubbs (community) code Approve
Review via email: mp+21061@code.launchpad.net

Description of the change

This is my branch to export bugtrackerset over the api.

    lp:~sinzui/launchpad/api-bug-tracker-0
    Diff size: 129
    Launchpad bug: https://bugs.launchpad.net/bugs/id
    Test command: ./bin/test -vv \
        -t webservice/xx-bug-tracker
    Pre-implementation: Edwin
    Target release: 10.03

Export bugtrackerset over the api
---------------------------------

Export the bugtrackerset of the api so that ensureBugTracker() can be
used in API operations. We want a formoverlay to register an new bugtracker
when user discovers that the bug tracker he wants to set to the project is
not registered.

Rules
-----

    * Export IBugTrackerSet and ensureBugTracker

QA
--

    * Verify that you can get the IBugTrackerSet via anonymous api
    * Verify that you can use ensureBugTracker() to register a tracker
      logged in.

Lint
----

Linting changed files:
  lib/canonical/launchpad/security.py
  lib/lp/bugs/interfaces/bugtracker.py
  lib/lp/bugs/stories/webservice/xx-bug-tracker.txt

Test
----

    * lib/lp/bugs/stories/webservice/xx-bug-tracker.txt
      * Added tests to verify that IBugTrakerSet is exported for anonymous
        Use. Added a test to verify that ensureBugTracker can create a
        new bugtracker.

Implementation
--------------

    * lib/canonical/launchpad/security.py
      * Added a security checker for IBugTracker to ensure anonymous users
        can see them.
    * lib/lp/bugs/interfaces/bugtracker.py
      * Exported IbugTrackerSet with search and ensureBugTracker methods.

To post a comment you must log in.
Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

Hi Curtis,

This branch looks good. Just one comment below.

merge-conditional

-Edwin

>=== added file 'lib/lp/bugs/stories/webservice/xx-bug-tracker.txt'
>--- lib/lp/bugs/stories/webservice/xx-bug-tracker.txt>*1970-01-01 00:00:00 +0000
>+++ lib/lp/bugs/stories/webservice/xx-bug-tracker.txt>*2010-03-10 16:34:01 +0000
>@@ -0,0 +1,62 @@
>+Bug tracker
>+===========
>+
>+The bug tracker set is exported as a collection at /bugs/bugtrackers that
>+any user can access.
>+
>+ >>> from lazr.restful.testing.webservice import (
>+ ... pprint_collection, pprint_entry)
>+
>+ >>> bug_tracker_collection = anon_webservice.get(
>+ ... '/bugs/bugtrackers').jsonBody()
>+ >>> pprint_collection(bug_tracker_collection)
>+ next_collection_link:
>+ u'http://api.launchpad.dev/beta/bugs/bugtrackers?ws.start=5&ws.size=5'

Normally, "api.launchpad.dev/beta" is replaced with "..." so that the test doesn't break when the default version changes.
Please replace all the other instances also.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/security.py'
2--- lib/canonical/launchpad/security.py 2010-03-10 00:46:20 +0000
3+++ lib/canonical/launchpad/security.py 2010-03-10 19:03:28 +0000
4@@ -1297,6 +1297,11 @@
5 user.inTeam(translation_group.owner)))
6
7
8+class ViewBugTracker(AnonymousAuthorization):
9+ """Anyone can view a bug tracker."""
10+ usedfor = IBugTracker
11+
12+
13 class EditBugTracker(AuthorizationBase):
14 permission = 'launchpad.Edit'
15 usedfor = IBugTracker
16
17=== modified file 'lib/lp/bugs/interfaces/bugtracker.py'
18--- lib/lp/bugs/interfaces/bugtracker.py 2009-12-25 16:36:53 +0000
19+++ lib/lp/bugs/interfaces/bugtracker.py 2010-03-10 19:03:28 +0000
20@@ -32,7 +32,10 @@
21
22 from lazr.lifecycle.snapshot import doNotSnapshot
23 from lazr.restful.declarations import (
24- export_as_webservice_entry, exported)
25+ call_with, collection_default_content, export_as_webservice_collection,
26+ export_as_webservice_entry, export_factory_operation,
27+ export_read_operation, exported, operation_parameters,
28+ operation_returns_entry, rename_parameters_as, REQUEST_USER)
29 from lazr.restful.fields import CollectionField, Reference
30
31
32@@ -325,6 +328,7 @@
33 Each BugTracker is a distinct instance of a bug tracking tool. For
34 example, bugzilla.mozilla.org is distinct from bugzilla.gnome.org.
35 """
36+ export_as_webservice_collection(IBugTracker)
37
38 title = Attribute('Title')
39
40@@ -336,6 +340,10 @@
41 If no tracker with the given id exists, return default.
42 """
43
44+ @operation_parameters(
45+ name=TextLine(title=u"The bug tracker name", required=True))
46+ @operation_returns_entry(IBugTracker)
47+ @export_read_operation()
48 def getByName(name, default=None):
49 """Get a BugTracker by its name.
50
51@@ -352,9 +360,23 @@
52 def __iter__():
53 """Iterate through BugTrackers."""
54
55+ @rename_parameters_as(baseurl='base_url')
56+ @operation_parameters(
57+ baseurl=TextLine(
58+ title=u"The base URL of the bug tracker", required=True))
59+ @operation_returns_entry(IBugTracker)
60+ @export_read_operation()
61 def queryByBaseURL(baseurl):
62 """Return one or None BugTracker's by baseurl"""
63
64+ @call_with(owner=REQUEST_USER)
65+ @rename_parameters_as(
66+ baseurl='base_url', bugtrackertype='bug_tracker_type',
67+ contactdetails='contat_details')
68+ @export_factory_operation(
69+ IBugTracker,
70+ ['baseurl', 'bugtrackertype', 'title', 'summary',
71+ 'contactdetails', 'name'])
72 def ensureBugTracker(baseurl, owner, bugtrackertype,
73 title=None, summary=None, contactdetails=None, name=None):
74 """Make sure that there is a bugtracker for the given base url.
75@@ -362,6 +384,7 @@
76 If not, create one using the given attributes.
77 """
78
79+ @collection_default_content()
80 def search():
81 """Search all the IBugTrackers in the system."""
82
83
84=== added file 'lib/lp/bugs/stories/webservice/xx-bug-tracker.txt'
85--- lib/lp/bugs/stories/webservice/xx-bug-tracker.txt 1970-01-01 00:00:00 +0000
86+++ lib/lp/bugs/stories/webservice/xx-bug-tracker.txt 2010-03-10 19:03:28 +0000
87@@ -0,0 +1,77 @@
88+Bug tracker
89+===========
90+
91+The bug tracker set is exported as a collection at /bugs/bugtrackers that
92+any user can access.
93+
94+ >>> from lazr.restful.testing.webservice import (
95+ ... pprint_collection, pprint_entry)
96+
97+ >>> bug_tracker_collection = anon_webservice.get(
98+ ... '/bugs/bugtrackers').jsonBody()
99+ >>> pprint_collection(bug_tracker_collection)
100+ next_collection_link: u'http://.../bugs/bugtrackers?ws.start=5&ws.size=5'
101+ resource_type_link: u'http://.../#bug_trackers'
102+ start: 0
103+ total_size: 8
104+ ---
105+ active: True
106+ base_url: u'https://bugzilla.mozilla.org/'
107+ base_url_aliases: []
108+ bug_tracker_type: u'Bugzilla'
109+ contact_details: u'Carrier pigeon only'
110+ has_lp_plugin: None
111+ name: u'mozilla.org'
112+ registrant_link: u'http://.../~name12'
113+ resource_type_link: u'http://.../#bug_tracker'
114+ self_link: u'http://.../bugs/bugtrackers/mozilla.org'
115+ summary: u'The Mozilla.org bug tracker is the grand-daddy of ...'
116+ title: u'The Mozilla.org Bug Tracker'
117+ watches_collection_link: u'http:.../bugs/bugtrackers/mozilla.org/watches'
118+ --- ...
119+
120+A bug tracker can be retrieved using the the bug tracker collection's
121+getByName named operation.
122+
123+ >>> bug_tracker = anon_webservice.named_get(
124+ ... '/bugs/bugtrackers', 'getByName',
125+ ... name='gnome-bugzilla').jsonBody()
126+ >>> print bug_tracker['name']
127+ gnome-bugzilla
128+
129+A bug tracker can be retrieved using the the bug tracker collection's
130+queryByBaseURL named operation.
131+
132+ >>> bug_tracker = anon_webservice.named_get(
133+ ... '/bugs/bugtrackers', 'queryByBaseURL',
134+ ... base_url='https://bugzilla.mozilla.org/').jsonBody()
135+ >>> print bug_tracker['name']
136+ mozilla.org
137+
138+The bug tracker set provides the ensureBugTracker named operation that a
139+logged in user can call to create a bug tracker.
140+
141+ >>> params = dict(
142+ ... base_url='http://wombat.zz/', bug_tracker_type='Bugzilla',
143+ ... name='wombat', title='Wombat title', summary='Wombat summary',
144+ ... contact_details='big-nose@wombat.zz')
145+ >>> print webservice.named_post(
146+ ... '/bugs/bugtrackers', 'ensureBugTracker', **params)
147+ HTTP/1.1 201 Created ...
148+ Location: http://.../bugs/bugtrackers/wombat ...
149+
150+ >>> bug_tracker = webservice.get('/bugs/bugtrackers/wombat').jsonBody()
151+ >>> pprint_entry(bug_tracker)
152+ active: True
153+ base_url: u'http://wombat.zz/'
154+ base_url_aliases: []
155+ bug_tracker_type: u'Bugzilla'
156+ contact_details: None
157+ has_lp_plugin: False
158+ name: u'wombat'
159+ registrant_link: u'http://.../~salgado'
160+ resource_type_link: u'http://.../#bug_tracker'
161+ self_link: u'http://.../bugs/bugtrackers/wombat'
162+ summary: u'Wombat summary'
163+ title: u'Wombat title'
164+ watches_collection_link: u'http://.../bugs/bugtrackers/wombat/watches'