streams: Raise same error for all values of invite_to_stream_policy.

We keep the error message same for all cases when a user is not
allowed to subscribe others for all values of invite_to_stream_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:
sahil839
2021-04-08 00:48:33 +05:30
committed by Tim Abbott
parent 1ffcb0f8b9
commit 39c9845cb0
2 changed files with 7 additions and 23 deletions

View File

@@ -512,19 +512,9 @@ def add_subscriptions_backend(
_("You can only invite other Zephyr mirroring users to private streams.")
)
if not user_profile.can_subscribe_other_users():
if user_profile.realm.invite_to_stream_policy == Realm.POLICY_ADMINS_ONLY:
return json_error(_("Only administrators can modify other users' subscriptions."))
if user_profile.realm.invite_to_stream_policy == Realm.POLICY_MODERATORS_ONLY:
return json_error(
_("Only administrators and moderators can modify other users' subscriptions.")
)
# Realm.POLICY_MEMBERS_ONLY only fails if the
# user is a guest, which happens in the decorator above.
if user_profile.realm.invite_to_stream_policy == Realm.POLICY_FULL_MEMBERS_ONLY:
return json_error(
_("Your account is too new to modify other users' subscriptions.")
)
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"))
subscribers = {
principal_to_user_profile(user_profile, principal) for principal in principals
}