mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
refactor: Extract can_view_subscribers().
We also remove some needless uses of the calculated field in the node tests.
This commit is contained in:
@@ -515,6 +515,11 @@ export function can_change_permissions(sub) {
|
||||
return page_params.is_admin && (!sub.invite_only || sub.subscribed);
|
||||
}
|
||||
|
||||
export function can_view_subscribers(sub) {
|
||||
// Guest users can't access subscribers of any(public or private) non-subscribed streams.
|
||||
return page_params.is_admin || sub.subscribed || (!page_params.is_guest && !sub.invite_only);
|
||||
}
|
||||
|
||||
export function is_subscribed(stream_name) {
|
||||
const sub = get_sub(stream_name);
|
||||
return sub !== undefined && sub.subscribed;
|
||||
@@ -592,7 +597,7 @@ export function maybe_get_stream_name(stream_id) {
|
||||
|
||||
export function is_user_subscribed(stream_id, user_id) {
|
||||
const sub = get_sub_by_id(stream_id);
|
||||
if (sub === undefined || !sub.can_access_subscribers) {
|
||||
if (sub === undefined || !can_view_subscribers(sub)) {
|
||||
// If we don't know about the stream, or we ourselves cannot access subscriber list,
|
||||
// so we return undefined (treated as falsy if not explicitly handled).
|
||||
blueslip.warn(
|
||||
|
||||
@@ -54,11 +54,10 @@ export function update_calculated_fields(sub) {
|
||||
sub.should_display_subscription_button = stream_data.can_toggle_subscription(sub);
|
||||
sub.should_display_preview_button = stream_data.can_preview(sub);
|
||||
sub.can_change_stream_permissions = stream_data.can_change_permissions(sub);
|
||||
// User can add other users to stream if stream is public or user is subscribed to stream.
|
||||
// Guest users can't access subscribers of any(public or private) non-subscribed streams.
|
||||
sub.can_access_subscribers =
|
||||
page_params.is_admin || sub.subscribed || (!page_params.is_guest && !sub.invite_only);
|
||||
sub.can_access_subscribers = stream_data.can_view_subscribers(sub);
|
||||
|
||||
sub.preview_url = hash_util.by_stream_uri(sub.stream_id);
|
||||
// User can add other users to stream if stream is public or user is subscribed to stream.
|
||||
sub.can_add_subscribers = !page_params.is_guest && (!sub.invite_only || sub.subscribed);
|
||||
sub.is_old_stream = sub.stream_weekly_traffic !== null;
|
||||
if (sub.rendered_description !== undefined) {
|
||||
|
||||
@@ -151,7 +151,7 @@ export function update_subscribers_list(sub) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sub.can_access_subscribers) {
|
||||
if (!stream_data.can_view_subscribers(sub)) {
|
||||
$(".subscriber_list_settings_container").hide();
|
||||
} else {
|
||||
const subscribers = peer_data.get_subscribers(sub.stream_id);
|
||||
|
||||
Reference in New Issue
Block a user