Merge lp:~beuno/canonical-identity-provider/u1embeddeable into lp:canonical-identity-provider/release

Proposed by Martin Albisetti
Status: Rejected
Rejected by: Martin Albisetti
Proposed branch: lp:~beuno/canonical-identity-provider/u1embeddeable
Merge into: lp:canonical-identity-provider/release
Diff against target: 253 lines (+84/-3)
8 files modified
django_project/config_dev/config/devel.cfg (+1/-0)
django_project/config_dev/config/main.cfg (+2/-0)
identityprovider/context_processors.py (+13/-0)
identityprovider/middleware/u1embedded.py (+22/-0)
identityprovider/templates/registration/new_account.html (+12/-0)
identityprovider/templates/ubuntu/base.html (+4/-1)
identityprovider/templates/ubuntu/registration/login.html (+13/-2)
identityprovider/tests/unit/test_middleware.py (+17/-0)
To merge this branch: bzr merge lp:~beuno/canonical-identity-provider/u1embeddeable
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Needs Fixing
Review via email: mp+116922@code.launchpad.net

Commit message

Add a UI for U1 to embed in its site.

Description of the change

Add a UI for U1 to embed in its site.

To post a comment you must log in.
463. By Martin Albisetti

Fix failing test

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

No approved revision specified.

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

