mirror of
https://github.com/zulip/zulip.git
synced 2026-07-09 21:21:47 +08:00
invite: Raise same error for all values of invite_to_realm_policy.
We keep the error message same for all cases when a user is not allowed to invite others for all values of invite_to_realm_policy. We raise error with different message for guest cases because it is handled by decorators. We aim to change this behavior in future. Explaining the details in error message isn't much important as we do not show errors probably in API only, as we do not the show the options itself in the frontend.
This commit is contained in:
parent
abcfd40b29
commit
adec45777d
@ -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)
|
||||
|
||||
@ -18,7 +18,7 @@ from zerver.lib.request import REQ, JsonableError, has_request_variables
|
||||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.streams import access_stream_by_id
|
||||
from zerver.lib.validator import check_int, check_list
|
||||
from zerver.models import MultiuseInvite, PreregistrationUser, Realm, Stream, UserProfile
|
||||
from zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfile
|
||||
|
||||
|
||||
def 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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user