refactor: Extract stream_data.can_subscribe_others().

This commit is contained in:
Steve Howell 2021-04-04 16:15:17 +00:00 committed by Tim Abbott
parent 36fd76dc20
commit 430fadfb0b
2 changed files with 7 additions and 2 deletions

View File

@ -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;

View File

@ -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("<p>", "").replace("</p>", "");
}