Merge lp:~jcsackett/launchpad/global-privacy-ribbon into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 13614
Proposed branch: lp:~jcsackett/launchpad/global-privacy-ribbon
Merge into: lp:launchpad
Diff against target: 381 lines (+118/-170)
7 files modified
lib/lp/app/javascript/privacy.js (+83/-91)
lib/lp/app/templates/base-layout-macros.pt (+15/-10)
lib/lp/bugs/javascript/bugtask_index.js (+13/-2)
lib/lp/bugs/templates/bugcomment-index.pt (+0/-16)
lib/lp/bugs/templates/bugtask-index.pt (+7/-18)
lib/lp/code/templates/branch-index.pt (+0/-17)
lib/lp/code/templates/branchmergeproposal-index.pt (+0/-16)
To merge this branch: bzr merge lp:~jcsackett/launchpad/global-privacy-ribbon
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+70327@code.launchpad.net

Commit message

Moves the privacy ribbon template code into the base-layout, so that is now active and available on all private contexts.

Description of the change

Summary
=======
After doing a lot of work to add the privacy notification code to various templates, it became clear that it's better to lose a bit of flexability in order to have the notification automatically displayed for any private context.

To do this, the privacy notification code had to be moved to the base layout javascript macros, and the privacy notification functions had to be altered a bit to deal with being less flexible in their invocation.

Pre-implementation notes
========================
Initially proposed by William Grant. There were subsequent discussions on what exactly the tradeoffs would be with Curtis Hovey.

Implementation details
======================
lib/lp/app/javascript/privacy.js
lib/lp/app/templates/base-layout-macros.pt
------------------------------------------
The base layout macros had the setup and display code added within a privacy feature flag. The javascript file was modified to remove the variable indicating whether or not the notification was enabled, as it's only in place at all if the feature flag is set. Some configuration was also removed, as the portlet-highlighting behavior is now automatic if a privacy portlet exists.

lib/lp/bugs/templates/bugtask-index.pt
lib/lp/code/templates/branch-index.pt
lib/lp/code/templates/branchmergeproposal-index.pt
lib/lp/bugs/templates/bugcomment-index.pt
-----------------------------------------
The templates have all had the individual setup and display calls removed.

Tests
=====
firefox lib/lp/app/javascript/tests/test_privacy.js

QA
==
Check all the various private contexts on Launchpad; with the flag set, they should be guarded by the new privacy notification. Without the flag, the ne new notification shouldn't appear. On public contexts, the notification should not display.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/code/templates/branchmergeproposal-index.pt
  lib/lp/bugs/templates/bugcomment-index.pt
  lib/lp/app/javascript/privacy.js
  lib/lp/app/templates/base-layout-macros.pt
  lib/lp/bugs/templates/bugtask-index.pt
  lib/lp/code/templates/branch-index.pt

./lib/lp/app/javascript/privacy.js
     134: Expected '!==' and instead saw '!='.

