From 430fadfb0bb975ccb17352f7ff93a67a6fd3b30e Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 4 Apr 2021 16:15:17 +0000 Subject: [PATCH] refactor: Extract stream_data.can_subscribe_others(). --- static/js/stream_data.js | 5 +++++ static/js/stream_settings_data.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 055b836573..e59c5e42b1 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -520,6 +520,11 @@ export function can_view_subscribers(sub) { return page_params.is_admin || sub.subscribed || (!page_params.is_guest && !sub.invite_only); } +export function can_subscribe_others(sub) { + // User can add other users to stream if stream is public or user is subscribed to stream. + return !page_params.is_guest && (!sub.invite_only || sub.subscribed); +} + export function is_subscribed(stream_name) { const sub = get_sub(stream_name); return sub !== undefined && sub.subscribed; diff --git a/static/js/stream_settings_data.js b/static/js/stream_settings_data.js index 6dce2effb3..ea7ddc7649 100644 --- a/static/js/stream_settings_data.js +++ b/static/js/stream_settings_data.js @@ -55,11 +55,11 @@ export function update_calculated_fields(sub) { sub.should_display_preview_button = stream_data.can_preview(sub); sub.can_change_stream_permissions = stream_data.can_change_permissions(sub); sub.can_access_subscribers = stream_data.can_view_subscribers(sub); + sub.can_add_subscribers = stream_data.can_subscribe_others(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) { sub.rendered_description = sub.rendered_description.replace("

", "").replace("

", ""); }