streams: Disable option to add other subscribers in existing streams.

This commit disables the field used for adding other subscribers
to existing streams for users who are not allowed to add other users
to streams because of realm level setting "Who can add users to streams".
This commit is contained in:
Ujjawal Modi 2023-05-08 12:31:27 +05:30 committed by Tim Abbott
parent eda1ee555b
commit 105acc8495
2 changed files with 21 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import {page_params} from "./page_params";
import * as peer_data from "./peer_data";
import * as people from "./people";
import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data";
import * as sub_store from "./sub_store";
import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
@ -516,8 +517,13 @@ export function can_view_subscribers(sub) {
}
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);
// User can add other users to stream if stream is public or user is subscribed to stream
// and realm level setting allows user to add subscribers.
return (
!page_params.is_guest &&
(!sub.invite_only || sub.subscribed) &&
settings_data.user_can_subscribe_other_users()
);
}
export function can_unsubscribe_others(sub) {

View File

@ -7,6 +7,7 @@ import render_stream_settings_tip from "../templates/stream_settings/stream_sett
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
import {page_params} from "./page_params";
import * as settings_data from "./settings_data";
import * as settings_org from "./settings_org";
import * as stream_data from "./stream_data";
import * as stream_edit from "./stream_edit";
@ -252,11 +253,22 @@ export function update_add_subscriptions_elements(sub) {
enable_or_disable_add_subscribers_elements($add_subscribers_container, allow_user_to_add_subs);
if (!allow_user_to_add_subs) {
let tooltip_message;
if (!settings_data.user_can_subscribe_other_users()) {
tooltip_message = $t({
defaultMessage:
"You do not have permission to add other users to streams in this organization.",
});
} else {
tooltip_message = $t({
defaultMessage: "Only stream members can add users to a private stream.",
});
}
initialize_disable_btn_hint_popover(
$add_subscribers_container,
$input_element,
$button_element,
$t({defaultMessage: "Only stream members can add users to a private stream"}),
tooltip_message,
);
}
}