Merge lp:~canonical-isd-hackers/canonical-identity-provider/web_api-captchas into lp:~canonical-isd-hackers/canonical-identity-provider/web_api

Proposed by David Owen
Status: Work in progress
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/web_api-captchas
Merge into: lp:~canonical-isd-hackers/canonical-identity-provider/web_api
Prerequisite: lp:~canonical-isd-hackers/canonical-identity-provider/web_api-root
Diff against target: 160 lines (+79/-17)
5 files modified
identityprovider/webservice/models.py (+1/-11)
identityprovider/webservice/urlinfo.py (+4/-0)
identityprovider/webservice/urls.py (+4/-1)
identityprovider/webservice/views.py (+69/-5)
identityprovider/wsgi.py (+1/-0)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/web_api-captchas
Reviewer Review Type Date Requested Status
Canonical ISD hackers Pending
Review via email: mp+48199@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identityprovider/webservice/models.py'
2--- identityprovider/webservice/models.py 2011-01-20 21:27:57 +0000
3+++ identityprovider/webservice/models.py 2011-02-01 18:39:15 +0000
4@@ -352,17 +352,7 @@
5
6 class CaptchaSet(make_set('BaseCaptchaSet', 'captchas', ICaptchaSet,
7 Captcha, 'id')):
8- def new(self):
9- request = get_current_browser_request()
10- try:
11- return CaptchaModel.new().serialize()
12- except NewCaptchaError, e:
13- request.environment['oops-dump'] = True
14- logging.warning(e.traceback)
15- logging.warning("Failed to connect to reCaptcha server")
16- # TODO: Some better return here?
17- return e.dummy
18-
19+ pass
20
21
22 class SSOWebServiceRootResource(RootResource):
23
24=== added file 'identityprovider/webservice/urlinfo.py'
25--- identityprovider/webservice/urlinfo.py 1970-01-01 00:00:00 +0000
26+++ identityprovider/webservice/urlinfo.py 2011-02-01 18:39:15 +0000
27@@ -0,0 +1,4 @@
28+# Copyright 2010 Canonical Ltd. This software is licensed under the
29+# GNU Affero General Public License version 3 (see the file LICENSE).
30+
31+CAPTCHAS_VIEW = "api_captchas"
32
33=== modified file 'identityprovider/webservice/urls.py'
34--- identityprovider/webservice/urls.py 2011-02-01 18:39:14 +0000
35+++ identityprovider/webservice/urls.py 2011-02-01 18:39:15 +0000
36@@ -7,7 +7,10 @@
37 from piston.resource import Resource
38
39 from . import views
40+from urlinfo import *
41
42
43 urlpatterns = patterns('identityprovider.webservice.views',
44- (r'^$', views.root))
45+ (r'^$', views.root),
46+ url(r'^captchas', views.CaptchasHandler(), name=CAPTCHAS_VIEW),
47+)
48
49=== modified file 'identityprovider/webservice/views.py'
50--- identityprovider/webservice/views.py 2011-02-01 18:39:14 +0000
51+++ identityprovider/webservice/views.py 2011-02-01 18:39:15 +0000
52@@ -3,7 +3,11 @@
53 from django.conf import settings
54 from django.contrib.auth.decorators import login_required
55 from django.core.urlresolvers import reverse
56-from django.http import HttpResponse, HttpResponseRedirect
57+from django.http import (
58+ HttpResponse,
59+ HttpResponseRedirect,
60+ HttpResponseNotAllowed,
61+)
62 from django.shortcuts import render_to_response, get_object_or_404
63 from django.template import RequestContext
64 from django.utils.translation import ugettext as _
65@@ -13,11 +17,13 @@
66 import simplejson as json
67
68 from identityprovider.auth import basic_authenticate, oauth_authenticate
69-from identityprovider.models.captcha import Captcha
70+from identityprovider.models.captcha import Captcha, NewCaptchaError
71+from urlinfo import *
72
73
74 def is_wadl_request(request):
75- wadl_accept = set(['application/vnd.sun.wadl+xml', 'application/vd.sun.wadl+xml'])
76+ wadl_accept = set(['application/vnd.sun.wadl+xml',
77+ 'application/vd.sun.wadl+xml'])
78 accept = set([s.strip() for s in request.META['HTTP_ACCEPT'].split(',')])
79 return not accept.isdisjoint(wadl_accept)
80
81@@ -42,8 +48,66 @@
82
83 return JsonResponse({
84 "registrations_collection_link": "http://openid.launchpad.dev/api/1.0/registration",
85- "captchas_collection_link": "http://openid.launchpad.dev/api/1.0/captchas",
86+ "captchas_collection_link": api_reverse(request, CAPTCHAS_VIEW),
87 "validations_collection_link": "http://openid.launchpad.dev/api/1.0/validation",
88 "authentications_collection_link": "http://openid.launchpad.dev/api/1.0/authentications",
89- "resource_type_link": api_reverse(request, root, fragment="#service-root"),
90+ "resource_type_link": api_reverse(
91+ request, root, fragment="#service-root"),
92 "accounts_collection_link": "http://openid.launchpad.dev/api/1.0/accounts"})
93+
94+
95+# def get(request, unique_id):
96+# """Retrieve a captcha by its ID."""
97+
98+#class CaptchaSet(make_set('BaseCaptchaSet', 'captchas', ICaptchaSet,
99+# Captcha, 'id')):
100+
101+
102+class NotAllowed(Exception):
103+ pass
104+
105+
106+class JsonHandler(object):
107+
108+ def _not_allowed(self, request):
109+ raise NotAllowed()
110+
111+ delete = _not_allowed
112+ get = _not_allowed
113+ post = _not_allowed
114+ put = _not_allowed
115+
116+ verbs = ["delete", "get", "post", "put"]
117+
118+ def __call__(self, request):
119+ method = request.method.lower()
120+ if method in self.verbs:
121+ try:
122+ return JsonResponse(getattr(self, method)(request))
123+ except NotAllowed:
124+ pass
125+ allowed = [v.upper() for v in self.verbs
126+ if getattr(self, v) != self._not_allowed]
127+ return HttpResponseNotAllowed(allowed)
128+
129+
130+class CaptchasHandler(JsonHandler):
131+
132+ def get(self, request):
133+ # Theoretically, this should be returning lists of captchas.
134+ # I don't think it's actually used, though.
135+ return {
136+ "total_size": 0,
137+ "start": None,
138+ "resource_type_link": api_reverse(
139+ request, root, fragment="#captchas"),
140+ "entries": []}
141+
142+ def post(self, request):
143+ try:
144+ return Captcha.new().serialize()
145+ except NewCaptchaError, e:
146+ logging.warning(e.traceback)
147+ logging.warning("Failed to connect to reCaptcha server")
148+ # TODO: Some better return here?
149+ return e.dummy
150
151=== modified file 'identityprovider/wsgi.py'
152--- identityprovider/wsgi.py 2011-02-01 18:39:14 +0000
153+++ identityprovider/wsgi.py 2011-02-01 18:39:15 +0000
154@@ -90,6 +90,7 @@
155
156 dispatch = WSGIDispatch(
157 [(r'^/api/1.0/?$', django),
158+ (r'^/api/1.0/captchas', django),
159 (r'^/api/1.0', api)],
160 django)
161

Subscribers

People subscribed via source and target branches

to all changes: