Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
invite: Raise same error for all values of invite_to_realm_policy.
sahil839adec45777d76
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 0203c852d61..3cc0eece2f4 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -1255,7 +1255,7 @@ class InviteUserTest(InviteUserBase):invitee = f"Alice Test <{email}>, {email2}"self.assert_json_error(self.invite(invitee, ["Denmark"]),- "Only administrators can invite others to this organization.",+ "Insufficient permission",)# Now verify an administrator can do it@@ -1279,7 +1279,7 @@ class InviteUserTest(InviteUserBase):invitee = f"Carol Test <{email}>, {email2}"self.assert_json_error(self.invite(invitee, ["Denmark"]),- "Only administrators and moderators can invite others to this organization.",+ "Insufficient permission",)self.login("shiva")@@ -1323,7 +1323,7 @@ class InviteUserTest(InviteUserBase):invitee = f"Issac Test <{email}>, {email2}"self.assert_json_error(self.invite(invitee, ["Denmark"]),- "Your account is too new to invite others to this organization.",+ "Insufficient permission",)do_set_realm_property(realm, "waiting_period_threshold", 0, acting_user=None)diff --git a/zerver/views/invite.py b/zerver/views/invite.pyindex 01bc7a5c039..9c759a06059 100644--- a/zerver/views/invite.py+++ b/zerver/views/invite.py@@ -18,7 +18,7 @@ from zerver.lib.request import REQ, JsonableError, has_request_variablesfrom zerver.lib.response import json_error, json_successfrom zerver.lib.streams import access_stream_by_idfrom zerver.lib.validator import check_int, check_list-from zerver.models import MultiuseInvite, PreregistrationUser, Realm, Stream, UserProfile+from zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfiledef check_if_owner_required(invited_as: int, user_profile: UserProfile) -> None:@@ -40,16 +40,9 @@ def invite_users_backend() -> HttpResponse:if not user_profile.can_invite_others_to_realm():- if user_profile.realm.invite_to_realm_policy == Realm.POLICY_ADMINS_ONLY:- return json_error(_("Only administrators can invite others to this organization."))- if user_profile.realm.invite_to_realm_policy == Realm.POLICY_MODERATORS_ONLY:- return json_error(- _("Only administrators and moderators can invite others to this organization.")- )- if user_profile.realm.invite_to_realm_policy == Realm.POLICY_FULL_MEMBERS_ONLY:- return json_error(_("Your account is too new to invite others to this organization."))- # Guest case will be handled by require_member_or_admin decorator.- raise AssertionError("Unexpected policy validation failure")+ # Guest users case will not be handled here as it will+ # be handled by the decorator above.+ raise JsonableError(_("Insufficient permission"))if invite_as not in PreregistrationUser.INVITE_AS.values():return json_error(_("Must be invited as an valid type of user"))check_if_owner_required(invite_as, user_profile)