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

This commit is contained in:
Sahil Batra 2021-11-24 13:08:20 +05:30 committed by Tim Abbott
parent 30c190a120
commit 8411c6eb21
1 changed files with 18 additions and 14 deletions

View File

@ -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);
}