streams: Allow changing can_remove_subscribers_group through API.

This commit adds API support to change can_remove_subscribers_group
setting for a stream.
This commit is contained in:
Sahil Batra
2022-09-16 17:57:38 +05:30
committed by Tim Abbott
parent 6fa0a83d6b
commit c3759814be
5 changed files with 157 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ from zerver.actions.message_send import (
from zerver.actions.streams import (
bulk_add_subscriptions,
bulk_remove_subscriptions,
do_change_can_remove_subscribers_group,
do_change_stream_description,
do_change_stream_message_retention_days,
do_change_stream_permission,
@@ -79,6 +80,7 @@ from zerver.lib.topic import (
messages_for_topic,
)
from zerver.lib.types import Validator
from zerver.lib.user_groups import access_user_group_for_setting
from zerver.lib.utils import assert_is_not_none
from zerver.lib.validator import (
check_bool,
@@ -266,6 +268,7 @@ def update_stream_backend(
message_retention_days: Optional[Union[int, str]] = REQ(
json_validator=check_string_or_int, default=None
),
can_remove_subscribers_group_id: Optional[int] = REQ(json_validator=check_int, default=None),
) -> HttpResponse:
# We allow realm administrators to to update the stream name and
# description even for private streams.
@@ -380,6 +383,20 @@ def update_stream_backend(
if stream_post_policy is not None:
do_change_stream_post_policy(stream, stream_post_policy, acting_user=user_profile)
if can_remove_subscribers_group_id is not None:
if sub is None and stream.invite_only:
# Admins cannot change this setting for unsubscribed private streams.
raise JsonableError(_("Invalid stream ID"))
user_group = access_user_group_for_setting(
can_remove_subscribers_group_id,
user_profile,
setting_name="can_remove_subscribers_group",
require_system_group=True,
)
do_change_can_remove_subscribers_group(stream, user_group, acting_user=user_profile)
return json_success(request)