From 884f50cdd75ae62b8baffc24166d0be14549826d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 26 Jul 2016 16:54:16 -0700 Subject: [PATCH] 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. --- zerver/lib/actions.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 7ff7559661..f492a6401b 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -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 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"]: - raise ValidationError("Requesting user not on given realm") + if user_profile is None: + 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"]: raise JsonableError(_("You cannot get subscribers for public streams in this realm")) - if (user_profile is not None and stream_dict["invite_only"] and - not check_user_subscribed()): + if (stream_dict["invite_only"] and not check_user_subscribed()): 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