def get_subscription_backend(request: HttpRequest, user_profile: UserProfile, user_id: int=REQ(validator=check_int, path_only=True), stream_id: int=REQ(validator=check_int, path_only=True), ) -> HttpResponse: target_user = access_user_by_id(user_profile, user_id, read_only=True) (stream, recipient, sub) = access_stream_by_id(user_profile, stream_id) subscription_status = {'is_subscribed': subscribed_to_stream(target_user, stream_id)} return json_success(subscription_status)
def get_subscription_backend( request: HttpRequest, user_profile: UserProfile, user_id: int = REQ(json_validator=check_int, path_only=True), stream_id: int = REQ(json_validator=check_int, path_only=True), ) -> HttpResponse: target_user = access_user_by_id(user_profile, user_id, for_admin=False) (stream, sub) = access_stream_by_id(user_profile, stream_id, allow_realm_admin=True) subscription_status = { "is_subscribed": subscribed_to_stream(target_user, stream_id) } return json_success(request, data=subscription_status)
def validate_user_access_to_subscribers(user_profile: Optional[UserProfile], stream: Stream) -> None: """Validates whether the user can view the subscribers of a stream. Raises a JsonableError if: * The user and the stream are in different realms * The realm is MIT and the stream is not invite only. * The stream is invite only, requesting_user is passed, and that user does not subscribe to the stream. """ validate_user_access_to_subscribers_helper( user_profile, { "realm_id": stream.realm_id, "is_web_public": stream.is_web_public, "invite_only": stream.invite_only, }, # We use a lambda here so that we only compute whether the # user is subscribed if we have to lambda user_profile: subscribed_to_stream(user_profile, stream.id), )