stream_data: Add can_edit_description function.

Added can_edit_description function in stream_data to check if the user has permission to edit the description of the stream.
This commit is contained in:
opmkumar 2024-09-14 00:48:15 +05:30 committed by Tim Abbott
parent f31371969d
commit d4b1d0a68e
4 changed files with 7 additions and 5 deletions

View File

@ -7,7 +7,6 @@ import * as browser_history from "./browser_history";
import * as hash_util from "./hash_util";
import * as modals from "./modals";
import * as popover_menus from "./popover_menus";
import {current_user} from "./state_data";
import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store";
import * as ui_util from "./ui_util";
@ -49,7 +48,7 @@ export function initialize(): void {
// modals.close_active_if_any() is mainly used to handle navigation to channel settings
// using the popover that is opened when clicking on channel pills in the invite user modal.
modals.close_active_if_any();
const can_change_name_description = current_user.is_admin;
const can_change_name_description = stream_data.can_edit_description();
const can_change_stream_permissions = stream_data.can_change_permissions(sub);
let stream_edit_hash = hash_util.channels_settings_edit_url(sub, "general");
if (!can_change_stream_permissions && !can_change_name_description) {

View File

@ -506,6 +506,10 @@ export function can_change_permissions(sub: StreamSubscription): boolean {
return current_user.is_admin && (!sub.invite_only || sub.subscribed);
}
export function can_edit_description(): boolean {
return current_user.is_admin;
}
export function can_view_subscribers(sub: StreamSubscription): boolean {
// Guest users can't access subscribers of any(public or private) non-subscribed streams.
return current_user.is_admin || sub.subscribed || (!current_user.is_guest && !sub.invite_only);

View File

@ -21,7 +21,6 @@ import * as popover_menus from "./popover_menus";
import {left_sidebar_tippy_options} from "./popover_menus";
import {web_channel_default_view_values} from "./settings_config";
import * as settings_data from "./settings_data";
import {current_user} from "./state_data";
import * as stream_color from "./stream_color";
import * as stream_data from "./stream_data";
import * as stream_settings_api from "./stream_settings_api";
@ -153,7 +152,7 @@ function build_stream_popover(opts) {
// Admin can change any stream's name & description either stream is public or
// private, subscribed or unsubscribed.
const can_change_name_description = current_user.is_admin;
const can_change_name_description = stream_data.can_edit_description();
const can_change_stream_permissions = stream_data.can_change_permissions(sub);
let stream_edit_hash = hash_util.channels_settings_edit_url(sub, "general");
if (!can_change_stream_permissions && !can_change_name_description) {

View File

@ -42,7 +42,7 @@ export function get_sub_for_settings(sub: StreamSubscription): SettingsSubscript
is_realm_admin: current_user.is_admin,
// Admin can change any stream's name & description either stream is public or
// private, subscribed or unsubscribed.
can_change_name_description: current_user.is_admin,
can_change_name_description: stream_data.can_edit_description(),
should_display_subscription_button: stream_data.can_toggle_subscription(sub),
should_display_preview_button: stream_data.can_preview(sub),