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.

settings_data: Move checks for nobody and owners_only case to user_has_permission.

Sahil Batra8411c6eb2148
diff --git a/static/js/settings_data.ts b/static/js/settings_data.ts
index 41200326175..3b826113501 100644
--- a/static/js/settings_data.ts
+++ b/static/js/settings_data.ts
@@ -113,6 +113,24 @@ export function user_can_change_logo(): boolean {
}
function user_has_permission(policy_value: number): boolean {
+ /* At present, nobody and by_owners_only is not present in
+ * common_policy_values, but we include a check for it here,
+ * so that code using create_web_public_stream_policy_values
+ * or other supersets can use this function. */
+ if (policy_value === settings_config.create_web_public_stream_policy_values.nobody.code) {
+ return false;
+ }
+
+ if (page_params.is_owner) {
+ return true;
+ }
+
+ if (
+ policy_value === settings_config.create_web_public_stream_policy_values.by_owners_only.code
+ ) {
+ return false;
+ }
+
if (page_params.is_admin) {
return true;
}
@@ -189,20 +207,6 @@ export function user_can_create_web_public_streams(): boolean {
return false;
}
- if (
- page_params.realm_create_web_public_stream_policy ===
- settings_config.create_web_public_stream_policy_values.nobody.code
- ) {
- return false;
- }
-
- if (
- page_params.realm_create_web_public_stream_policy ===
- settings_config.create_web_public_stream_policy_values.by_owners_only.code
- ) {
- return page_params.is_owner;
- }
-
return user_has_permission(page_params.realm_create_web_public_stream_policy);
}