Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

server: Add defensive assertions for permission checks.

Tim Abbott2c9a1e085cc8
diff --git a/zerver/views/invite.py b/zerver/views/invite.py
index 8bd27b0e7a8..010f8ccf703 100644
--- a/zerver/views/invite.py
+++ b/zerver/views/invite.py
@@ -49,6 +49,7 @@ def invite_users_backend(
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")
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)
diff --git a/zerver/views/streams.py b/zerver/views/streams.py
index 18fce81f606..d16567032b2 100644
--- a/zerver/views/streams.py
+++ b/zerver/views/streams.py
@@ -520,8 +520,11 @@ def add_subscriptions_backend(
)
# Realm.POLICY_MEMBERS_ONLY only fails if the
# user is a guest, which happens in the decorator above.
- assert 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."))
+ 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")
subscribers = {
principal_to_user_profile(user_profile, principal) for principal in principals
}