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:
Shubham Padia
2025-02-06 11:09:31 +00:00
committed by Tim Abbott
parent 98c5243c9b
commit 9e09a240d7
2 changed files with 8 additions and 5 deletions

View File

@@ -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
)
]

View File

@@ -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