diff --git a/frontend_tests/casper_tests/05-subscriptions.js b/frontend_tests/casper_tests/05-subscriptions.js index 5b24eb0a38..ea1e25da59 100644 --- a/frontend_tests/casper_tests/05-subscriptions.js +++ b/frontend_tests/casper_tests/05-subscriptions.js @@ -5,6 +5,19 @@ function user_checkbox(email) { return '#user-checkboxes [data-user-id="' + user_id + '"]'; } +function user_span(email) { + return user_checkbox(email) + ' input ~ span'; +} + +function is_checked(email) { + var sel = user_checkbox(email); + return casper.evaluate(function (sel) { + return $(sel).find('input')[0].checked; + }, { + sel: sel, + }); +} + common.start_and_log_in(); casper.then(function () { @@ -69,21 +82,21 @@ casper.then(function () { casper.test.info("Check Uncheck only visible users for new stream"); casper.click('.subs_set_all_users'); casper.wait(100, function () { - casper.test.assert(casper.evaluate(function () { - return !$('#user-checkboxes [value="cordelia@zulip.com"]')[0].checked; - }), "Cordelia is unchecked"); - casper.test.assert(casper.evaluate(function () { - return $('#user-checkboxes [value="othello@zulip.com"]')[0].checked; - }), "Othello is checked"); + casper.test.assert( + !is_checked('cordelia@zulip.com'), + "Cordelia is unchecked"); + casper.test.assert( + is_checked('othello@zulip.com'), + "Othello is checked"); }); }); casper.then(function () { casper.test.info("Check Uncheck only visible users for new stream"); casper.click('.subs_unset_all_users'); casper.wait(100, function () { - casper.test.assert(casper.evaluate(function () { - return !$('#user-checkboxes [value="othello@zulip.com"]')[0].checked; - }), "Othello is unchecked"); + casper.test.assert( + !is_checked('othello@zulip.com'), + "Othello is unchecked"); }); }); casper.then(function () { @@ -109,8 +122,8 @@ casper.then(function () { casper.test.assertTextExists('Create stream', 'New stream creation panel'); casper.fill('form#stream_creation_form', {stream_name: 'Waseemio', stream_description: 'Oimeesaw'}); casper.click('input[value="Scotland"] ~ span'); - casper.click('input[value="cordelia@zulip.com"] ~ span'); - casper.click('input[value="othello@zulip.com"] ~ span'); + casper.click(user_span('cordelia@zulip.com')); + casper.click(user_span('othello@zulip.com')); casper.click('form#stream_creation_form button.button.sea-green'); }); }); diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 3388de25f3..70f1f0c0bb 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -97,8 +97,16 @@ const stream_name_error = (function () { return self; }()); -function ajaxSubscribeForCreation(stream_name, description, principals, invite_only, +function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_only, is_announcement_only, announce, history_public_to_subscribers) { + // TODO: We can eliminate the user_ids -> principals conversion + // once we upgrade the backend to accept user_ids. + const persons = _.compact(_.map(user_ids, (user_id) => { + return people.get_person_from_user_id(user_id); + })); + + const principals = _.map(persons, (person) => person.email); + // Subscribe yourself and possible other people to a new stream. return channel.post({ url: "/json/users/me/subscriptions", @@ -164,7 +172,8 @@ function get_principals() { return _.map( $("#stream_creation_form input:checkbox[name=user]:checked"), function (elem) { - return $(elem).val(); + const label = $(elem).closest('.add-user-label'); + return parseInt(label.attr('data-user-id'), 10); } ); } @@ -397,7 +406,7 @@ exports.set_up_handlers = function () { stream_subscription_error.report_no_subs_to_stream(); return; } - if (principals.indexOf(people.my_current_email()) < 0 && !page_params.is_admin) { + if (principals.indexOf(people.my_current_user_id()) < 0 && !page_params.is_admin) { stream_subscription_error.cant_create_stream_without_susbscribing(); return; } diff --git a/static/templates/new_stream_users.hbs b/static/templates/new_stream_users.hbs index 1d9b299dde..2705443b65 100644 --- a/static/templates/new_stream_users.hbs +++ b/static/templates/new_stream_users.hbs @@ -30,7 +30,7 @@