mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
stream: Pass is_subscribed
to check_basic_stream_access
.
Earlier, we were passing the whole subscription object to the function in order to check if the user was subscribed or not. In the future commits, we want to check that without fetching and passing the complete subscription object and this commit will help us do that.
This commit is contained in:
committed by
Tim Abbott
parent
98c5243c9b
commit
9e09a240d7
@@ -913,7 +913,7 @@ def send_subscription_remove_events(
|
||||
stream
|
||||
for stream in streams_by_user[user_profile.id]
|
||||
if not check_basic_stream_access(
|
||||
user_profile, stream, sub=None, allow_realm_admin=True
|
||||
user_profile, stream, is_subscribed=False, allow_realm_admin=True
|
||||
)
|
||||
]
|
||||
|
||||
|
@@ -484,7 +484,8 @@ def access_stream_for_delete_or_update(
|
||||
def check_basic_stream_access(
|
||||
user_profile: UserProfile,
|
||||
stream: Stream,
|
||||
sub: Subscription | None,
|
||||
*,
|
||||
is_subscribed: bool,
|
||||
allow_realm_admin: bool = False,
|
||||
) -> bool:
|
||||
# Any realm user, even guests, can access web_public streams.
|
||||
@@ -496,7 +497,7 @@ def check_basic_stream_access(
|
||||
return True
|
||||
|
||||
# Or if you are subscribed to the stream, you can access it.
|
||||
if sub is not None:
|
||||
if is_subscribed:
|
||||
return True
|
||||
|
||||
# For some specific callers (e.g. getting list of subscribers,
|
||||
@@ -538,7 +539,7 @@ def access_stream_common(
|
||||
sub = None
|
||||
|
||||
if not stream.deactivated and check_basic_stream_access(
|
||||
user_profile, stream, sub, allow_realm_admin=allow_realm_admin
|
||||
user_profile, stream, is_subscribed=sub is not None, allow_realm_admin=allow_realm_admin
|
||||
):
|
||||
return sub
|
||||
|
||||
@@ -777,7 +778,9 @@ def can_access_stream_history_by_id(user_profile: UserProfile, stream_id: int) -
|
||||
def can_remove_subscribers_from_stream(
|
||||
stream: Stream, user_profile: UserProfile, sub: Subscription | None
|
||||
) -> bool:
|
||||
if not check_basic_stream_access(user_profile, stream, sub, allow_realm_admin=True):
|
||||
if not check_basic_stream_access(
|
||||
user_profile, stream, is_subscribed=sub is not None, allow_realm_admin=True
|
||||
):
|
||||
return False
|
||||
|
||||
# Optimization for the organization administrator code path. We
|
||||
|
Reference in New Issue
Block a user