l.91: no need to return None (it's the default)
l.124: please mark strings for translation and add some validation for the checkbox

review: Needs Fixing
464. By Martin Albisetti

Address review comments

Revision history for this message
Martin Albisetti (beuno) wrote :

> l.91: no need to return None (it's the default)
> l.124: please mark strings for translation and add some validation for the
> checkbox

Addressed and pushed

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

Only one extra request before approving

l. 30, 60, 100, 145, 187: these are unnecessary changes, please revert them
l. 74-90: why not put everything in process_request directly?
l. 76-78: it might be clearer to do something like

u1embedded = getattr(request, 'GET', {}).get('u1embedded')
if u1embedded is not None:
    try:
        value = bool(int(u1embedded))
    except ValueError:
        value = False

review: Needs Fixing
Revision history for this message
Martin Albisetti (beuno) wrote :

> Only one extra request before approving
>
> l. 30, 60, 100, 145, 187: these are unnecessary changes, please revert them
> l. 74-90: why not put everything in process_request directly?
> l. 76-78: it might be clearer to do something like
>
> u1embedded = getattr(request, 'GET', {}).get('u1embedded')
> if u1embedded is not None:
> try:
> value = bool(int(u1embedded))
> except ValueError:
> value = False

Pushed.

465. By Martin Albisetti

Review comments 2

466. By Martin Albisetti

Fix failing test

Unmerged revisions

466. By Martin Albisetti

Fix failing test

465. By Martin Albisetti

Review comments 2

464. By Martin Albisetti

Address review comments

463. By Martin Albisetti

Fix failing test

462. By Martin Albisetti

Add a test

461. By Martin Albisetti

Un-break the non-u1embedded site!

460. By Martin Albisetti

Make log in work for u1embedded

459. By Martin Albisetti

Strip the sign-up template of everything we dont want

458. By Martin Albisetti

Add in the context processor

457. By Martin Albisetti

Add the middleware to check for the GET parameter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_project/config_dev/config/devel.cfg'
2--- django_project/config_dev/config/devel.cfg 2012-07-23 19:35:42 +0000
3+++ django_project/config_dev/config/devel.cfg 2012-08-31 20:24:37 +0000
4@@ -45,6 +45,7 @@
5 django.middleware.locale.LocaleMiddleware
6 identityprovider.middleware.exception.LogExceptionMiddleware
7 raven.contrib.django.middleware.Sentry404CatchMiddleware
8+ identityprovider.middleware.u1embedded.DetectEmbedded
9 # Uncomment this to enable profiling middleware
10 # identityprovider.middleware.profile.ProfileMiddleware
11 # allow cookies to be stored when accessing via http
12
13=== modified file 'django_project/config_dev/config/main.cfg'
14--- django_project/config_dev/config/main.cfg 2012-08-13 15:20:18 +0000
15+++ django_project/config_dev/config/main.cfg 2012-08-31 20:24:37 +0000
16@@ -71,6 +71,7 @@
17 django.middleware.locale.LocaleMiddleware
18 identityprovider.middleware.exception.LogExceptionMiddleware
19 raven.contrib.django.middleware.Sentry404CatchMiddleware
20+ identityprovider.middleware.u1embedded.DetectEmbedded
21 # Uncomment this to enable profiling middleware
22 # identityprovider.middleware.profile.ProfileMiddleware
23 secret_key =
24@@ -91,6 +92,7 @@
25 identityprovider.context_processors.branding
26 django.core.context_processors.request
27 identityprovider.context_processors.detect_embedded
28+ identityprovider.context_processors.is_u1_embedded
29 identityprovider.context_processors.google_analytics_id
30 template_debug = %(debug)s
31 template_dirs =
32
33=== modified file 'identityprovider/context_processors.py'
34--- identityprovider/context_processors.py 2011-11-21 19:38:32 +0000
35+++ identityprovider/context_processors.py 2012-08-31 20:24:37 +0000
36@@ -55,6 +55,19 @@
37 result = {'embedded': embedded_trust_root == trust_root}
38 return result
39
40+def is_u1_embedded(request):
41+ """Whether we're in u1-embedded mode."""
42+ # "embedded" is already used in detect_embedded, we just add a U1-specific
43+ # variable to customise it even further
44+
45+ try:
46+ embed = bool(request.session.get('u1embedded'))
47+ # In tests you may not have a session
48+ except AttributeError:
49+ embed = False
50+ return {'embedded': embed,
51+ 'u1embedded': embed}
52+
53 def google_analytics_id(request):
54 """Adds the google analytics id to the context if it's present."""
55 return {
56
57=== added file 'identityprovider/middleware/u1embedded.py'
58--- identityprovider/middleware/u1embedded.py 1970-01-01 00:00:00 +0000
59+++ identityprovider/middleware/u1embedded.py 2012-08-31 20:24:37 +0000
60@@ -0,0 +1,22 @@
61+"""Middleware to remove headers and footers from the templates for Ubuntu One."""
62+# Copyright 2012 Canonical Ltd. This software is licensed under the
63+# GNU Affero General Public License version 3 (see the file LICENSE).
64+
65+
66+class DetectEmbedded(object):
67+ """Middleware that checks for a GET parameter to disable headers/footers"""
68+
69+ def process_request(self, request):
70+ """Process requests to set or unset the session to remove the headers
71+ and footers."""
72+ value = False
73+ u1embedded = getattr(request, 'GET', {}).get('u1embedded')
74+ if u1embedded is not None:
75+ try:
76+ value = bool(int(u1embedded))
77+ except ValueError:
78+ value = False
79+ if hasattr(request, "session"):
80+ if request.session.get('u1embedded') != value:
81+ request.session['u1embedded'] = value
82+
83
84=== modified file 'identityprovider/templates/registration/new_account.html'
85--- identityprovider/templates/registration/new_account.html 2012-05-24 13:32:45 +0000
86+++ identityprovider/templates/registration/new_account.html 2012-08-31 20:24:37 +0000
87@@ -19,12 +19,14 @@
88 {% endblock %}
89
90 {% block text_title %}
91+{% if not u1embedded %}
92 {% if rpconfig %}
93 <div id='rpconfig_logo'>
94 <img src='{{ rpconfig.logo_url }}'/>
95 </div>
96 {% endif %}
97 <h1 class="main">{{ brand.create_account }}</h1>
98+{% endif %}
99 {% endblock %}
100
101 {% block content_id %}auth{% endblock %}
102@@ -63,9 +65,19 @@
103 {% if old %}
104 <input type="hidden" name="old" value="old">
105 {% endif %}
106+ {% if not u1embedded %}
107 <button type="submit" class="btn" name="continue"><span><span>{% trans "Continue" %}</span></span></button>
108 {% trans "or" %}
109 <a href=".">{% trans "cancel" %}</a>
110+ {% else %}
111+ <p>
112+ <input type="checkbox" name="u1_tos" id="u1_tos" value="agree" />{% trans "I agree to the Ubuntu One" %}
113+ <a href="https://one.ubuntu.com/terms/" target="_blank">{% trans "terms and conditions." %}</a>
114+ </p>
115+ <p>
116+ <button type="submit" class="btn" name="continue"><span><span>{% trans "Sign up now" %}</span></span></button>
117+ </p>
118+ {% endif %}
119 </p>
120 </form>
121 <script type="text/javascript">
122
123=== modified file 'identityprovider/templates/ubuntu/base.html'
124--- identityprovider/templates/ubuntu/base.html 2012-03-06 11:06:06 +0000
125+++ identityprovider/templates/ubuntu/base.html 2012-08-31 20:24:37 +0000
126@@ -50,10 +50,10 @@
127 <body {% block bodyclass %}class="onecol"{% endblock %} {% if embedded %}onload="blank_targets()"{% endif %}>
128 <div id="container">
129 <div id="container-inner">
130+ {% if not u1embedded %}
131 <div id="header">
132 <h1 id="ubuntu-header">{% if not embedded %}<a href="/">{% trans "Ubuntu Single Sign On" %}</a>{% endif %}</h1>
133 </div>
134-
135 {% block menu %}
136 <div id="subheader">
137 <div class="subheader-menu">
138@@ -65,6 +65,7 @@
139 </div>
140 </div>
141 {% endblock %}
142+ {% endif %}
143
144 <div id="title">{% block text_title %}{% endblock %}</div>
145
146@@ -102,6 +103,7 @@
147
148 <div id="footer-logo"><a href="{% if not embedded %}http://www.ubuntu.com{% endif %}"></a></div>
149
150+ {% if not u1embedded %}
151 <div id="copyright">
152 <p>{% blocktrans %}&copy; 2009-2011 Canonical Ltd.
153 <a href="https://launchpad.net/canonical-identity-provider">Source code for this service</a> is licensed under the <a href="http://www.gnu.org/licenses/agpl-3.0.html">AGPL</a>.<br />
154@@ -127,5 +129,6 @@
155
156 </script>
157 {% endif %}
158+ {% endif %}
159 </body>
160 </html>
161
162=== modified file 'identityprovider/templates/ubuntu/registration/login.html'
163--- identityprovider/templates/ubuntu/registration/login.html 2012-02-21 18:39:20 +0000
164+++ identityprovider/templates/ubuntu/registration/login.html 2012-08-31 20:24:37 +0000
165@@ -25,18 +25,21 @@
166
167 {% block leftcol %}
168 <div id="auth">
169+{% if not u1embedded %}
170 {% if rpconfig %}
171 {% include "widgets/trusted_rp.html" %}
172 {% else %}
173 <h2 class="main">{% blocktrans %}Log in to Ubuntu Single Sign On{% endblocktrans %}</h2>
174 {% endif %}
175
176+
177 <div id="auth-text">
178 <p>
179 {% blocktrans %}Please note that if you've registered with Launchpad you can use your existing Launchpad credentials to log in.{% endblocktrans %}
180 </p>
181 </div>
182
183+{% endif %}
184 <form action="{{ login_path }}" method="post"
185 id="login-form" name="loginform">
186 {% csrf_token %}
187@@ -82,7 +85,13 @@
188
189 <div class="actions">
190 {% if next %}<input type="hidden" name="next" value="{{ next }}" />{% endif %}
191- <button type="submit" class="btn" name="continue"><span><span>{% trans "Continue" %}</span></span></button>
192+ <button type="submit" class="btn" name="continue"><span><span>
193+ {% if not u1embedded %}
194+ {% trans "Continue" %}
195+ {% else %}
196+ {% trans "Log in" %}
197+ {% endif %}
198+ </span></span></button>
199 {% if token %}{% trans "or" %}
200 {% if rpconfig %}
201 <a href="+cancel">{% blocktrans with rpconfig_name=rpconfig.displayname %}go back to {{ rpconfig_name }}{% endblocktrans %}</a>
202@@ -101,11 +110,12 @@
203 {% endblock %}
204
205 {% block rightcol %}
206+{% if not u1embedded %}
207 <h2 class="main">{% trans "Are you new?" %}</h2>
208 <p>
209 {% blocktrans %}This is a new service to provide a single, central login service for all Ubuntu-related sites.{% endblocktrans %}
210 </p>
211-{%if not embedded %}
212+{% if not embedded %}
213 <p class="findoutmore">
214 <a href="/+description">{% trans "Find out more" %}</a>
215 </p>
216@@ -118,4 +128,5 @@
217 <a href="+new_account{% if form.email.data %}?email={{ form.email.data|urlencode }}{% endif %}" class="btn alt"><span><span>{% trans "New account" %}</span></span></a>
218 </p>
219 {% endif %}
220+{% endif %}
221 {% endblock %}
222
223=== modified file 'identityprovider/tests/unit/test_middleware.py'
224--- identityprovider/tests/unit/test_middleware.py 2012-02-29 18:48:14 +0000
225+++ identityprovider/tests/unit/test_middleware.py 2012-08-31 20:24:37 +0000
226@@ -18,6 +18,7 @@
227 from identityprovider.middleware import exception, util as middleware_util
228 from identityprovider.middleware.useraccount import (
229 UserAccountConversionMiddleware)
230+from identityprovider.middleware.u1embedded import DetectEmbedded
231 from identityprovider.models import Account, EmailAddress, OpenIDRPConfig
232 from identityprovider.tests.utils import MockRequest, SSOBaseTestCase
233 from identityprovider.views import testing as test_views
234@@ -357,3 +358,19 @@
235 # We *must not* have a CSRF token on the form that submits
236 # to the RP.
237 self.assertEquals(_extract_csrf_token(r), None)
238+
239+
240+class TestDetectEmbedded(TestCase):
241+ """Test that session setting is correct."""
242+
243+ def test_u1embedded_process_request(self):
244+ request = MockRequest('/login')
245+ request.GET = {}
246+ request.META = {'SERVER_NAME': 'localhost', 'SERVER_PORT': 80}
247+
248+ val = DetectEmbedded().process_request(request)
249+ self.assertFalse(val)
250+
251+ request.GET['u1embedded'] = 1
252+ val = DetectEmbedded().process_request(request)
253+ self.assertTrue(val)