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: Check permission to post messages to access channel email.

Sahil Batra29b44932ba67
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 948a6112c19..017d494d7ab 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 448**
+
+* [`GET /streams/{stream_id}/email_address`](/api/get-stream-email-address):
+ Users have access to a channel's email address only if they have permission
+ to post messages in the channel.
+
**Feature level 447**
* `PATCH /bots/{bot_id}`: Added `short_name` parameter to support updating bot's email.
diff --git a/version.py b/version.py
index 4d3a1e353ee..34757e98e71 100644
--- a/version.py
+++ b/version.py
@@ -35,7 +35,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 447
+API_FEATURE_LEVEL = 448
# 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
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index a4864b4ccc5..d49aa63d740 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -23034,7 +23034,14 @@ paths:
description: |
Get email address of a channel.
- **Changes**: New in Zulip 8.0 (feature level 226).
+ Note that only users with permission to post messages in the channel
+ can access the channel's email address.
+
+ **Changes**: Prior to Zulip 12.0 (feature level 448), users without
+ permission to post messages in the channel could access the channel's email
+ if they had metadata access.
+
+ New in Zulip 8.0 (feature level 226).
parameters:
- $ref: "#/components/parameters/ChannelIdInPath"
- name: sender_id
diff --git a/zerver/tests/test_channel_fetch.py b/zerver/tests/test_channel_fetch.py
index e472772012c..17097b7891b 100644
--- a/zerver/tests/test_channel_fetch.py
+++ b/zerver/tests/test_channel_fetch.py
@@ -457,6 +457,23 @@ class GetStreamsTest(ZulipTestCase):
)
self.assertEqual(json["email"], hamlet_denmark_email)
+ # Users without permission to post cannot access the channel email.
+ owners_group = NamedUserGroup.objects.get(
+ name=SystemGroups.OWNERS, realm_for_sharding=realm
+ )
+ do_change_stream_group_based_setting(
+ denmark_stream, "can_send_message_group", owners_group, acting_user=iago
+ )
+ result = self.client_get(f"/json/streams/{denmark_stream.id}/email_address")
+ self.assert_json_error(result, "You do not have permission to post in this channel.")
+
+ everyone_group = NamedUserGroup.objects.get(
+ name=SystemGroups.EVERYONE, realm_for_sharding=realm
+ )
+ do_change_stream_group_based_setting(
+ denmark_stream, "can_send_message_group", everyone_group, acting_user=iago
+ )
+
self.login("polonius")
result = self.client_get(f"/json/streams/{denmark_stream.id}/email_address")
self.assert_json_error(result, "Invalid channel ID")
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index fd7cb7d91ae..7714f05a9d7 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -73,6 +73,7 @@ from zerver.lib.streams import (
access_stream_by_id,
access_stream_by_name,
access_stream_for_delete_or_update_requiring_metadata_access,
+ access_stream_for_send_message,
access_web_public_stream,
channel_events_topic_name,
check_channel_creation_permissions,
@@ -1401,6 +1402,7 @@ def get_stream_email_address(
user_profile,
stream_id,
)
+ access_stream_for_send_message(user_profile, stream, forwarder_user_profile=None)
email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id)
if sender_id is None or sender_id == email_gateway_bot.id: