Merge lp:~danilo/launchpad/bug-761257 into lp:launchpad

Proposed by Данило Шеган
Status: Merged
Approved by: Данило Шеган
Approved revision: no longer in the source branch.
Merged at revision: 12909
Proposed branch: lp:~danilo/launchpad/bug-761257
Merge into: lp:launchpad
Diff against target: 167 lines (+86/-26)
2 files modified
lib/lp/bugs/javascript/bug_subscription.js (+10/-4)
lib/lp/bugs/javascript/bugtask_index_portlets.js (+76/-22)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-761257
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+58801@code.launchpad.net

Commit message

[r=bac][bug=761257] Allow teams to be unsubscribed from the advanced subscription overlay.

Description of the change

= Bug 761257 =

Advanced bug subscription overlay UI shows an option to unsubscribe any of the teams that you have privileges for. However, choosing those options doesn't really work.

== Proposed fix ==

We need to factor handle_advanced_subscription_overlay to actually properly handle all the possible cases:
 a. updating existing subscription
 b. unmuting and subscribing with a different notification level
 c. unmuting
 d. unsubscribing teams

Case b. is equivalent to a. and is treated as such, so we've got only a conditional for a/c/d.

== Implementation details ==

I also fixed a very jumpy animation (it always slided out a list of bug notification levels when you had a bug muted), and (not so) accidentally fixed the case of "unmuting" not really allowing to set a bug notification level even if the UI offered it.

== Tests ==

No tests. I am doing a refactoring branch that will include tests for this separately.

== Demo and Q/A ==

https://bugs.launchpad.dev/debian/+source/mozilla-firefox/+bug/3
https://bugs.launchpad.dev/debian/+source/mozilla-firefox/+bug/3/+subscribe

The demo at
  https://devpad.canonical.com/~danilo/screencasts/bug-subscription-advanced.ogv
shows approximatelly what steps need to be taken for proper QA. Refreshing between steps will help ensure you've got the data updated (and not just the UI), and will avoid a bug in existing code that when you get rid of all subscribers, subscribing someone else stops working.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/javascript/bug_subscription.js
  lib/lp/bugs/javascript/bugtask_index_portlets.js

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Danilos thanks for fixing this bug. I'm especially happy since it is one I opened.

On IRC we identified some issues that can be addressed in your follow-on branch:

- In the overlay form, change the value of the teams to have the '/~' prefixed which will prevent any future clashes between valid team names and the other checkbox values in the form.

- Rename and change the description of 'unsubscribe_current_user' to reflect the larger scope of what it is doing. In this case you're using it to unsubscribe a team.

