mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
stream create: Avoid unnecessary val attribute.
We used to put the user's email in a value, which was redundant (we could find the value from our parent's label) and brittle (would break on email changes). Now the DOM's a bit slimmer and more robust. Also note that we now deal with user_ids, not emails, in the call stack until we hit the "edge" and convert to emails for the server.
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<div id="user-checkboxes">
|
||||
{{#each users}}
|
||||
<label class="checkbox add-user-label" data-user-id="{{this.user_id}}">
|
||||
<input type="checkbox" name="user" value="{{this.email}}" {{#if @first}}checked="checked"{{#unless is_admin}} disabled="disabled"{{/unless}}{{/if}}/>
|
||||
<input type="checkbox" name="user" {{#if @first}}checked="checked"{{#unless is_admin}} disabled="disabled"{{/unless}}{{/if}}/>
|
||||
<span></span>
|
||||
{{this.full_name}} ({{this.email}})
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user