Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
users: Extract access_user_common function.
Sahil Batraa46501353d3d
diff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex b9892124bfd..ec778a48844 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -241,6 +241,25 @@ def access_bot_by_id(user_profile: UserProfile, user_id: int) -> UserProfile:return target+def access_user_common(+ target: UserProfile,+ user_profile: UserProfile,+ allow_deactivated: bool,+ allow_bots: bool,+ for_admin: bool,+) -> UserProfile:+ if target.is_bot and not allow_bots:+ raise JsonableError(_("No such user"))+ if not target.is_active and not allow_deactivated:+ raise JsonableError(_("User is deactivated"))+ if not for_admin:+ # Administrative access is not required just to read a user.+ return target+ if not user_profile.can_admin_user(target):+ raise JsonableError(_("Insufficient permission"))+ return target++def access_user_by_id(user_profile: UserProfile,target_user_id: int,@@ -258,16 +277,8 @@ def access_user_by_id(target = get_user_profile_by_id_in_realm(target_user_id, user_profile.realm)except UserProfile.DoesNotExist:raise JsonableError(_("No such user"))- if target.is_bot and not allow_bots:- raise JsonableError(_("No such user"))- if not target.is_active and not allow_deactivated:- raise JsonableError(_("User is deactivated"))- if not for_admin:- # Administrative access is not required just to read a user.- return target- if not user_profile.can_admin_user(target):- raise JsonableError(_("Insufficient permission"))- return target++ return access_user_common(target, user_profile, allow_deactivated, allow_bots, for_admin)class Accounts(TypedDict):