streams: Rename `can_remove_subscribers_group_id` parameter.

Earlier the API endpoints related to streams accepts and returns a
field `can_remove_subscribers_group_id` which represents the ID
of user_group whose members can remove subscribers from stream.

This commit renames this field to `can_remove_subscribers_group`.
This commit is contained in:
Ujjawal Modi 2023-07-12 16:27:57 +05:30 committed by Tim Abbott
parent 5ccb408f19
commit c8bcb422f5
22 changed files with 118 additions and 85 deletions

View File

@ -20,6 +20,17 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 8.0
**Feature level 197**
* [`POST /users/me/subscriptions`](/api/subscribe),
[`PATCH /streams/{stream_id}`](/api/update-stream),
[`GET users/me/subscriptions`](/api/get-subscriptions),
[`GET /streams`](/api/get-streams),
[`POST /register`](/api/register-queue),
[`GET /events`](/api/get-events): Renamed
stream setting `can_remove_subscribers_group_id`
to `can_remove_subscribers_group`.
**Feature level 196**
* [`POST /realm/playgrounds`](/api/add-code-playground): `url_prefix` is

View File

@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# Changes should be accompanied by documentation explaining what the
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
API_FEATURE_LEVEL = 196
API_FEATURE_LEVEL = 197
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump

View File

@ -600,7 +600,7 @@ export function get_widget_for_dropdown_list_settings(property_name) {
return signup_notifications_stream_widget;
case "realm_default_code_block_language":
return default_code_language_widget;
case "can_remove_subscribers_group_id":
case "can_remove_subscribers_group":
return stream_edit.can_remove_subscribers_group_widget;
default:
blueslip.error("No dropdown list widget for property", {property_name});
@ -641,7 +641,7 @@ export function discard_property_element_changes(elem, for_realm_default_setting
case "realm_notifications_stream_id":
case "realm_signup_notifications_stream_id":
case "realm_default_code_block_language":
case "can_remove_subscribers_group_id":
case "can_remove_subscribers_group":
set_dropdown_list_widget_setting_value(property_name, property_value);
break;
case "realm_default_language":
@ -957,7 +957,7 @@ export function check_property_changed(elem, for_realm_default_settings, sub) {
case "realm_notifications_stream_id":
case "realm_signup_notifications_stream_id":
case "realm_default_code_block_language":
case "can_remove_subscribers_group_id":
case "can_remove_subscribers_group":
proposed_val = get_dropdown_list_widget_setting_value($elem, false);
break;
case "email_notifications_batching_period_seconds":

View File

@ -259,7 +259,7 @@ function create_stream() {
stream_settings_ui.new_stream_can_remove_subscribers_group_widget.value(),
10,
);
data.can_remove_subscribers_group_id = can_remove_subscribers_group_id;
data.can_remove_subscribers_group = can_remove_subscribers_group_id;
loading.make_indicator($("#stream_creating_indicator"), {
text: $t({defaultMessage: "Creating stream..."}),

View File

@ -430,7 +430,7 @@ export function update_message_retention_setting(sub, message_retention_days) {
}
export function update_can_remove_subscribers_group_id(sub, can_remove_subscribers_group_id) {
sub.can_remove_subscribers_group_id = can_remove_subscribers_group_id;
sub.can_remove_subscribers_group = can_remove_subscribers_group_id;
}
export function receives_notifications(stream_id, notification_name) {
@ -558,7 +558,7 @@ export function can_unsubscribe_others(sub) {
}
return user_groups.is_user_in_group(
sub.can_remove_subscribers_group_id,
sub.can_remove_subscribers_group,
people.my_current_user_id(),
);
}

View File

@ -210,13 +210,13 @@ export function show_settings_for(node) {
});
const opts = {
widget_name: "can_remove_subscribers_group_id",
widget_name: "can_remove_subscribers_group",
data: user_groups.get_realm_user_groups_for_dropdown_list_widget(
"can_remove_subscribers_group",
),
default_text: $t({defaultMessage: "No user groups"}),
include_current_item: false,
value: sub.can_remove_subscribers_group_id,
value: sub.can_remove_subscribers_group,
on_update() {
settings_org.save_discard_widget_status_handler(
$("#stream_permission_settings"),

View File

@ -93,7 +93,7 @@ export function update_property(stream_id, property, value, other_values) {
case "message_retention_days":
stream_settings_ui.update_message_retention_setting(sub, value);
break;
case "can_remove_subscribers_group_id":
case "can_remove_subscribers_group":
stream_settings_ui.update_can_remove_subscribers_group_id(sub, value);
break;
default:

View File

@ -247,7 +247,7 @@ export function update_message_retention_setting(sub, new_value) {
export function update_can_remove_subscribers_group_id(sub, new_value) {
stream_data.update_can_remove_subscribers_group_id(sub, new_value);
stream_ui_updates.update_setting_element(sub, "can_remove_subscribers_group_id");
stream_ui_updates.update_setting_element(sub, "can_remove_subscribers_group");
stream_edit_subscribers.rerender_subscribers_list(sub);
}
@ -665,7 +665,7 @@ export function setup_page(callback) {
$("#streams_overlay_container").empty();
const opts = {
widget_name: "new_stream_can_remove_subscribers_group_id",
widget_name: "new_stream_can_remove_subscribers_group",
data: user_groups.get_realm_user_groups_for_dropdown_list_widget(
"can_remove_subscribers_group",
),

View File

@ -32,7 +32,7 @@
{{> stream_types
stream_post_policy=stream_post_policy_values.everyone.code
is_stream_edit=false
can_remove_subscribers_setting_widget_name="new_stream_can_remove_subscribers_group_id" }}
can_remove_subscribers_setting_widget_name="new_stream_can_remove_subscribers_group" }}
</div>
</section>
<section class="block">

View File

@ -61,7 +61,7 @@
is_business_type_org=../is_business_type_org
org_level_message_retention_setting=../org_level_message_retention_setting
is_stream_edit=true
can_remove_subscribers_setting_widget_name="can_remove_subscribers_group_id" }}
can_remove_subscribers_setting_widget_name="can_remove_subscribers_group" }}
</div>
{{/with}}
<div class="stream-email-box" {{#unless sub.email_address}}style="display: none;"{{/unless}}>

View File

@ -50,7 +50,7 @@ exports.test_streams = {
is_web_public: false,
message_retention_days: null,
stream_post_policy: 1,
can_remove_subscribers_group_id: 2,
can_remove_subscribers_group: 2,
},
test: {
name: "test",
@ -65,7 +65,7 @@ exports.test_streams = {
is_announcement_only: false,
message_retention_days: null,
stream_post_policy: 1,
can_remove_subscribers_group_id: 2,
can_remove_subscribers_group: 2,
},
};

View File

@ -286,7 +286,7 @@ test("admin_options", () => {
stream_id: 1,
is_muted: true,
invite_only: false,
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
stream_data.add_sub(sub);
return sub;
@ -339,7 +339,7 @@ test("stream_settings", () => {
color: "cinnamon",
subscribed: true,
invite_only: false,
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const blue = {
@ -348,7 +348,7 @@ test("stream_settings", () => {
color: "blue",
subscribed: false,
invite_only: false,
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const amber = {
@ -360,7 +360,7 @@ test("stream_settings", () => {
history_public_to_subscribers: true,
stream_post_policy: stream_data.stream_post_policy_values.admins.code,
message_retention_days: 10,
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
stream_data.add_sub(cinnamon);
stream_data.add_sub(amber);
@ -398,7 +398,7 @@ test("stream_settings", () => {
assert.equal(sub.history_public_to_subscribers, false);
assert.equal(sub.stream_post_policy, stream_data.stream_post_policy_values.everyone.code);
assert.equal(sub.message_retention_days, -1);
assert.equal(sub.can_remove_subscribers_group_id, moderators_group.id);
assert.equal(sub.can_remove_subscribers_group, moderators_group.id);
// For guest user only retrieve subscribed streams
sub_rows = stream_settings_data.get_updated_unsorted_subs();
@ -970,7 +970,7 @@ test("can_unsubscribe_others", () => {
subscribed: true,
color: "red",
stream_id: 1,
can_remove_subscribers_group_id: admins.id,
can_remove_subscribers_group: admins.id,
};
stream_data.add_sub(sub);
@ -979,7 +979,7 @@ test("can_unsubscribe_others", () => {
people.initialize_current_user(moderator_user_id);
assert.equal(stream_data.can_unsubscribe_others(sub), false);
sub.can_remove_subscribers_group_id = moderators.id;
sub.can_remove_subscribers_group = moderators.id;
people.initialize_current_user(admin_user_id);
assert.equal(stream_data.can_unsubscribe_others(sub), true);
people.initialize_current_user(moderator_user_id);
@ -987,7 +987,7 @@ test("can_unsubscribe_others", () => {
people.initialize_current_user(member_user_id);
assert.equal(stream_data.can_unsubscribe_others(sub), false);
sub.can_remove_subscribers_group_id = all.id;
sub.can_remove_subscribers_group = all.id;
people.initialize_current_user(admin_user_id);
assert.equal(stream_data.can_unsubscribe_others(sub), true);
people.initialize_current_user(moderator_user_id);
@ -996,7 +996,7 @@ test("can_unsubscribe_others", () => {
assert.equal(stream_data.can_unsubscribe_others(sub), true);
// Even with the nobody system group, admins can still unsubscribe others.
sub.can_remove_subscribers_group_id = nobody.id;
sub.can_remove_subscribers_group = nobody.id;
page_params.is_admin = true;
assert.equal(stream_data.can_unsubscribe_others(sub), true);
page_params.is_admin = false;

View File

@ -249,11 +249,11 @@ test("update_property", ({override, override_rewire}) => {
assert.equal(args.val, 20);
}
// Test stream can_remove_subscribers_group_id change event
// Test stream can_remove_subscribers_group change event
{
const stub = make_stub();
override(stream_settings_ui, "update_can_remove_subscribers_group_id", stub.f);
stream_events.update_property(stream_id, "can_remove_subscribers_group_id", 3);
stream_events.update_property(stream_id, "can_remove_subscribers_group", 3);
assert.equal(stub.num_calls, 1);
const args = stub.get_args("sub", "val");
assert.equal(args.sub.stream_id, stream_id);

View File

@ -43,7 +43,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
subscribers: [1],
stream_weekly_traffic: null,
color: "red",
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const poland = {
elem: "poland",
@ -54,7 +54,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
subscribers: [1, 2, 3],
stream_weekly_traffic: 13,
color: "red",
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const pomona = {
elem: "pomona",
@ -65,7 +65,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
subscribers: [],
stream_weekly_traffic: 0,
color: "red",
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const cpp = {
elem: "cpp",
@ -76,7 +76,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
subscribers: [1, 2],
stream_weekly_traffic: 6,
color: "red",
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const zzyzx = {
elem: "zzyzx",
@ -87,7 +87,7 @@ run_test("redraw_left_panel", ({mock_template}) => {
subscribers: [1, 2],
stream_weekly_traffic: 6,
color: "red",
can_remove_subscribers_group_id: admins_group.id,
can_remove_subscribers_group: admins_group.id,
};
const sub_row_data = [denmark, poland, pomona, cpp, zzyzx];

View File

@ -374,7 +374,7 @@ def send_subscription_add_events(
stream_weekly_traffic=stream_info.stream_weekly_traffic,
subscribers=stream_info.subscribers,
# Fields from Stream.API_FIELDS
can_remove_subscribers_group_id=stream_dict["can_remove_subscribers_group_id"],
can_remove_subscribers_group=stream_dict["can_remove_subscribers_group"],
date_created=stream_dict["date_created"],
description=stream_dict["description"],
first_message_id=stream_dict["first_message_id"],
@ -1440,7 +1440,7 @@ def do_change_stream_group_based_setting(
event = dict(
op="update",
type="stream",
property=setting_name + "_id",
property=setting_name,
value=user_group.id,
stream_id=stream.id,
name=stream.name,

View File

@ -50,7 +50,7 @@ from zerver.models import Realm, RealmUserDefault, Stream, UserProfile
# These fields are used for "stream" events, and are included in the
# larger "subscription" events that also contain personal settings.
basic_stream_fields = [
("can_remove_subscribers_group_id", int),
("can_remove_subscribers_group", int),
("date_created", int),
("description", str),
("first_message_id", OptionalType(int)),
@ -1282,7 +1282,7 @@ def check_stream_update(
elif prop == "stream_post_policy":
assert extra_keys == set()
assert value in Stream.STREAM_POST_POLICY_TYPES
elif prop == "can_remove_subscribers_group_id":
elif prop == "can_remove_subscribers_group":
assert extra_keys == set()
assert isinstance(value, int)
else:

View File

@ -72,7 +72,7 @@ def get_web_public_subs(realm: Realm) -> SubscriptionInfo:
sub = SubscriptionStreamDict(
audible_notifications=audible_notifications,
can_remove_subscribers_group_id=can_remove_subscribers_group_id,
can_remove_subscribers_group=can_remove_subscribers_group_id,
color=color,
date_created=date_created,
description=description,
@ -156,7 +156,7 @@ def build_stream_dict_for_sub(
# Our caller may add a subscribers field.
return SubscriptionStreamDict(
audible_notifications=audible_notifications,
can_remove_subscribers_group_id=can_remove_subscribers_group_id,
can_remove_subscribers_group=can_remove_subscribers_group_id,
color=color,
date_created=date_created,
description=description,
@ -207,7 +207,7 @@ def build_stream_dict_for_never_sub(
# Our caller may add a subscribers field.
return NeverSubscribedStreamDict(
can_remove_subscribers_group_id=can_remove_subscribers_group_id,
can_remove_subscribers_group=can_remove_subscribers_group_id,
date_created=date_created,
description=description,
first_message_id=first_message_id,
@ -443,7 +443,6 @@ def gather_subscriptions_helper(
stream_id = get_stream_id(sub_dict)
sub_unsub_stream_ids.add(stream_id)
raw_stream_dict = all_streams_map[stream_id]
stream_dict = build_stream_dict_for_sub(
user=user_profile,
sub_dict=sub_dict,

View File

@ -173,7 +173,7 @@ class SubscriptionStreamDict(TypedDict):
"""
audible_notifications: Optional[bool]
can_remove_subscribers_group_id: int
can_remove_subscribers_group: int
color: str
date_created: int
description: str
@ -200,7 +200,7 @@ class SubscriptionStreamDict(TypedDict):
class NeverSubscribedStreamDict(TypedDict):
can_remove_subscribers_group_id: int
can_remove_subscribers_group: int
date_created: int
description: str
first_message_id: Optional[int]
@ -223,7 +223,7 @@ class APIStreamDict(TypedDict):
with few exceptions and possible additional fields.
"""
can_remove_subscribers_group_id: int
can_remove_subscribers_group: int
date_created: int
description: str
first_message_id: Optional[int]

View File

@ -2708,7 +2708,7 @@ class Stream(models.Model):
def to_dict(self) -> APIStreamDict:
return APIStreamDict(
can_remove_subscribers_group_id=self.can_remove_subscribers_group_id,
can_remove_subscribers_group=self.can_remove_subscribers_group_id,
date_created=datetime_to_timestamp(self.date_created),
description=self.description,
first_message_id=self.first_message_id,

View File

@ -660,7 +660,7 @@ paths:
"in_home_view": true,
"email_address": "test_stream.af64447e9e39374841063747ade8e6b0.show-sender@testserver",
"stream_weekly_traffic": null,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
"subscribers": [10],
},
],
@ -1217,7 +1217,7 @@ paths:
"first_message_id": null,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
],
"id": 0,
@ -1263,7 +1263,7 @@ paths:
"first_message_id": null,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
],
"id": 0,
@ -1829,7 +1829,7 @@ paths:
"first_message_id": 1,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
{
"name": "Denmark",
@ -1843,7 +1843,7 @@ paths:
"first_message_id": 4,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
{
"name": "Verona",
@ -1857,7 +1857,7 @@ paths:
"first_message_id": 6,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
],
},
@ -1902,7 +1902,7 @@ paths:
"first_message_id": 1,
"message_retention_days": null,
"is_announcement_only": false,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
],
"id": 0,
@ -8840,17 +8840,21 @@ paths:
- Users can unsubscribe any user from a stream if they [have
access](/help/stream-permissions) to the stream and are a
member of the [user group](/api/get-user-groups) specified
by the [`can_remove_subscribers_group_id`][can-remove-parameter]
by the [`can_remove_subscribers_group`][can-remove-parameter]
for the stream.
**Changes**: Before Zulip 7.0 (feature level 161), the
**Changes**: Before Zulip 8.0 (feature level 197),
the `can_remove_subscribers_group` setting
was named `can_remove_subscribers_group_id`.
Before Zulip 7.0 (feature level 161), the
`can_remove_subscribers_group_id` for all streams was always
the system group for organization administrators.
Before Zulip 6.0 (feature level 145), users had no special
privileges for managing bots that they own.
[can-remove-parameter]: /api/subscribe#parameter-can_remove_subscribers_group_id
[can-remove-parameter]: /api/subscribe#parameter-can_remove_subscribers_group
x-curl-examples-parameters:
oneOf:
- type: include
@ -11571,7 +11575,7 @@ paths:
first_message_id:
nullable: true
is_announcement_only: {}
can_remove_subscribers_group_id: {}
can_remove_subscribers_group: {}
stream_weekly_traffic:
type: integer
nullable: true
@ -15680,7 +15684,7 @@ paths:
first_message_id:
nullable: true
is_announcement_only: {}
can_remove_subscribers_group_id: {}
can_remove_subscribers_group: {}
is_default:
type: boolean
description: |
@ -15792,7 +15796,7 @@ paths:
"rendered_description": "<p>A Scandinavian country</p>",
"stream_id": 7,
"stream_post_policy": 1,
"can_remove_subscribers_group_id": 2,
"can_remove_subscribers_group": 2,
},
}
"400":
@ -16977,7 +16981,7 @@ components:
first_message_id:
nullable: true
is_announcement_only: {}
can_remove_subscribers_group_id: {}
can_remove_subscribers_group: {}
BasicStreamBase:
type: object
description: |
@ -17079,13 +17083,17 @@ components:
**Changes**: Deprecated in Zulip 3.0 (feature level 1). Clients
should use `stream_post_policy` instead.
can_remove_subscribers_group_id:
can_remove_subscribers_group:
type: integer
description: |
ID of the user group whose members are allowed to unsubscribe others
from the stream.
**Changes**: New in Zulip 6.0 (feature level 142).
**Changes**: Before Zulip 8.0 (feature level 197),
the `can_remove_subscribers_group` setting
was named `can_remove_subscribers_group_id`.
New in Zulip 6.0 (feature level 142).
BasicBot:
allOf:
- $ref: "#/components/schemas/BasicBotBase"
@ -17726,13 +17734,17 @@ components:
If `null`, the stream was recently created and there is
insufficient data to estimate the average traffic.
can_remove_subscribers_group_id:
can_remove_subscribers_group:
type: integer
description: |
ID of the user group whose members are allowed to unsubscribe others
from the stream.
**Changes**: New in Zulip 6.0 (feature level 142).
**Changes**: Before Zulip 8.0 (feature level 197),
the `can_remove_subscribers_group` setting
was named `can_remove_subscribers_group_id`.
New in Zulip 6.0 (feature level 142).
DefaultStreamGroup:
type: object
description: |
@ -19313,7 +19325,7 @@ components:
example: "20"
required: false
CanRemoveSubscribersGroupId:
name: can_remove_subscribers_group_id
name: can_remove_subscribers_group
in: query
description: |
ID of the [user group](/api/get-user-groups) whose members are
@ -19326,7 +19338,11 @@ components:
system groups, except for the system groups named
`"role:internet"` and `"role:owners"`.
**Changes**: New in Zulip 7.0 (feature level 161).
**Changes**: Before Zulip 8.0 (feature level 197),
the `can_remove_subscribers_group` setting
was named `can_remove_subscribers_group_id`.
New in Zulip 7.0 (feature level 161).
schema:
type: integer
example: 20

View File

@ -226,7 +226,8 @@ class TestMiscStuff(ZulipTestCase):
in `APIStreamDict` and `APISubscriptionDict`, respectively.
"""
expected_fields = set(Stream.API_FIELDS) | {"stream_id"}
expected_fields -= {"id"}
expected_fields -= {"id", "can_remove_subscribers_group_id"}
expected_fields |= {"can_remove_subscribers_group"}
stream_dict_fields = set(APIStreamDict.__annotations__.keys())
computed_fields = {"is_announcement_only", "is_default"}
@ -490,7 +491,7 @@ class TestCreateStreams(ZulipTestCase):
"subscriptions": orjson.dumps(
[{"name": "new_stream1", "description": "First new stream"}]
).decode(),
"can_remove_subscribers_group_id": orjson.dumps(moderators_system_group.id).decode(),
"can_remove_subscribers_group": orjson.dumps(moderators_system_group.id).decode(),
}
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, subdomain="zulip")
self.assert_json_success(result)
@ -512,7 +513,7 @@ class TestCreateStreams(ZulipTestCase):
"subscriptions": orjson.dumps(
[{"name": "new_stream3", "description": "Third new stream"}]
).decode(),
"can_remove_subscribers_group_id": orjson.dumps(hamletcharacters_group.id).decode(),
"can_remove_subscribers_group": orjson.dumps(hamletcharacters_group.id).decode(),
}
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, subdomain="zulip")
self.assert_json_error(
@ -526,7 +527,7 @@ class TestCreateStreams(ZulipTestCase):
"subscriptions": orjson.dumps(
[{"name": "new_stream3", "description": "Third new stream"}]
).decode(),
"can_remove_subscribers_group_id": orjson.dumps(internet_group.id).decode(),
"can_remove_subscribers_group": orjson.dumps(internet_group.id).decode(),
}
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, subdomain="zulip")
self.assert_json_error(
@ -539,7 +540,7 @@ class TestCreateStreams(ZulipTestCase):
"subscriptions": orjson.dumps(
[{"name": "new_stream3", "description": "Third new stream"}]
).decode(),
"can_remove_subscribers_group_id": orjson.dumps(owners_group.id).decode(),
"can_remove_subscribers_group": orjson.dumps(owners_group.id).decode(),
}
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, subdomain="zulip")
self.assert_json_error(
@ -552,7 +553,7 @@ class TestCreateStreams(ZulipTestCase):
"subscriptions": orjson.dumps(
[{"name": "new_stream3", "description": "Third new stream"}]
).decode(),
"can_remove_subscribers_group_id": orjson.dumps(nobody_group.id).decode(),
"can_remove_subscribers_group": orjson.dumps(nobody_group.id).decode(),
}
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, subdomain="zulip")
self.assert_json_error(
@ -2167,14 +2168,14 @@ class StreamAdminTest(ZulipTestCase):
self.login("shiva")
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(moderators_system_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(moderators_system_group.id).decode()},
)
self.assert_json_error(result, "Must be an organization administrator")
self.login("iago")
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(moderators_system_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(moderators_system_group.id).decode()},
)
self.assert_json_success(result)
stream = get_stream("stream_name1", realm)
@ -2184,7 +2185,7 @@ class StreamAdminTest(ZulipTestCase):
hamletcharacters_group = UserGroup.objects.get(name="hamletcharacters", realm=realm)
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(hamletcharacters_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(hamletcharacters_group.id).decode()},
)
self.assert_json_error(
result, "'can_remove_subscribers_group' must be a system user group."
@ -2195,7 +2196,7 @@ class StreamAdminTest(ZulipTestCase):
)
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(internet_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(internet_group.id).decode()},
)
self.assert_json_error(
result,
@ -2205,7 +2206,7 @@ class StreamAdminTest(ZulipTestCase):
owners_group = UserGroup.objects.get(name="role:owners", is_system_group=True, realm=realm)
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(owners_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(owners_group.id).decode()},
)
self.assert_json_error(
result,
@ -2215,7 +2216,7 @@ class StreamAdminTest(ZulipTestCase):
nobody_group = UserGroup.objects.get(name="role:nobody", is_system_group=True, realm=realm)
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(nobody_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(nobody_group.id).decode()},
)
self.assert_json_error(
result,
@ -2227,14 +2228,14 @@ class StreamAdminTest(ZulipTestCase):
stream = self.make_stream("stream_name2", invite_only=True)
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(moderators_system_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(moderators_system_group.id).decode()},
)
self.assert_json_error(result, "Invalid stream ID")
self.subscribe(user_profile, "stream_name2")
result = self.client_patch(
f"/json/streams/{stream.id}",
{"can_remove_subscribers_group_id": orjson.dumps(moderators_system_group.id).decode()},
{"can_remove_subscribers_group": orjson.dumps(moderators_system_group.id).decode()},
)
self.assert_json_success(result)
stream = get_stream("stream_name2", realm)
@ -5800,7 +5801,8 @@ class GetSubscribersTest(ZulipTestCase):
}
expected_fields = set(Stream.API_FIELDS) | set(Subscription.API_FIELDS) | other_fields
expected_fields -= {"id"}
expected_fields -= {"id", "can_remove_subscribers_group_id"}
expected_fields |= {"can_remove_subscribers_group"}
for lst in [sub_data.subscriptions, sub_data.unsubscribed]:
for sub in lst:
@ -5814,7 +5816,8 @@ class GetSubscribersTest(ZulipTestCase):
}
expected_fields = set(Stream.API_FIELDS) | other_fields
expected_fields -= {"id"}
expected_fields -= {"id", "can_remove_subscribers_group_id"}
expected_fields |= {"can_remove_subscribers_group"}
for never_sub in sub_data.never_subscribed:
self.assertEqual(set(never_sub), expected_fields)

View File

@ -269,7 +269,9 @@ 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),
can_remove_subscribers_group_id: Optional[int] = REQ(
"can_remove_subscribers_group", json_validator=check_int, default=None
),
) -> HttpResponse:
# We allow realm administrators to to update the stream name and
# description even for private streams.
@ -393,7 +395,7 @@ def update_stream_backend(
if request_settings_dict[setting_group_id_name] is not None and request_settings_dict[
setting_group_id_name
] != getattr(stream, setting_name):
] != getattr(stream, setting_group_id_name):
if sub is None and stream.invite_only:
# Admins cannot change this setting for unsubscribed private streams.
raise JsonableError(_("Invalid stream ID"))
@ -570,7 +572,9 @@ def add_subscriptions_backend(
message_retention_days: Union[str, int] = REQ(
json_validator=check_string_or_int, default=RETENTION_DEFAULT
),
can_remove_subscribers_group_id: Optional[int] = REQ(json_validator=check_int, default=None),
can_remove_subscribers_group_id: Optional[int] = REQ(
"can_remove_subscribers_group", json_validator=check_int, default=None
),
announce: bool = REQ(json_validator=check_bool, default=False),
principals: Union[Sequence[str], Sequence[int]] = REQ(
json_validator=check_principals,
@ -591,11 +595,11 @@ def add_subscriptions_backend(
allow_nobody_group=False,
)
else:
can_remove_subscribers_group_default = Stream.stream_permission_group_settings[
can_remove_subscribers_group_default_name = Stream.stream_permission_group_settings[
"can_remove_subscribers_group"
].default_group_name
can_remove_subscribers_group = UserGroup.objects.get(
name=can_remove_subscribers_group_default,
name=can_remove_subscribers_group_default_name,
realm=user_profile.realm,
is_system_group=True,
)