setting: Add moderator option in create stream and invite to stream policy.

This commit adds 'admins and moderators' option for create_stream_policy
and invite_to_stream_policy in frontend.
This commit is contained in:
sahil839 2021-04-22 01:13:27 +05:30 committed by Tim Abbott
parent f9503a4681
commit 6a58cf922f
4 changed files with 75 additions and 4 deletions

View File

@ -148,6 +148,14 @@ run_test("user_can_subscribe_other_users", () => {
page_params.is_admin = false;
assert.equal(can_subscribe_other_users(), false);
page_params.is_moderator = true;
page_params.realm_invite_to_stream_policy =
settings_config.common_policy_values.by_moderators_only.code;
assert.equal(can_subscribe_other_users(), true);
page_params.is_moderator = false;
assert.equal(can_subscribe_other_users(), false);
page_params.is_guest = true;
page_params.realm_invite_to_stream_policy =
settings_config.common_policy_values.by_members.code;
@ -179,6 +187,14 @@ run_test("user_can_create_streams", () => {
page_params.is_admin = false;
assert.equal(can_create_streams(), false);
page_params.is_moderator = true;
page_params.realm_create_stream_policy =
settings_config.common_policy_values.by_moderators_only.code;
assert.equal(can_create_streams(), true);
page_params.is_moderator = false;
assert.equal(can_create_streams(), false);
page_params.is_guest = true;
page_params.realm_create_stream_policy = settings_config.common_policy_values.by_members.code;
assert.equal(can_create_streams(), false);

View File

@ -505,6 +505,24 @@ function test_sync_realm_settings() {
);
}
{
/*
Test that when create stream policy is set to "by moderators only" that the dropdown
is set to the correct value.
*/
const property_elem = $("#id_realm_create_stream_policy");
property_elem.length = 1;
property_elem.attr("id", "id_realm_create_stream_policy");
page_params.realm_create_stream_policy = 4;
settings_org.sync_realm_settings("create_stream_policy");
assert.equal(
$("#id_realm_create_stream_policy").val(),
settings_config.common_policy_values.by_moderators_only.code,
);
}
{
/*
Test that when invite to stream policy is set to "full members" that the dropdown
@ -559,6 +577,24 @@ function test_sync_realm_settings() {
);
}
{
/*
Test that when invite to stream policy is set to "by moderators only" that the dropdown
is set to the correct value.
*/
const property_elem = $("#id_realm_invite_to_stream_policy");
property_elem.length = 1;
property_elem.attr("id", "id_realm_invite_to_stream_policy");
page_params.realm_invite_to_stream_policy = 4;
settings_org.sync_realm_settings("invite_to_stream_policy");
assert.equal(
$("#id_realm_invite_to_stream_policy").val(),
settings_config.common_policy_values.by_moderators_only.code,
);
}
{
/* Test message content edit limit minutes sync */
const property_elem = $("#id_realm_message_content_edit_limit_minutes");
@ -815,14 +851,20 @@ test("test get_organization_settings_options", () => {
description: $t({defaultMessage: "Admins"}),
},
{
key: "by_full_members",
key: "by_moderators_only",
order: 2,
code: 4,
description: $t({defaultMessage: "Admins and moderators"}),
},
{
key: "by_full_members",
order: 3,
code: 3,
description: $t({defaultMessage: "Admins and full members"}),
},
{
key: "by_members",
order: 3,
order: 4,
code: 1,
description: $t({defaultMessage: "Admins and members"}),
},

View File

@ -109,13 +109,18 @@ export const common_policy_values = {
code: 2,
description: $t({defaultMessage: "Admins"}),
},
by_full_members: {
by_moderators_only: {
order: 2,
code: 4,
description: $t({defaultMessage: "Admins and moderators"}),
},
by_full_members: {
order: 3,
code: 3,
description: $t({defaultMessage: "Admins and full members"}),
},
by_members: {
order: 3,
order: 4,
code: 1,
description: $t({defaultMessage: "Admins and members"}),
},

View File

@ -95,6 +95,14 @@ function user_has_permission(policy_value) {
return false;
}
if (page_params.is_moderator) {
return true;
}
if (policy_value === settings_config.common_policy_values.by_moderators_only.code) {
return false;
}
if (policy_value === settings_config.common_policy_values.by_members.code) {
return true;
}