settings: Add user_can_create_web_public_streams function.

This commit adds user_can_create_web_public_streams function
in settings_data.js which will be used in further commits
to disable or hide the UI elements for creating web-public
streams.
This commit is contained in:
Sahil Batra 2021-11-19 22:06:00 +05:30 committed by Tim Abbott
parent 56a8443f05
commit 443d8b6a65
4 changed files with 98 additions and 0 deletions

View File

@ -283,3 +283,49 @@ run_test("user_can_invite_others_to_realm_nobody_case", () => {
settings_config.invite_to_realm_policy_values.nobody.code; settings_config.invite_to_realm_policy_values.nobody.code;
assert.equal(settings_data.user_can_invite_others_to_realm(), false); assert.equal(settings_data.user_can_invite_others_to_realm(), false);
}); });
run_test("user_can_create_web_public_streams", () => {
page_params.is_owner = true;
page_params.server_web_public_streams_enabled = true;
page_params.realm_enable_spectator_access = true;
page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.nobody.code;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.by_owners_only.code;
assert.equal(settings_data.user_can_create_web_public_streams(), true);
page_params.realm_enable_spectator_access = false;
page_params.server_web_public_streams_enabled = true;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_enable_spectator_access = true;
page_params.server_web_public_streams_enabled = false;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_enable_spectator_access = false;
page_params.server_web_public_streams_enabled = false;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_enable_spectator_access = true;
page_params.server_web_public_streams_enabled = true;
page_params.is_owner = false;
page_params.is_admin = true;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.by_admins_only.code;
assert.equal(settings_data.user_can_create_web_public_streams(), true);
page_params.is_admin = false;
page_params.is_moderator = true;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
page_params.realm_create_web_public_stream_policy =
settings_config.create_web_public_stream_policy_values.by_moderators_only.code;
assert.equal(settings_data.user_can_create_web_public_streams(), true);
page_params.is_moderator = false;
assert.equal(settings_data.user_can_create_web_public_streams(), false);
});

View File

@ -12,14 +12,17 @@ export const page_params: {
is_admin: boolean; is_admin: boolean;
is_guest: boolean; is_guest: boolean;
is_moderator: boolean; is_moderator: boolean;
is_owner: boolean;
is_spectator: boolean; is_spectator: boolean;
realm_add_custom_emoji_policy: number; realm_add_custom_emoji_policy: number;
realm_avatar_changes_disabled: boolean; realm_avatar_changes_disabled: boolean;
realm_create_private_stream_policy: number; realm_create_private_stream_policy: number;
realm_create_public_stream_policy: number; realm_create_public_stream_policy: number;
realm_create_web_public_stream_policy: number;
realm_delete_own_message_policy: number; realm_delete_own_message_policy: number;
realm_edit_topic_policy: number; realm_edit_topic_policy: number;
realm_email_address_visibility: number; realm_email_address_visibility: number;
realm_enable_spectator_access: boolean;
realm_invite_to_realm_policy: number; realm_invite_to_realm_policy: number;
realm_invite_to_stream_policy: number; realm_invite_to_stream_policy: number;
realm_move_messages_between_streams_policy: number; realm_move_messages_between_streams_policy: number;
@ -30,6 +33,7 @@ export const page_params: {
request_language: string; request_language: string;
server_avatar_changes_disabled: boolean; server_avatar_changes_disabled: boolean;
server_name_changes_disabled: boolean; server_name_changes_disabled: boolean;
server_web_public_streams_enabled: boolean;
translation_data: Record<string, string>; translation_data: Record<string, string>;
zulip_plan_is_not_limited: boolean; zulip_plan_is_not_limited: boolean;
} = $("#page-params").remove().data("params"); } = $("#page-params").remove().data("params");

View File

@ -227,6 +227,29 @@ export const wildcard_mention_policy_values = {
}, },
}; };
export const create_web_public_stream_policy_values = {
by_moderators_only: {
order: 1,
code: 4,
description: $t({defaultMessage: "Admins and moderators"}),
},
by_admins_only: {
order: 2,
code: 2,
description: $t({defaultMessage: "Admins only"}),
},
by_owners_only: {
order: 3,
code: 7,
description: $t({defaultMessage: "Owners only"}),
},
nobody: {
order: 4,
code: 6,
description: $t({defaultMessage: "Nobody"}),
},
};
export const common_message_policy_values = { export const common_message_policy_values = {
by_everyone: { by_everyone: {
order: 1, order: 1,

View File

@ -181,6 +181,31 @@ export function user_can_create_public_streams(): boolean {
return user_has_permission(page_params.realm_create_public_stream_policy); return user_has_permission(page_params.realm_create_public_stream_policy);
} }
export function user_can_create_web_public_streams(): boolean {
if (
!page_params.server_web_public_streams_enabled ||
!page_params.realm_enable_spectator_access
) {
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);
}
export function user_can_move_messages_between_streams(): boolean { export function user_can_move_messages_between_streams(): boolean {
return user_has_permission(page_params.realm_move_messages_between_streams_policy); return user_has_permission(page_params.realm_move_messages_between_streams_policy);
} }