streams: Add create and edit ui for is_announcement_only.

The user can now specify the value while creating a stream.
An admin can later change it via `Change stream permissions`
modal. Add is_announcement_only to subscription type text.
This commit is contained in:
Shubham Padia
2018-05-30 19:32:13 +05:30
committed by Tim Abbott
parent 518764b843
commit 214ce1ccca
7 changed files with 30 additions and 3 deletions

View File

@@ -1259,6 +1259,9 @@ run_test('handlebars_bug', () => {
assert.equal(other_options[1].value, 'invite-only-public-history'); assert.equal(other_options[1].value, 'invite-only-public-history');
assert.equal(other_options[2].value, 'invite-only'); assert.equal(other_options[2].value, 'invite-only');
var is_announcement_only = $(html).find("input[name=is-announcement-only]");
assert.equal(is_announcement_only.prop('checked'), false);
var button = $(html).find("#change-stream-privacy-button"); var button = $(html).find("#change-stream-privacy-button");
assert(button.hasClass("btn-danger")); assert(button.hasClass("btn-danger"));
assert.equal(button.text().trim(), "translated: Save changes"); assert.equal(button.text().trim(), "translated: Save changes");

View File

@@ -98,7 +98,7 @@ var stream_name_error = (function () {
}()); }());
function ajaxSubscribeForCreation(stream_name, description, principals, invite_only, function ajaxSubscribeForCreation(stream_name, description, principals, invite_only,
announce, history_public_to_subscribers) { is_announcement_only, announce, history_public_to_subscribers) {
// Subscribe yourself and possible other people to a new stream. // Subscribe yourself and possible other people to a new stream.
return channel.post({ return channel.post({
url: "/json/users/me/subscriptions", url: "/json/users/me/subscriptions",
@@ -106,6 +106,7 @@ function ajaxSubscribeForCreation(stream_name, description, principals, invite_o
description: description}]), description: description}]),
principals: JSON.stringify(principals), principals: JSON.stringify(principals),
invite_only: JSON.stringify(invite_only), invite_only: JSON.stringify(invite_only),
is_announcement_only: JSON.stringify(is_announcement_only),
announce: JSON.stringify(announce), announce: JSON.stringify(announce),
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers), history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
}, },
@@ -171,6 +172,7 @@ function create_stream() {
var stream_name = $.trim($("#create_stream_name").val()); var stream_name = $.trim($("#create_stream_name").val());
var description = $.trim($("#create_stream_description").val()); var description = $.trim($("#create_stream_description").val());
var privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val(); var privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val();
var is_announcement_only = $('#stream_creation_form input[name=is-announcement-only]').prop('checked');
var principals = get_principals(); var principals = get_principals();
var invite_only; var invite_only;
@@ -199,6 +201,7 @@ function create_stream() {
description, description,
principals, principals,
invite_only, invite_only,
is_announcement_only,
announce, announce,
history_public_to_subscribers history_public_to_subscribers
); );

View File

@@ -344,6 +344,7 @@ function change_stream_privacy(e) {
var sub = stream_data.get_sub_by_id(stream_id); var sub = stream_data.get_sub_by_id(stream_id);
var privacy_setting = $('#stream_privacy_modal input[name=privacy]:checked').val(); var privacy_setting = $('#stream_privacy_modal input[name=privacy]:checked').val();
var is_announcement_only = $('#stream_privacy_modal input[name=is-announcement-only]').prop('checked');
var invite_only; var invite_only;
var history_public_to_subscribers; var history_public_to_subscribers;
@@ -364,6 +365,7 @@ function change_stream_privacy(e) {
stream_name: sub.name, stream_name: sub.name,
// toggle the privacy setting // toggle the privacy setting
is_private: JSON.stringify(invite_only), is_private: JSON.stringify(invite_only),
is_announcement_only: JSON.stringify(is_announcement_only),
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers), history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
}; };
@@ -376,6 +378,7 @@ function change_stream_privacy(e) {
// save new privacy settings. // save new privacy settings.
sub.invite_only = invite_only; sub.invite_only = invite_only;
sub.is_announcement_only = is_announcement_only;
sub.history_public_to_subscribers = history_public_to_subscribers; sub.history_public_to_subscribers = history_public_to_subscribers;
redraw_privacy_related_stuff(sub_row, sub); redraw_privacy_related_stuff(sub_row, sub);
@@ -508,6 +511,7 @@ exports.initialize = function () {
var template_data = { var template_data = {
stream_id: stream_id, stream_id: stream_id,
stream_name: stream.name, stream_name: stream.name,
is_announcement_only: stream.is_announcement_only,
is_public: !stream.invite_only, is_public: !stream.invite_only,
is_private: stream.invite_only && !stream.history_public_to_subscribers, is_private: stream.invite_only && !stream.history_public_to_subscribers,
is_private_with_public_history: (stream.invite_only && is_private_with_public_history: (stream.invite_only &&

View File

@@ -589,6 +589,10 @@ form#add_new_subscription {
margin: 5px; margin: 5px;
} }
.stream-creation-body #make-invite-only .grey-box .checkbox {
margin: 5px;
}
#announce-new-stream { #announce-new-stream {
margin-top: 10px; margin-top: 10px;
} }
@@ -962,7 +966,10 @@ form#add_new_subscription {
padding: 5px 0px; padding: 5px 0px;
} }
#stream_privacy_modal ul.grey-box li input[type=checkbox], #stream_privacy_modal ul.grey-box li input[type=checkbox] {
margin-top: 4px;
}
#subscription_overlay ul.grey-box li input[type=checkbox] { #subscription_overlay ul.grey-box li input[type=checkbox] {
margin-top: 0px; margin-top: 0px;
} }

View File

@@ -23,4 +23,11 @@
{{/tr}} {{/tr}}
</label> </label>
</li> </li>
<li>
<label class="checkbox">
<input type="checkbox" name="is-announcement-only" value="is-announcement-only" {{#if is_announcement_only}}checked{{/if}}/>
<span></span>
{{#tr this}}Restrict posting to organization administrators{{/tr}}
</label>
</li>
</ul> </ul>

View File

@@ -6,3 +6,6 @@
{{else}} {{else}}
{{t 'This is a <span class="icon-vector-globe"></span> <b>public stream</b>. Anybody in your organization can join.' }} {{t 'This is a <span class="icon-vector-globe"></span> <b>public stream</b>. Anybody in your organization can join.' }}
{{/if}} {{/if}}
{{#if is_announcement_only}}
{{t 'Only organization administrators can post.'}}
{{/if}}

View File

@@ -1620,7 +1620,7 @@ def create_stream_if_needed(realm: Realm,
stream_name: str, stream_name: str,
*, *,
invite_only: bool=False, invite_only: bool=False,
is_announcement_only: Optional[bool]=False, is_announcement_only: bool=False,
history_public_to_subscribers: Optional[bool]=None, history_public_to_subscribers: Optional[bool]=None,
stream_description: str="") -> Tuple[Stream, bool]: stream_description: str="") -> Tuple[Stream, bool]: