settings: Migrate to stream_post_policy structure.

This commit includes a new `stream_post_policy` setting,
by replacing the `is_announcement_only` field from the Stream model,
which is done by mirroring the structure of the existing
`create_stream_policy`.

It includes the necessary schema and database migrations to migrate
the is_announcement_only boolean field to stream_post_policy,
a smallPositiveInteger field similar to many other settings.

This change is done to allow organization administrators to restrict
new members from creating and posting to a stream. However, this does
not affect admins who are new members.

With many tweaks by tabbott to documentation under /help, etc.

Fixes #13616.
This commit is contained in:
Ryan Rehman
2020-02-05 02:20:55 +05:30
committed by Tim Abbott
parent 31aecc0abb
commit 174b2abcfd
60 changed files with 525 additions and 189 deletions

View File

@@ -98,7 +98,7 @@ const stream_name_error = (function () {
}());
function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_only,
is_announcement_only, announce, history_public_to_subscribers) {
stream_post_policy, announce, history_public_to_subscribers) {
// TODO: We can eliminate the user_ids -> principals conversion
// once we upgrade the backend to accept user_ids.
const persons = _.compact(_.map(user_ids, (user_id) => {
@@ -114,7 +114,7 @@ function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_onl
description: description}]),
principals: JSON.stringify(principals),
invite_only: JSON.stringify(invite_only),
is_announcement_only: JSON.stringify(is_announcement_only),
stream_post_policy: JSON.stringify(stream_post_policy),
announce: JSON.stringify(announce),
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
},
@@ -182,12 +182,18 @@ function create_stream() {
const stream_name = $.trim($("#create_stream_name").val());
const description = $.trim($("#create_stream_description").val());
const privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val();
const is_announcement_only = $('#stream_creation_form input[name=is-announcement-only]').prop('checked');
let stream_post_policy = parseInt($('#stream_creation_form input[name=stream-post-policy]').val(), 10);
const principals = get_principals();
let invite_only;
let history_public_to_subscribers;
// Because the stream_post_policy field is hidden when non-administrators create streams,
// we need to set the default value here.
if (isNaN(stream_post_policy)) {
stream_post_policy = stream_data.stream_post_policy_values.everyone.code;
}
if (privacy_setting === 'invite-only') {
invite_only = true;
history_public_to_subscribers = false;
@@ -219,7 +225,7 @@ function create_stream() {
description,
principals,
invite_only,
is_announcement_only,
stream_post_policy,
announce,
history_public_to_subscribers
);