mirror of https://github.com/zulip/zulip.git
subscriber list: Fix display of email addresses in subscribers list.
Original email address is shown to admin users in subscriber list when email_address_visibilty is set to "Admins only" by passing delivery_email at required places. Email address are not shown to non-admin users when visibility is set to "Admins only". Tweaked by tabbott to fix a few bugs and dead code. Fixes a part of #13541.
This commit is contained in:
parent
d0927d38fc
commit
6a791e1939
|
@ -91,6 +91,8 @@ zrequire('message_store');
|
|||
zrequire('people');
|
||||
zrequire('starred_messages');
|
||||
zrequire('user_status');
|
||||
zrequire('subs');
|
||||
zrequire('stream_ui_updates');
|
||||
|
||||
zrequire('server_events_dispatch');
|
||||
|
||||
|
@ -238,6 +240,13 @@ const event_fixtures = {
|
|||
value: 1,
|
||||
},
|
||||
|
||||
realm__update__email_addresses_visibility: {
|
||||
type: 'realm',
|
||||
op: 'update',
|
||||
property: 'email_address_visibility',
|
||||
value: 3,
|
||||
},
|
||||
|
||||
realm__update__disallow_disposable_email_addresses: {
|
||||
type: 'realm',
|
||||
op: 'update',
|
||||
|
@ -934,6 +943,11 @@ with_overrides(function (override) {
|
|||
event = event_fixtures.realm__update__disallow_disposable_email_addresses;
|
||||
test_realm_boolean(event, 'realm_disallow_disposable_email_addresses');
|
||||
|
||||
event = event_fixtures.realm__update__email_addresses_visibility;
|
||||
override('stream_ui_updates.update_subscribers_list', noop);
|
||||
dispatch(event);
|
||||
assert_same(page_params.realm_email_address_visibility, 3);
|
||||
|
||||
event = event_fixtures.realm__update_notifications_stream_id;
|
||||
override('settings_org.render_notifications_stream_ui', noop);
|
||||
dispatch(event);
|
||||
|
|
|
@ -2,12 +2,24 @@ const render_settings_deactivation_stream_modal = require("../templates/settings
|
|||
const render_stream_member_list_entry = require('../templates/stream_member_list_entry.hbs');
|
||||
const render_subscription_settings = require('../templates/subscription_settings.hbs');
|
||||
const render_subscription_stream_privacy_modal = require("../templates/subscription_stream_privacy_modal.hbs");
|
||||
const settings_data = require("./settings_data");
|
||||
|
||||
function setup_subscriptions_stream_hash(sub) {
|
||||
const hash = hash_util.stream_edit_uri(sub);
|
||||
hashchange.update_browser_history(hash);
|
||||
}
|
||||
|
||||
function compare_by_email(a, b) {
|
||||
if (a.delivery_email && b.delivery_email) {
|
||||
return a.delivery_email.localeCompare(b.delivery_email);
|
||||
}
|
||||
return a.email.localeCompare(b.email);
|
||||
}
|
||||
|
||||
function compare_by_name(a, b) {
|
||||
return a.full_name.localeCompare(b.full_name);
|
||||
}
|
||||
|
||||
exports.setup_subscriptions_tab_hash = function (tab_key_value) {
|
||||
if (tab_key_value === "all-streams") {
|
||||
hashchange.update_browser_history('#streams/all');
|
||||
|
@ -34,9 +46,9 @@ exports.is_sub_settings_active = function (sub) {
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.get_email_of_subscribers = function (subscribers) {
|
||||
exports.get_users_from_subscribers = function (subscribers) {
|
||||
return subscribers.map(function (user_id) {
|
||||
return people.get_by_user_id(user_id).email;
|
||||
return people.get_by_user_id(user_id);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -86,13 +98,13 @@ exports.open_edit_panel_empty = function () {
|
|||
exports.setup_subscriptions_tab_hash(tab_key);
|
||||
};
|
||||
|
||||
function format_member_list_elem(email) {
|
||||
const person = people.get_by_email(email);
|
||||
function format_member_list_elem(person) {
|
||||
return render_stream_member_list_entry({
|
||||
name: person.full_name,
|
||||
user_id: person.user_id,
|
||||
email: email,
|
||||
email: settings_data.email_for_user_settings(person),
|
||||
displaying_for_admin: page_params.is_admin,
|
||||
show_email: settings_data.show_email(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -137,18 +149,25 @@ exports.remove_user_from_stream = function (user_email, sub, success, failure) {
|
|||
});
|
||||
};
|
||||
|
||||
exports.sort_but_pin_current_user_on_top = function (emails) {
|
||||
if (emails === undefined) {
|
||||
blueslip.error("Undefined emails are passed to function sort_but_pin_current_user_on_top");
|
||||
exports.sort_but_pin_current_user_on_top = function (users) {
|
||||
if (users === undefined) {
|
||||
blueslip.error("Undefined users are passed to function sort_but_pin_current_user_on_top");
|
||||
return;
|
||||
}
|
||||
// Set current user top of subscription list, if subscribed.
|
||||
if (emails.includes(people.my_current_email())) {
|
||||
emails.splice(emails.indexOf(people.my_current_email()), 1);
|
||||
emails.sort();
|
||||
emails.unshift(people.my_current_email());
|
||||
|
||||
const my_user = people.get_by_email(people.my_current_email());
|
||||
let compare_function;
|
||||
if (settings_data.show_email()) {
|
||||
compare_function = compare_by_email;
|
||||
} else {
|
||||
emails.sort();
|
||||
compare_function = compare_by_name;
|
||||
}
|
||||
if (users.includes(my_user)) {
|
||||
users.splice(users.indexOf(my_user), 1);
|
||||
users.sort(compare_function);
|
||||
users.unshift(my_user);
|
||||
} else {
|
||||
users.sort(compare_function);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -172,10 +191,10 @@ function show_subscription_settings(sub_row) {
|
|||
const list = get_subscriber_list(sub_settings);
|
||||
list.empty();
|
||||
|
||||
const emails = exports.get_email_of_subscribers(sub.subscribers);
|
||||
exports.sort_but_pin_current_user_on_top(emails);
|
||||
const users = exports.get_users_from_subscribers(sub.subscribers);
|
||||
exports.sort_but_pin_current_user_on_top(users);
|
||||
|
||||
list_render.create(list, emails, {
|
||||
list_render.create(list, users, {
|
||||
name: "stream_subscribers/" + stream_id,
|
||||
modifier: function (item) {
|
||||
return format_member_list_elem(item);
|
||||
|
@ -183,13 +202,14 @@ function show_subscription_settings(sub_row) {
|
|||
filter: {
|
||||
element: $("[data-stream-id='" + stream_id + "'] .search"),
|
||||
predicate: function (item, value) {
|
||||
const person = people.get_by_email(item);
|
||||
const person = item;
|
||||
|
||||
if (person) {
|
||||
const email = person.email.toLocaleLowerCase();
|
||||
const full_name = person.full_name.toLowerCase();
|
||||
|
||||
return email.includes(value) || full_name.includes(value);
|
||||
if (person.email.toLocaleLowerCase().includes(value) &&
|
||||
settings_data.show_email()) {
|
||||
return true;
|
||||
}
|
||||
return person.full_name.toLowerCase().includes(value);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
@ -172,7 +172,7 @@ exports.update_subscribers_list = function (sub) {
|
|||
if (!sub.can_access_subscribers) {
|
||||
$(".subscriber_list_settings_container").hide();
|
||||
} else {
|
||||
const emails = stream_edit.get_email_of_subscribers(sub.subscribers);
|
||||
const users = stream_edit.get_users_from_subscribers(sub.subscribers);
|
||||
|
||||
/*
|
||||
We try to find a subscribers list that is already in the
|
||||
|
@ -187,8 +187,8 @@ exports.update_subscribers_list = function (sub) {
|
|||
// Perform re-rendering only when the stream settings form of the corresponding
|
||||
// stream is open.
|
||||
if (subscribers_list) {
|
||||
stream_edit.sort_but_pin_current_user_on_top(emails);
|
||||
subscribers_list.data(emails);
|
||||
stream_edit.sort_but_pin_current_user_on_top(users);
|
||||
subscribers_list.data(users);
|
||||
subscribers_list.render();
|
||||
}
|
||||
$(".subscriber_list_settings_container").show();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<tr data-subscriber-id="{{user_id}}">
|
||||
<td class="subscriber-name">{{name}}</td>
|
||||
{{#if show_email}}
|
||||
<td class="subscriber-email">{{email}}</td>
|
||||
{{/if}}
|
||||
{{#if displaying_for_admin}}
|
||||
<td class="unsubscribe">
|
||||
<div class="subscriber_list_remove">
|
||||
|
|
Loading…
Reference in New Issue