refactor: Extract stream_data.can_change_permissions().

This commit is contained in:
Steve Howell 2021-04-04 15:40:48 +00:00 committed by Tim Abbott
parent b27ff978c7
commit ea972569a3
2 changed files with 5 additions and 2 deletions

View File

@ -511,6 +511,10 @@ export function can_preview(sub) {
return sub.subscribed || !sub.invite_only || sub.previously_subscribed; return sub.subscribed || !sub.invite_only || sub.previously_subscribed;
} }
export function can_change_permissions(sub) {
return page_params.is_admin && (!sub.invite_only || sub.subscribed);
}
export function is_subscribed(stream_name) { export function is_subscribed(stream_name) {
const sub = get_sub(stream_name); const sub = get_sub(stream_name);
return sub !== undefined && sub.subscribed; return sub !== undefined && sub.subscribed;

View File

@ -53,8 +53,7 @@ export function update_calculated_fields(sub) {
sub.should_display_subscription_button = stream_data.can_toggle_subscription(sub); sub.should_display_subscription_button = stream_data.can_toggle_subscription(sub);
sub.should_display_preview_button = stream_data.can_preview(sub); sub.should_display_preview_button = stream_data.can_preview(sub);
sub.can_change_stream_permissions = sub.can_change_stream_permissions = stream_data.can_change_permissions(sub);
page_params.is_admin && (!sub.invite_only || sub.subscribed);
// User can add other users to stream if stream is public or user is subscribed to stream. // 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. // Guest users can't access subscribers of any(public or private) non-subscribed streams.
sub.can_access_subscribers = sub.can_access_subscribers =