org settings: Extract setting for new user waiting period.

This commit separates the `waiting_period_threshold` setting from
the `create_stream_policy` setting, adding a new setting that the user
can use to select a waiting period threshold.

Both the invite to stream policy and create stream policy now have
three options: admins only, members and admins, or members after
waiting period/admins.
This commit is contained in:
David Wood 2019-05-07 18:06:05 +01:00 committed by Tim Abbott
parent 5e53e3d960
commit 6b9a9b1e31
5 changed files with 250 additions and 75 deletions

View File

@ -85,9 +85,9 @@ function submit_permissions_change() {
casper.click('#org-submit-other-permissions');
}
// Test setting limiting stream creation to administrators
// Test setting create streams policy to 'admins only'.
casper.then(function () {
casper.test.info("Test setting limiting stream creation to administrators");
casper.test.info("Test setting create streams policy to 'admins only'.");
casper.waitUntilVisible("#id_realm_create_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_create_stream_policy").val("by_admins_only").change();
@ -97,50 +97,137 @@ casper.then(function () {
});
casper.then(function () {
// Test setting was activated
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions',
'Saved');
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
// Test setting create streams policy to 'members and admins'.
casper.then(function () {
casper.test.info("Test setting create streams policy to 'members and admins'.");
casper.waitUntilVisible("#id_realm_create_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_create_stream_policy").val("by_admin_user_with_custom_time").change();
$("#id_realm_waiting_period_threshold").val('6');
$("#id_realm_create_stream_policy").val("by_members").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test setting was activated
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions',
'Saved');
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
casper.waitUntilVisible('#id_realm_create_stream_policy', function () {
// Test setting was saved
casper.test.assertEval(function () {
return $('input[type="text"][id="id_realm_waiting_period_threshold"]').val() === '6';
}, 'Waiting period threshold set to 6 days');
// Deactivate setting
casper.evaluate(function () {
$("#id_realm_create_stream_policy").val("by_admins_only").change();
// Test setting create streams policy to 'full members'.
casper.then(function () {
casper.test.info("Test setting create streams policy to 'waiting period.");
casper.waitUntilVisible("#id_realm_create_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_create_stream_policy").val("by_full_members").change();
});
submit_permissions_change();
});
submit_permissions_change();
});
casper.then(function () {
// Test setting was activated
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions',
'Saved');
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
// Test setting invite to streams policy to 'admins only'.
casper.then(function () {
casper.test.info("Test setting invite to streams policy to 'admins only'.");
casper.waitUntilVisible("#id_realm_invite_to_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_invite_to_stream_policy").val("by_admins_only").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
// Test setting invite to streams policy to 'members and admins'.
casper.then(function () {
casper.test.info("Test setting invite to streams policy to 'members and admins'.");
casper.waitUntilVisible("#id_realm_invite_to_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_invite_to_stream_policy").val("by_members").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
// Test setting invite to streams policy to 'full members'.
casper.then(function () {
casper.test.info("Test setting invite to streams policy to 'waiting period'.");
casper.waitUntilVisible("#id_realm_invite_to_stream_policy", function () {
casper.evaluate(function () {
$("#id_realm_invite_to_stream_policy").val("by_full_members").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
});
});
// Test setting new user threshold to three days.
casper.then(function () {
casper.test.info("Test setting new user threshold to three days.");
casper.waitUntilVisible("#id_realm_waiting_period_setting", function () {
casper.evaluate(function () {
$("#id_realm_waiting_period_setting").val("three_days").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
casper.test.assertNotVisible('#id_realm_waiting_period_threshold');
});
});
// Test setting new user threshold to N days.
casper.then(function () {
casper.test.info("Test setting new user threshold to N days.");
casper.waitUntilVisible("#id_realm_waiting_period_setting", function () {
casper.evaluate(function () {
$("#id_realm_waiting_period_setting").val("custom_days").change();
});
submit_permissions_change();
});
});
casper.then(function () {
// Test that save worked.
casper.waitUntilVisible('#org-submit-other-permissions[data-status="saved"]', function () {
casper.test.assertSelectorHasText('#org-submit-other-permissions', 'Saved');
casper.test.assertVisible('#id_realm_waiting_period_threshold');
});
});

View File

@ -215,14 +215,10 @@ function test_submit_settings_form(submit_form) {
save_button.replace = () => {
return `${subsection}`;
};
$("#id_realm_create_stream_policy").val("by_anyone");
$("#id_realm_add_emoji_by_admins_only").val("by_anyone");
const invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
invite_to_stream_policy_elem.val("1");
invite_to_stream_policy_elem.attr('id', 'id_realm_invite_to_stream_policy');
invite_to_stream_policy_elem.data = () => {
return "integer";
};
$("#id_realm_create_stream_policy").val("by_members");
$("#id_realm_invite_to_stream_policy").val("by_members");
$("#id_realm_waiting_period_threshold").val(10);
const bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
bot_creation_policy_elem.val("1");
bot_creation_policy_elem.attr('id', 'id_realm_bot_creation_policy');
@ -239,7 +235,6 @@ function test_submit_settings_form(submit_form) {
let subsection_elem = $(`#org-${subsection}`);
subsection_elem.set_find_results('.setting-widget', [
bot_creation_policy_elem,
invite_to_stream_policy_elem,
email_address_visibility_elem,
]);
@ -249,11 +244,11 @@ function test_submit_settings_form(submit_form) {
let expected_value = {
bot_creation_policy: '1',
invite_to_stream_policy: '1',
invite_to_stream_policy: 1,
email_address_visibility: '1',
add_emoji_by_admins_only: false,
create_stream_policy: '1',
waiting_period_threshold: 0,
create_stream_policy: 1,
waiting_period_threshold: 10,
};
assert.deepEqual(data, expected_value);
@ -507,24 +502,55 @@ function test_sync_realm_settings() {
}
{
/* Test create new stream permission settings sync */
/*
Test that when create stream policy is set to "full members" 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');
const waiting_period_input_parent = $.create('stub-waiting-period-input-parent');
$("#id_realm_waiting_period_threshold").set_parent(waiting_period_input_parent);
page_params.realm_create_stream_policy = 3;
page_params.realm_waiting_period_threshold = 3;
settings_org.sync_realm_settings('create_stream_policy');
assert.equal($("#id_realm_create_stream_policy").val(), "by_admin_user_with_three_days_old");
assert.equal(waiting_period_input_parent.visible(), false);
assert.equal($("#id_realm_create_stream_policy").val(), "by_full_members");
}
{
/* Test invite to stream policy settings sync */
/*
Test that when create stream policy is set to "by members" 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 = 1;
settings_org.sync_realm_settings('create_stream_policy');
assert.equal($("#id_realm_create_stream_policy").val(), "by_members");
}
{
/*
Test that when create stream policy is set to "by admins 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 = 2;
settings_org.sync_realm_settings('create_stream_policy');
assert.equal($("#id_realm_create_stream_policy").val(), "by_admins_only");
}
{
/*
Test that when invite to stream policy is set to "full members" 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');
@ -532,7 +558,37 @@ function test_sync_realm_settings() {
page_params.realm_invite_to_stream_policy = 3;
settings_org.sync_realm_settings('invite_to_stream_policy');
assert.equal($("#id_realm_invite_to_stream_policy").val(), "by_members_with_waiting_period");
assert.equal($("#id_realm_invite_to_stream_policy").val(), "by_full_members");
}
{
/*
Test that when create stream policy is set to "by members" 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 = 1;
settings_org.sync_realm_settings('invite_to_stream_policy');
assert.equal($("#id_realm_invite_to_stream_policy").val(), "by_members");
}
{
/*
Test that when create stream policy is set to "by admins 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 = 2;
settings_org.sync_realm_settings('invite_to_stream_policy');
assert.equal($("#id_realm_invite_to_stream_policy").val(), "by_admins_only");
}
{
@ -719,7 +775,6 @@ run_test('set_up', () => {
};
simulate_tip_box();
$('#id_realm_create_stream_policy').change = set_callback('realm_create_stream_policy');
$('#id_realm_video_chat_provider').change = set_callback('realm_video_chat_provider');
$("#id_realm_org_join_restrictions").change = set_callback('change_org_join_restrictions');
$('#submit-add-realm-domain').click = set_callback('add_realm_domain');
@ -760,9 +815,10 @@ run_test('set_up', () => {
$("#id_realm_digest_weekday").set_parent($.create('<stub digest weekday setting dropdown>'));
$("#id_realm_msg_edit_limit_setting").change = noop;
$('#id_realm_msg_delete_limit_setting').change = noop;
$("#allowed_domains_label").set_parent($.create('<stub-allowed-domain-label-parent>'));
const waiting_period_parent_elem = $.create('waiting-period-parent-stub');
$('#id_realm_waiting_period_threshold').set_parent(waiting_period_parent_elem);
$("#allowed_domains_label").set_parent($.create('<stub-allowed-domain-label-parent>'));
$("#id_realm_waiting_period_setting").change = noop;
const allow_topic_edit_label_parent = $.create('allow-topic-edit-label-parent');
$('#id_realm_allow_community_topic_editing_label').set_parent(allow_topic_edit_label_parent);

View File

@ -76,18 +76,26 @@ function get_property_value(property_name) {
return exports.get_realm_time_limits_in_minutes('realm_message_content_delete_limit_seconds');
}
if (property_name === 'realm_waiting_period_setting') {
if (page_params.realm_waiting_period_threshold === 0) {
return "none";
}
if (page_params.realm_waiting_period_threshold === 3) {
return "three_days";
}
return "custom_days";
}
if (property_name === 'realm_create_stream_policy') {
if (page_params.realm_create_stream_policy === 2) {
return "by_admins_only";
}
if (page_params.realm_create_stream_policy === 1) {
return "by_anyone";
return "by_members";
}
if (page_params.realm_create_stream_policy === 3 &&
page_params.realm_waiting_period_threshold === 3) {
return "by_admin_user_with_three_days_old";
if (page_params.realm_create_stream_policy === 3) {
return "by_full_members";
}
return "by_admin_user_with_custom_time";
}
if (property_name === 'realm_invite_to_stream_policy') {
@ -162,16 +170,21 @@ exports.extract_property_name = function (elem) {
return elem.attr('id').split('-').join('_').replace("id_", "");
};
function set_create_stream_policy_dropdown() {
var value = get_property_value("realm_create_stream_policy");
$("#id_realm_create_stream_policy").val(value);
if (value === "by_admin_user_with_custom_time") {
function set_realm_waiting_period_dropdown() {
var value = get_property_value("realm_waiting_period_setting");
$("#id_realm_waiting_period_setting").val(value);
if (value === "custom_days") {
$("#id_realm_waiting_period_threshold").parent().show();
} else {
$("#id_realm_waiting_period_threshold").parent().hide();
}
}
function set_create_stream_policy_dropdown() {
var value = get_property_value("realm_create_stream_policy");
$("#id_realm_create_stream_policy").val(value);
}
function set_invite_to_stream_policy_dropdown() {
var value = get_property_value("realm_invite_to_stream_policy");
$("#id_realm_invite_to_stream_policy").val(value);
@ -419,7 +432,9 @@ exports.populate_signup_notifications_stream_dropdown = function (stream_list) {
};
function update_dependent_subsettings(property_name) {
if (property_name === 'realm_create_stream_policy' || property_name === 'realm_waiting_period_threshold') {
if (property_name === 'realm_waiting_period_threshold') {
set_realm_waiting_period_dropdown();
} else if (property_name === 'realm_create_stream_policy') {
set_create_stream_policy_dropdown();
} else if (property_name === 'realm_invite_to_stream_policy') {
set_invite_to_stream_policy_dropdown();
@ -598,6 +613,7 @@ exports.build_page = function () {
return data;
}
set_realm_waiting_period_dropdown();
set_create_stream_policy_dropdown();
set_invite_to_stream_policy_dropdown();
set_add_emoji_permission_dropdown();
@ -739,6 +755,7 @@ exports.build_page = function () {
data.message_retention_days = new_message_retention_days !== "" ?
JSON.stringify(parseInt(new_message_retention_days, 10)) : null;
} else if (subsection === 'other_permissions') {
var waiting_period_threshold = $("#id_realm_waiting_period_setting").val();
var create_stream_policy = $("#id_realm_create_stream_policy").val();
var invite_to_stream_policy = $("#id_realm_invite_to_stream_policy").val();
var add_emoji_permission = $("#id_realm_add_emoji_by_admins_only").val();
@ -751,15 +768,10 @@ exports.build_page = function () {
if (create_stream_policy === "by_admins_only") {
data.create_stream_policy = 2;
} else if (create_stream_policy === "by_admin_user_with_three_days_old") {
data.create_stream_policy = 3;
data.waiting_period_threshold = 3;
} else if (create_stream_policy === "by_admin_user_with_custom_time") {
data.create_stream_policy = 3;
data.waiting_period_threshold = $("#id_realm_waiting_period_threshold").val();
} else if (create_stream_policy === "by_anyone") {
} else if (create_stream_policy === "by_members") {
data.create_stream_policy = 1;
data.waiting_period_threshold = 0;
} else if (create_stream_policy === "by_full_members") {
data.create_stream_policy = 3;
}
if (invite_to_stream_policy === "by_admins_only") {
@ -769,6 +781,14 @@ exports.build_page = function () {
} else if (invite_to_stream_policy === "by_full_members") {
data.invite_to_stream_policy = 3;
}
if (waiting_period_threshold === "none") {
data.waiting_period_threshold = 0;
} else if (waiting_period_threshold === "three_days") {
data.waiting_period_threshold = 3;
} else if (waiting_period_threshold === "custom_days") {
data.waiting_period_threshold = $("#id_realm_waiting_period_threshold").val();
}
} else if (subsection === 'org_join') {
var org_join_restrictions = $('#id_realm_org_join_restrictions').val();
if (org_join_restrictions === "only_selected_domain") {
@ -840,10 +860,10 @@ exports.build_page = function () {
}
});
$("#id_realm_create_stream_policy").change(function () {
var create_stream_policy = this.value;
$("#id_realm_waiting_period_setting").change(function () {
var waiting_period_threshold = this.value;
var node = $("#id_realm_waiting_period_threshold").parent();
if (create_stream_policy === 'by_admin_user_with_custom_time') {
if (waiting_period_threshold === 'custom_days') {
node.show();
} else {
node.hide();

View File

@ -1540,6 +1540,7 @@ body:not(.night-mode) #account-settings .custom_user_field .datepicker {
pointer-events: all;
}
#id_realm_waiting_period_setting,
#id_realm_create_stream_policy,
#id_realm_invite_to_stream_policy,
#id_realm_org_join_restrictions,

View File

@ -66,28 +66,39 @@
</div>
<div class="m-10 inline-block organization-permissions-parent">
<div class="input-group">
<label for="realm_create_stream_policy" class="dropdown-title">{{t "Who can create streams" }}</label>
<select name="realm_create_stream_policy" id="id_realm_create_stream_policy" class="prop-element">
<option value="by_anyone">{{t "Members and admins" }}</option>
<option value="by_admins_only">{{t "Admins only" }}</option>
<option value="by_admin_user_with_three_days_old">{{t "All admins, and members with accounts at least 3 days old" }}</option>
<option value="by_admin_user_with_custom_time">{{t "All admins, and members with accounts at least N days old" }}</option>
<label for="realm_waiting_period_setting" class="dropdown-title">
{{t "Waiting period before new members turn into full members" }}
</label>
<select name="realm_waiting_period_setting" id="id_realm_waiting_period_setting" class="prop-element">
<option value="none">{{t "None" }}</option>
<option value="three_days">{{t "3 days" }}</option>
<option value="custom_days">{{t "Custom" }}</option>
</select>
</div>
{{!-- This setting is hidden unless `custom_days` --}}
<div class="dependent-block">
<label for="aitin" class="inline-block">{{t "Minimum account age (N)" }}:</label>
<label for="aitin" class="inline-block">{{t "Waiting period (days)" }}:</label>
<input type="text" id="id_realm_waiting_period_threshold"
name="realm_waiting_period_threshold"
class="admin-realm-time-limit-input prop-element"
value="{{ realm_waiting_period_threshold }}"/>
</div>
<div class="input-group">
<label for="realm_create_stream_policy" class="dropdown-title">{{t "Who can create streams" }}</label>
<select name="realm_create_stream_policy" id="id_realm_create_stream_policy" class="prop-element">
<option value="by_members">{{t "Members and admins" }}</option>
<option value="by_admins_only">{{t "Admins only" }}</option>
<option value="by_full_members">{{t "Admins and full members" }}</option>
</select>
</div>
<div class="input-group">
<label for="realm_invite_to_stream_policy" class="dropdown-title">{{t "Who can add users to streams" }}</label>
<select name="realm_invite_to_stream_policy" id="id_realm_invite_to_stream_policy" class="prop-element">
<option value="by_members">{{t "Members and admins" }}</option>
<option value="by_admins_only">{{t "Admins only" }}</option>
<option value="by_full_members">{{t "All admins and members who can create streams" }}</option>
<option value="by_full_members">{{t "Admins and full members" }}</option>
</select>
</div>