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.

streams: Raise same error for all values of create_stream_policy.

sahil8391ffcb0f8b956
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index 8367c75e60d..a9d91ce98a5 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -617,13 +617,9 @@ def list_to_streams(
else:
# autocreate=True path starts here
if not user_profile.can_create_streams():
- if user_profile.realm.create_stream_policy == Realm.POLICY_ADMINS_ONLY:
- raise JsonableError(_("Only administrators can create streams."))
- if user_profile.realm.create_stream_policy == Realm.POLICY_MODERATORS_ONLY:
- raise JsonableError(_("Only administrators and moderators can create streams."))
- if user_profile.realm.create_stream_policy == Realm.POLICY_FULL_MEMBERS_ONLY:
- raise JsonableError(_("Your account is too new to create streams."))
- raise JsonableError(_("Not allowed for guest users"))
+ # Guest users case will not be handled here as it will be
+ # handled by the decorator in add_subscriptions_backend.
+ raise JsonableError(_("Insufficient permission"))
elif not autocreate:
raise JsonableError(
_("Stream(s) ({}) do not exist").format(
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index 9589f593c89..d23ee21d4fa 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -1761,7 +1761,7 @@ class StreamAdminTest(ZulipTestCase):
# Cannot create stream because not an admin.
stream_name = ["admins_only"]
result = self.common_subscribe_to_streams(user_profile, stream_name, allow_fail=True)
- self.assert_json_error(result, "Only administrators can create streams.")
+ self.assert_json_error(result, "Insufficient permission")
# Make current user an admin.
do_change_user_role(user_profile, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
@@ -1789,7 +1789,7 @@ class StreamAdminTest(ZulipTestCase):
# period.
stream_name = ["waiting_period"]
result = self.common_subscribe_to_streams(user_profile, stream_name, allow_fail=True)
- self.assert_json_error(result, "Your account is too new to create streams.")
+ self.assert_json_error(result, "Insufficient permission")
# Make user account 11 days old..
user_profile.date_joined = timezone_now() - timedelta(days=11)
@@ -3239,7 +3239,7 @@ class SubscriptionAPITest(ZulipTestCase):
)
with mock.patch("zerver.models.UserProfile.can_create_streams", return_value=False):
result = self.common_subscribe_to_streams(self.test_user, ["stream1"], allow_fail=True)
- self.assert_json_error(result, "Only administrators can create streams.")
+ self.assert_json_error(result, "Insufficient permission")
with mock.patch("zerver.models.UserProfile.can_create_streams", return_value=True):
self.common_subscribe_to_streams(self.test_user, ["stream2"])
@@ -3261,7 +3261,7 @@ class SubscriptionAPITest(ZulipTestCase):
["new_stream1"],
allow_fail=True,
)
- self.assert_json_error(result, "Only administrators can create streams.")
+ self.assert_json_error(result, "Insufficient permission")
do_change_user_role(user_profile, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
self.common_subscribe_to_streams(user_profile, ["new_stream1"])
@@ -3278,7 +3278,7 @@ class SubscriptionAPITest(ZulipTestCase):
["new_stream2"],
allow_fail=True,
)
- self.assert_json_error(result, "Only administrators and moderators can create streams.")
+ self.assert_json_error(result, "Insufficient permission")
do_change_user_role(user_profile, UserProfile.ROLE_MODERATOR, acting_user=None)
self.common_subscribe_to_streams(user_profile, ["new_stream2"])
@@ -3309,7 +3309,7 @@ class SubscriptionAPITest(ZulipTestCase):
["new_stream4"],
allow_fail=True,
)
- self.assert_json_error(result, "Your account is too new to create streams.")
+ self.assert_json_error(result, "Insufficient permission")
do_set_realm_property(realm, "waiting_period_threshold", 0, acting_user=None)
self.common_subscribe_to_streams(user_profile, ["new_stream3"])
@@ -3711,7 +3711,7 @@ class SubscriptionAPITest(ZulipTestCase):
}
]
- with self.assertRaisesRegex(JsonableError, "Not allowed for guest users"):
+ with self.assertRaisesRegex(JsonableError, "Insufficient permission"):
list_to_streams(streams_raw, guest_user)
stream = self.make_stream("private_stream", invite_only=True)