mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
streams: Make /streams endpoint return also web-public streams.
This commit modifies the /streams endpoint so that the web-public streams are included in the default list of streams that users have access to. This is part of PR #14638 that aims to allow guest users to browse and subscribe themselves to web public streams.
This commit is contained in:
@@ -5520,7 +5520,7 @@ def get_web_public_streams(realm: Realm) -> List[Dict[str, Any]]:
|
|||||||
return streams
|
return streams
|
||||||
|
|
||||||
def do_get_streams(
|
def do_get_streams(
|
||||||
user_profile: UserProfile, include_public: bool=True,
|
user_profile: UserProfile, include_public: bool=True, include_web_public: bool=False,
|
||||||
include_subscribed: bool=True, include_all_active: bool=False,
|
include_subscribed: bool=True, include_all_active: bool=False,
|
||||||
include_default: bool=False, include_owner_subscribed: bool=False,
|
include_default: bool=False, include_owner_subscribed: bool=False,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
@@ -5552,6 +5552,9 @@ def do_get_streams(
|
|||||||
if include_public:
|
if include_public:
|
||||||
invite_only_check = Q(invite_only=False)
|
invite_only_check = Q(invite_only=False)
|
||||||
add_filter_option(invite_only_check)
|
add_filter_option(invite_only_check)
|
||||||
|
if include_web_public:
|
||||||
|
web_public_check = Q(is_web_public=True)
|
||||||
|
add_filter_option(web_public_check)
|
||||||
if include_owner_subscribed and user_profile.is_bot:
|
if include_owner_subscribed and user_profile.is_bot:
|
||||||
bot_owner = user_profile.bot_owner
|
bot_owner = user_profile.bot_owner
|
||||||
assert bot_owner is not None
|
assert bot_owner is not None
|
||||||
|
|||||||
@@ -4315,6 +4315,14 @@ paths:
|
|||||||
type: boolean
|
type: boolean
|
||||||
default: true
|
default: true
|
||||||
example: false
|
example: false
|
||||||
|
- name: include_web_public
|
||||||
|
in: query
|
||||||
|
description: |
|
||||||
|
Include all web public streams.
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
example: true
|
||||||
- name: include_subscribed
|
- name: include_subscribed
|
||||||
in: query
|
in: query
|
||||||
description: |
|
description: |
|
||||||
|
|||||||
@@ -1508,6 +1508,28 @@ class DefaultStreamTest(ZulipTestCase):
|
|||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
self.assertFalse(stream_name in self.get_default_stream_names(user_profile.realm))
|
self.assertFalse(stream_name in self.get_default_stream_names(user_profile.realm))
|
||||||
|
|
||||||
|
def test_guest_user_access_to_streams(self) -> None:
|
||||||
|
user_profile = self.example_user("polonius")
|
||||||
|
self.login_user(user_profile)
|
||||||
|
self.assertEqual(user_profile.role, UserProfile.ROLE_GUEST)
|
||||||
|
|
||||||
|
# Get all the streams that Polonius has access to (subscribed + web public streams)
|
||||||
|
result = self.client_get('/json/streams?include_web_public=true')
|
||||||
|
streams = result.json()['streams']
|
||||||
|
subscribed, unsubscribed, never_subscribed = gather_subscriptions_helper(user_profile)
|
||||||
|
self.assertEqual(len(streams),
|
||||||
|
len(subscribed) + len(unsubscribed) + len(never_subscribed))
|
||||||
|
expected_streams = subscribed + unsubscribed + never_subscribed
|
||||||
|
stream_names = [
|
||||||
|
stream['name']
|
||||||
|
for stream in streams
|
||||||
|
]
|
||||||
|
expected_stream_names = [
|
||||||
|
stream['name']
|
||||||
|
for stream in expected_streams
|
||||||
|
]
|
||||||
|
self.assertEqual(set(stream_names), set(expected_stream_names))
|
||||||
|
|
||||||
class DefaultStreamGroupTest(ZulipTestCase):
|
class DefaultStreamGroupTest(ZulipTestCase):
|
||||||
def test_create_update_and_remove_default_stream_group(self) -> None:
|
def test_create_update_and_remove_default_stream_group(self) -> None:
|
||||||
realm = get_realm("zulip")
|
realm = get_realm("zulip")
|
||||||
|
|||||||
@@ -597,6 +597,7 @@ def get_subscribers_backend(request: HttpRequest, user_profile: UserProfile,
|
|||||||
def get_streams_backend(
|
def get_streams_backend(
|
||||||
request: HttpRequest, user_profile: UserProfile,
|
request: HttpRequest, user_profile: UserProfile,
|
||||||
include_public: bool=REQ(validator=check_bool, default=True),
|
include_public: bool=REQ(validator=check_bool, default=True),
|
||||||
|
include_web_public: bool=REQ(validator=check_bool, default=False),
|
||||||
include_subscribed: bool=REQ(validator=check_bool, default=True),
|
include_subscribed: bool=REQ(validator=check_bool, default=True),
|
||||||
include_all_active: bool=REQ(validator=check_bool, default=False),
|
include_all_active: bool=REQ(validator=check_bool, default=False),
|
||||||
include_default: bool=REQ(validator=check_bool, default=False),
|
include_default: bool=REQ(validator=check_bool, default=False),
|
||||||
@@ -604,6 +605,7 @@ def get_streams_backend(
|
|||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
|
|
||||||
streams = do_get_streams(user_profile, include_public=include_public,
|
streams = do_get_streams(user_profile, include_public=include_public,
|
||||||
|
include_web_public=include_web_public,
|
||||||
include_subscribed=include_subscribed,
|
include_subscribed=include_subscribed,
|
||||||
include_all_active=include_all_active,
|
include_all_active=include_all_active,
|
||||||
include_default=include_default,
|
include_default=include_default,
|
||||||
|
|||||||
Reference in New Issue
Block a user