Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

streams: Modify get_stream_permission_policy_name to return dict key.

Ritwik187a008f13a4
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index 8a884592faf..2d3bede91cb 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -39,7 +39,7 @@ from zerver.lib.streams import (
can_access_stream_metadata_user_ids,
check_basic_stream_access,
get_anonymous_group_membership_dict_for_streams,
- get_stream_permission_policy_name,
+ get_stream_permission_policy_key,
get_stream_post_policy_value_based_on_group_setting,
get_user_ids_with_metadata_access_via_permission_groups,
get_users_dict_with_metadata_access_to_streams_via_permission_groups,
@@ -1377,16 +1377,18 @@ def do_change_stream_permission(
)
send_event_on_commit(stream.realm, event, notify_stream_update_ids)
- old_policy_name = get_stream_permission_policy_name(
+ old_policy_key = get_stream_permission_policy_key(
invite_only=old_invite_only_value,
history_public_to_subscribers=old_history_public_to_subscribers_value,
is_web_public=old_is_web_public_value,
)
- new_policy_name = get_stream_permission_policy_name(
+ old_policy_name = Stream.PERMISSION_POLICIES[old_policy_key]["policy_name"]
+ new_policy_key = get_stream_permission_policy_key(
invite_only=stream.invite_only,
history_public_to_subscribers=stream.history_public_to_subscribers,
is_web_public=stream.is_web_public,
)
+ new_policy_name = Stream.PERMISSION_POLICIES[new_policy_key]["policy_name"]
send_change_stream_permission_notification(
stream,
old_policy_name=old_policy_name,
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index 0b01cda0beb..6cd6e7eafc8 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -90,24 +90,24 @@ class StreamDict(TypedDict, total=False):
can_subscribe_group: UserGroup | None
-def get_stream_permission_policy_name(
+def get_stream_permission_policy_key(
*,
invite_only: bool | None = None,
history_public_to_subscribers: bool | None = None,
is_web_public: bool | None = None,
) -> str:
- policy_name = None
- for permission_dict in Stream.PERMISSION_POLICIES.values():
+ policy_key = None
+ for permission_key, permission_dict in Stream.PERMISSION_POLICIES.items():
if (
permission_dict["invite_only"] == invite_only
and permission_dict["history_public_to_subscribers"] == history_public_to_subscribers
and permission_dict["is_web_public"] == is_web_public
):
- policy_name = permission_dict["policy_name"]
+ policy_key = permission_key
break
- assert policy_name is not None
- return policy_name
+ assert policy_key is not None
+ return policy_key
def get_default_value_for_history_public_to_subscribers(
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index f45ad1ddea4..436fbd3c25c 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -72,7 +72,7 @@ from zerver.lib.streams import (
filter_stream_authorization_for_adding_subscribers,
get_anonymous_group_membership_dict_for_streams,
get_stream_permission_default_group,
- get_stream_permission_policy_name,
+ get_stream_permission_policy_key,
list_to_streams,
stream_to_dict,
user_has_content_access,
@@ -879,6 +879,12 @@ def send_messages_for_new_subscribers(
stream_description = "*" + _("No description.") + "*"
else:
stream_description = stream.description
+
+ policy_key = get_stream_permission_policy_key(
+ invite_only=stream.invite_only,
+ history_public_to_subscribers=stream.history_public_to_subscribers,
+ is_web_public=stream.is_web_public,
+ )
notifications.append(
internal_prep_stream_message(
sender=sender,
@@ -888,11 +894,7 @@ def send_messages_for_new_subscribers(
"**{policy}** channel created by {user_name}. **Description:**"
).format(
user_name=silent_mention_syntax_for_user(user_profile),
- policy=get_stream_permission_policy_name(
- invite_only=stream.invite_only,
- history_public_to_subscribers=stream.history_public_to_subscribers,
- is_web_public=stream.is_web_public,
- ),
+ policy=Stream.PERMISSION_POLICIES[policy_key]["policy_name"],
)
+ f"\n```` quote\n{stream_description}\n````",
),