validate_user_access: Assert user_profile is not None.

This function is only called in cases where user_profile isn't None,
and the code reads better if we just check that first rather than
checking it on every line that accesses user_profile.
This commit is contained in:
Tim Abbott
2016-07-26 16:54:16 -07:00
parent d1adbd798b
commit 884f50cdd7

View File

@@ -1126,14 +1126,16 @@ def validate_user_access_to_subscribers_helper(user_profile, stream_dict, check_
* check_user_subscribed is a function that when called with no * check_user_subscribed is a function that when called with no
arguments, will report whether the user is subscribed to the stream arguments, will report whether the user is subscribed to the stream
""" """
if user_profile is not None and user_profile.realm_id != stream_dict["realm_id"]: if user_profile is None:
raise ValidationError("Requesting user not on given realm") raise ValidationError("Missing user to validate access for")
if user_profile.realm_id != stream_dict["realm_id"]:
raise ValidationError("Requesting user not in given realm")
if stream_dict["realm__domain"] == "mit.edu" and not stream_dict["invite_only"]: if stream_dict["realm__domain"] == "mit.edu" and not stream_dict["invite_only"]:
raise JsonableError(_("You cannot get subscribers for public streams in this realm")) raise JsonableError(_("You cannot get subscribers for public streams in this realm"))
if (user_profile is not None and stream_dict["invite_only"] and if (stream_dict["invite_only"] and not check_user_subscribed()):
not check_user_subscribed()):
raise JsonableError(_("Unable to retrieve subscribers for invite-only stream")) raise JsonableError(_("Unable to retrieve subscribers for invite-only stream"))
# sub_dict is a dictionary mapping stream_id => whether the user is subscribed to that stream # sub_dict is a dictionary mapping stream_id => whether the user is subscribed to that stream