Lint will be cleaned before landing.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you for this refactoring. I think this implementation is less prone to human error and certainly easier to maintain.

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/app/javascript/privacy.js'
2--- lib/lp/app/javascript/privacy.js 2011-07-29 22:27:13 +0000
3+++ lib/lp/app/javascript/privacy.js 2011-08-04 14:23:45 +0000
4@@ -50,55 +50,48 @@
5 }
6 namespace.setup_privacy_notification = setup_privacy_notification;
7
8-function display_privacy_notification(highlight_portlet_on_close) {
9- /* Check if the feature flag is set for this notification. */
10- var highlight = true;
11- if (highlight_portlet_on_close !== undefined) {
12- highlight = highlight_portlet_on_close;
13- }
14- if (privacy_notification_enabled) {
15- /* Set a temporary class on the body for the feature flag,
16- this is because we have no way to use feature flags in
17- css directly. This should be removed if the feature
18- is accepted. */
19- var body = Y.one('body');
20- body.addClass('feature-flag-bugs-private-notification-enabled');
21- /* Set the visible flag so that the content moves down. */
22- body.addClass('global-notification-visible');
23-
24- var global_notification = Y.one('.global-notification');
25- if (global_notification.hasClass('hidden')) {
26- global_notification.addClass('transparent');
27- global_notification.removeClass('hidden');
28-
29- var fade_in = new Y.Anim({
30- node: global_notification,
31- to: {opacity: 1},
32- duration: 0.3
33- });
34- var body_space = new Y.Anim({
35- node: 'body',
36- to: {'paddingTop': '40px'},
37- duration: 0.2,
38- easing: Y.Easing.easeOut
39- });
40- var login_space = new Y.Anim({
41- node: '.login-logout',
42- to: {'top': '45px'},
43- duration: 0.2,
44- easing: Y.Easing.easeOut
45- });
46-
47- fade_in.run();
48- body_space.run();
49- login_space.run();
50- }
51-
52- Y.one('.global-notification-close').on('click', function(e) {
53- hide_privacy_notification(highlight);
54- e.halt();
55- });
56- }
57+function display_privacy_notification() {
58+ /* Set a temporary class on the body for the feature flag,
59+ this is because we have no way to use feature flags in
60+ css directly. This should be removed if the feature
61+ is accepted. */
62+ var body = Y.one('body');
63+ body.addClass('feature-flag-bugs-private-notification-enabled');
64+ /* Set the visible flag so that the content moves down. */
65+ body.addClass('global-notification-visible');
66+
67+ var global_notification = Y.one('.global-notification');
68+ if (global_notification.hasClass('hidden')) {
69+ global_notification.addClass('transparent');
70+ global_notification.removeClass('hidden');
71+
72+ var fade_in = new Y.Anim({
73+ node: global_notification,
74+ to: {opacity: 1},
75+ duration: 0.3
76+ });
77+ var body_space = new Y.Anim({
78+ node: 'body',
79+ to: {'paddingTop': '40px'},
80+ duration: 0.2,
81+ easing: Y.Easing.easeOut
82+ });
83+ var login_space = new Y.Anim({
84+ node: '.login-logout',
85+ to: {'top': '45px'},
86+ duration: 0.2,
87+ easing: Y.Easing.easeOut
88+ });
89+
90+ fade_in.run();
91+ body_space.run();
92+ login_space.run();
93+ }
94+
95+ Y.one('.global-notification-close').on('click', function(e) {
96+ hide_privacy_notification();
97+ e.halt();
98+ });
99 }
100 namespace.display_privacy_notification = display_privacy_notification;
101
102@@ -107,48 +100,47 @@
103 *
104 * This should be called after the page has loaded e.g. on 'domready'.
105 */
106-function hide_privacy_notification(highlight_portlet) {
107- if (privacy_notification_enabled) {
108- if (!Y.one('.global-notification').hasClass('hidden')) {
109- var fade_out = new Y.Anim({
110- node: '.global-notification',
111- to: {opacity: 0},
112- duration: 0.3
113- });
114- var body_space = new Y.Anim({
115- node: 'body',
116- to: {'paddingTop': 0},
117- duration: 0.2,
118- easing: Y.Easing.easeOut
119- });
120- var login_space = new Y.Anim({
121- node: '.login-logout',
122- to: {'top': '6px'},
123- duration: 0.2,
124- easing: Y.Easing.easeOut
125- });
126- fade_out.on('end', function() {
127- fade_out.get('node').addClass('hidden');
128- });
129- body_space.on('end', function() {
130- Y.one('body').removeClass('global-notification-visible');
131- });
132-
133- fade_out.run();
134- body_space.run();
135- login_space.run();
136-
137- if (highlight_portlet) {
138- var portlet_colour = new Y.Anim({
139- node: '.portlet.private',
140- to: {
141- color: '#fff',
142- backgroundColor:'#8d1f1f'
143- },
144- duration: 0.4
145- });
146- portlet_colour.run();
147- }
148+function hide_privacy_notification() {
149+ if (!Y.one('.global-notification').hasClass('hidden')) {
150+ var fade_out = new Y.Anim({
151+ node: '.global-notification',
152+ to: {opacity: 0},
153+ duration: 0.3
154+ });
155+ var body_space = new Y.Anim({
156+ node: 'body',
157+ to: {'paddingTop': 0},
158+ duration: 0.2,
159+ easing: Y.Easing.easeOut
160+ });
161+ var login_space = new Y.Anim({
162+ node: '.login-logout',
163+ to: {'top': '6px'},
164+ duration: 0.2,
165+ easing: Y.Easing.easeOut
166+ });
167+ fade_out.on('end', function() {
168+ fade_out.get('node').addClass('hidden');
169+ });
170+ body_space.on('end', function() {
171+ Y.one('body').removeClass('global-notification-visible');
172+ });
173+
174+ fade_out.run();
175+ body_space.run();
176+ login_space.run();
177+
178+ var privacy_portlet = Y.one('.portlet.private');
179+ if (privacy_portlet !== null) {
180+ var portlet_colour = new Y.Anim({
181+ node: privacy_portlet,
182+ to: {
183+ color: '#fff',
184+ backgroundColor:'#8d1f1f'
185+ },
186+ duration: 0.4
187+ });
188+ portlet_colour.run();
189 }
190 }
191 }
192
193=== modified file 'lib/lp/app/templates/base-layout-macros.pt'
194--- lib/lp/app/templates/base-layout-macros.pt 2011-07-29 14:32:45 +0000
195+++ lib/lp/app/templates/base-layout-macros.pt 2011-08-04 14:23:45 +0000
196@@ -106,16 +106,21 @@
197
198 <metal:load-lavascript use-macro="context/@@+base-layout-macros/load-javascript" />
199
200- <tal:if condition="request/features/bugs.private_notification.enabled">
201- <script type="text/javascript">
202- var privacy_notification_enabled = true;
203- </script>
204- </tal:if>
205- <tal:if condition="not:request/features/bugs.private_notification.enabled">
206- <script type="text/javascript">
207- var privacy_notification_enabled = false;
208- </script>
209- </tal:if>
210+ <tal:if condition="request/features/bugs.private_notification.enabled">
211+ <script type="text/javascript">
212+ LPS.use('base', 'node', 'oop', 'event', 'lp.bugs.bugtask_index',
213+ 'lp.bugs.subscribers',
214+ 'lp.code.branchmergeproposal.diff', 'lp.comments.hide',
215+ function(Y) {
216+ Y.on("domready", function () {
217+ if (Y.one(document.body).hasClass('private')) {
218+ Y.lp.app.privacy.setup_privacy_notification();
219+ Y.lp.app.privacy.display_privacy_notification();
220+ }
221+ });
222+ });
223+ </script>
224+ </tal:if>
225
226 <script id="base-layout-load-scripts" type="text/javascript">
227 LPS.use('node', 'event-delegate', 'lp', 'lp.app.links', 'lp.app.longpoll', function(Y) {
228
229=== modified file 'lib/lp/bugs/javascript/bugtask_index.js'
230--- lib/lp/bugs/javascript/bugtask_index.js 2011-07-29 20:17:56 +0000
231+++ lib/lp/bugs/javascript/bugtask_index.js 2011-08-04 14:23:45 +0000
232@@ -370,10 +370,19 @@
233 privacy_text.set(
234 'innerHTML',
235 'This report is <strong>private</strong> ');
236- Y.lp.app.privacy.display_privacy_notification();
237+ if (privacy_notification_enabled) {
238+ var notification = Y.one('.global-notification');
239+ if (notification === null) {
240+ Y.lp.app.privacy.setup_privacy_notification();
241+ }
242+ Y.lp.app.privacy.display_privacy_notification();
243+ }
244 } else {
245 if (privacy_notification_enabled) {
246 var notification = Y.one('.global-notification');
247+ if (notification === null) {
248+ Y.lp.app.privacy.setup_privacy_notification();
249+ }
250 if (notification.hasClass('hidden')) {
251 Y.one('.portlet.private').setStyles({
252 color: '#333',
253@@ -385,7 +394,9 @@
254 privacy_div.replaceClass('private', 'public');
255 privacy_text.set(
256 'innerHTML', 'This report is public ');
257- Y.lp.app.privacy.hide_privacy_notification();
258+ if (privacy_notification_enabled) {
259+ Y.lp.app.privacy.hide_privacy_notification();
260+ }
261 }
262 privacy_text.appendChild(privacy_link);
263 privacy_text.appendChild(privacy_spinner);
264
265=== modified file 'lib/lp/bugs/templates/bugcomment-index.pt'
266--- lib/lp/bugs/templates/bugcomment-index.pt 2011-07-29 21:53:43 +0000
267+++ lib/lp/bugs/templates/bugcomment-index.pt 2011-08-04 14:23:45 +0000
268@@ -8,22 +8,6 @@
269 >
270 <body>
271 <metal:block fill-slot="head_epilogue">
272- <tal:if condition="request/features/bugs.private_notification.enabled">
273- <script>
274- LPS.use('base', 'node', 'lp.app.privacy', function(Y) {
275- Y.on("domready", function () {
276- if (Y.one(document.body).hasClass('private')) {
277- var config = {
278- notification_text: 'This comment is on a private bug',
279- hidden: true
280- };
281- Y.lp.app.privacy.setup_privacy_notification(config);
282- Y.lp.app.privacy.display_privacy_notification(false);
283- }
284- });
285- });
286- </script>
287- </tal:if>
288 </metal:block>
289 <div metal:fill-slot="main" tal:define="comment view/comment">
290 <h1 tal:content="view/page_title">Foo doesn't work</h1>
291
292=== modified file 'lib/lp/bugs/templates/bugtask-index.pt'
293--- lib/lp/bugs/templates/bugtask-index.pt 2011-07-29 20:17:56 +0000
294+++ lib/lp/bugs/templates/bugtask-index.pt 2011-08-04 14:23:45 +0000
295@@ -36,24 +36,13 @@
296 </script>
297 <tal:if condition="request/features/bugs.private_notification.enabled">
298 <script type="text/javascript">
299- LPS.use('base', 'node', 'oop', 'event', 'lp.bugs.bugtask_index',
300- 'lp.bugs.subscribers',
301- 'lp.code.branchmergeproposal.diff', 'lp.comments.hide',
302- function(Y) {
303- /*
304- * Display the privacy notification if the bug is private
305- */
306- Y.on("domready", function () {
307- if (Y.one(document.body).hasClass('private')) {
308- var config = {
309- notification_text: 'This bug is private',
310- hidden: true
311- };
312- Y.lp.app.privacy.setup_privacy_notification(config);
313- Y.lp.app.privacy.display_privacy_notification();
314- }
315- });
316- });
317+ // We need to set up some bugtask
318+ var privacy_notification_enabled = true;
319+ </script>
320+ </tal:if>
321+ <tal:if condition="not: request/features/bugs.private_notification.enabled">
322+ <script type="text/javascript">
323+ var privacy_notification_enabled = false;
324 </script>
325 </tal:if>
326 <style type="text/css">
327
328=== modified file 'lib/lp/code/templates/branch-index.pt'
329--- lib/lp/code/templates/branch-index.pt 2011-08-01 16:05:59 +0000
330+++ lib/lp/code/templates/branch-index.pt 2011-08-04 14:23:45 +0000
331@@ -51,23 +51,6 @@
332 });
333 "/>
334
335- <tal:if condition="request/features/bugs.private_notification.enabled">
336- <script>
337- LPS.use('base', 'node', 'lp.app.privacy', function(Y) {
338- Y.on("domready", function () {
339- if (Y.one(document.body).hasClass('private')) {
340- var config = {
341- notification_text: 'This is a private branch',
342- hidden: true
343- };
344- Y.lp.app.privacy.setup_privacy_notification(config);
345- Y.lp.app.privacy.display_privacy_notification(true);
346- }
347- });
348- });
349- </script>
350- </tal:if>
351-
352 </metal:block>
353
354 <body>
355
356=== modified file 'lib/lp/code/templates/branchmergeproposal-index.pt'
357--- lib/lp/code/templates/branchmergeproposal-index.pt 2011-08-01 18:51:18 +0000
358+++ lib/lp/code/templates/branchmergeproposal-index.pt 2011-08-04 14:23:45 +0000
359@@ -48,22 +48,6 @@
360 padding-bottom: 10px;
361 }
362 </style>
363- <tal:if condition="request/features/bugs.private_notification.enabled">
364- <script>
365- LPS.use('base', 'node', 'lp.app.privacy', function(Y) {
366- Y.on("domready", function () {
367- if (Y.one(document.body).hasClass('private')) {
368- var config = {
369- notification_text: 'This merge proposal is for a private branch',
370- hidden: true
371- };
372- Y.lp.app.privacy.setup_privacy_notification(config);
373- Y.lp.app.privacy.display_privacy_notification(false);
374- }
375- });
376- });
377- </script>
378- </tal:if>
379 </metal:block>
380
381 <tal:registering metal:fill-slot="registering">