With the promised follow-on branch work this one is ok.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/bugs/javascript/bug_subscription.js'
--- lib/lp/bugs/javascript/bug_subscription.js 2011-04-19 15:16:58 +0000
+++ lib/lp/bugs/javascript/bug_subscription.js 2011-04-22 12:29:31 +0000
@@ -42,13 +42,19 @@
42 visibility: 'visible'42 visibility: 'visible'
43 });43 });
44 });44 });
45 var checked_box = subscription_radio_buttons.filter(':checked').pop();
46 var current_value = checked_box.get('value');
45 slide_in_anim.run();47 slide_in_anim.run();
46 Y.each(subscription_radio_buttons, function(subscription_button) {48 Y.each(subscription_radio_buttons, function(subscription_button) {
47 subscription_button.on('click', function(e) {49 subscription_button.on('click', function(e) {
48 if(e.target.get('value') === 'update-subscription') {50 var value = e.target.get('value');
49 slide_out_anim.run();51 if (value !== current_value) {
50 } else {52 if(value === 'update-subscription') {
51 slide_in_anim.run();53 slide_out_anim.run();
54 } else {
55 slide_in_anim.run();
56 }
57 current_value = value;
52 }58 }
53 });59 });
54 });60 });
5561
=== modified file 'lib/lp/bugs/javascript/bugtask_index_portlets.js'
--- lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-04-14 16:37:22 +0000
+++ lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-04-22 12:29:31 +0000
@@ -379,6 +379,30 @@
379 return subscription;379 return subscription;
380}380}
381381
382
383/*
384 * Set up and return a Subscription object for the team subscription
385 * link.
386 */
387function get_team_subscription(team_uri) {
388 setup_client_and_bug();
389 var subscription = new Y.lp.bugs.subscriber.Subscription({
390 link: Y.one('.menu-link-subscription'),
391 spinner: Y.one('#sub-unsub-spinner'),
392 subscriber: new Y.lp.bugs.subscriber.Subscriber({
393 uri: team_uri,
394 subscriber_ids: subscriber_ids
395 })
396 });
397
398 subscription.set('is_direct', true);
399 subscription.set('has_dupes', false);
400 subscription.set('can_be_unsubscribed', true);
401 subscription.set('person', subscription.get('subscriber'));
402 subscription.set('is_team', true);
403 return subscription;
404}
405
382/*406/*
383 * Initialize callbacks for subscribe/unsubscribe links.407 * Initialize callbacks for subscribe/unsubscribe links.
384 *408 *
@@ -777,6 +801,8 @@
777 Y.lp.app.errors.display_error(subscription_link, error_msg);801 Y.lp.app.errors.display_error(subscription_link, error_msg);
778 };802 };
779803
804 var subscriber_link = Y.lp.client.get_absolute_uri(
805 subscriber.get('escaped_uri'));
780 var config = {806 var config = {
781 on: {807 on: {
782 success: function(client) {808 success: function(client) {
@@ -815,9 +841,11 @@
815 },841 },
816842
817 failure: error_handler.getFailureHandler()843 failure: error_handler.getFailureHandler()
818 }844 },
845
846 parameters: { person: subscriber_link }
819 };847 };
820 if (subscription.is_direct_subscription()) {848 if (subscription.is_direct_subscription() || subscription.is_team()) {
821 lp_client.named_post(bug_repr.self_link, 'unsubscribe', config);849 lp_client.named_post(bug_repr.self_link, 'unsubscribe', config);
822 } else {850 } else {
823 lp_client.named_post(851 lp_client.named_post(
@@ -1211,22 +1239,36 @@
1211 * @param form_data {Object} The data from the submitted form.1239 * @param form_data {Object} The data from the submitted form.
1212 */1240 */
1213function handle_advanced_subscription_overlay(form_data) {1241function handle_advanced_subscription_overlay(form_data) {
1214 var subscription = get_subscribe_self_subscription();1242 var subscription;
1243 var mute_subscription = get_mute_subscription();
1244 var is_muted = (!Y.Lang.isNull(mute_subscription) &&
1245 mute_subscription.get('is_muted'));
1246 var requested_subscriber;
1247 var request_for_self = false;
1248 // XXX Danilo 20110422: this is a very lousy "special string"
1249 // that will make it break for a team/person named 'update-subscription'.
1250 // We should probably use special characters not allowed in team names
1251 // (maybe all-uppercase would work).
1252 var UPDATE_ACTION = 'update-subscription';
1253
1254 if (form_data['field.subscription'][0] === UPDATE_ACTION) {
1255 requested_subscriber = LP.links.me;
1256 request_for_self = true;
1257 } else {
1258 requested_subscriber = '/~' + form_data['field.subscription'][0];
1259 if (requested_subscriber === LP.links.me) {
1260 request_for_self = true;
1261 }
1262 }
1263 if (request_for_self) {
1264 subscription = get_subscribe_self_subscription();
1265 } else {
1266 subscription = get_team_subscription(requested_subscriber);
1267 }
1215 var link = subscription.get('link');1268 var link = subscription.get('link');
1216 var link_parent = link.get('parentNode');1269 var link_parent = link.get('parentNode');
1217 var mute_subscription = get_mute_subscription();1270
1218 var is_muted = (!Y.Lang.isNull(mute_subscription) &&1271 if (form_data['field.subscription'][0] === UPDATE_ACTION) {
1219 mute_subscription.get('is_muted'));
1220 if (link_parent.hasClass('subscribed-false') &&
1221 link_parent.hasClass('dup-subscribed-false') &&
1222 !is_muted) {
1223 // The user isn't subscribed or muted, so subscribe them.
1224 subscription.set(
1225 'bug_notification_level',
1226 form_data['field.bug_notification_level']);
1227 subscribe_current_user(subscription);
1228 } else if (
1229 form_data['field.subscription'] === 'update-subscription') {
1230 // The user is already subscribed or is muted and wants to1272 // The user is already subscribed or is muted and wants to
1231 // update their subscription.1273 // update their subscription.
1232 setup_client_and_bug();1274 setup_client_and_bug();
@@ -1279,13 +1321,25 @@
1279 }1321 }
1280 };1322 };
1281 lp_client.get(subscription_url, config);1323 lp_client.get(subscription_url, config);
1324
1325 } else if (link_parent.hasClass('subscribed-false') &&
1326 link_parent.hasClass('dup-subscribed-false') &&
1327 !is_muted && request_for_self) {
1328 // The user isn't subscribed or muted, and the request is
1329 // for himself (iow, not for a team).
1330 subscription.set(
1331 'bug_notification_level',
1332 form_data['field.bug_notification_level']);
1333 subscribe_current_user(subscription);
1334 } else if (is_muted && request_for_self) {
1335 // When a person has a bug muted, we show 2+ options:
1336 // a. unmute, b. unmute and subscribe, c. unsubscribe team1...
1337 // "b" is treated as 'update-subscription' case, and for any
1338 // of the teams, request_for_self won't be true.
1339 unmute_current_user(mute_subscription);
1282 } else {1340 } else {
1283 // The user is already subscribed and wants to unsubscribe.1341 // Unsubscribe this person/team.
1284 if (is_muted) {1342 unsubscribe_current_user(subscription);
1285 unmute_current_user(mute_subscription);
1286 } else {
1287 unsubscribe_current_user(subscription);
1288 }
1289 }1343 }
1290}1344}
12911345