create stream: Don't allow creating stream with zero subscribers.

Restrict users(even realm admins) from creating stream with zero
subscribers only in UI.
In backend, if subscribers are zero, we automatically subscribe
current user to stream.
This commit is contained in:
YJDave
2018-01-21 14:04:50 +05:30
committed by Tim Abbott
parent c3a289b473
commit e9e6b126ec
3 changed files with 25 additions and 2 deletions

View File

@@ -16,6 +16,22 @@ exports.get_name = function () {
return created_stream; return created_stream;
}; };
var stream_subscription_error = (function () {
var self = {};
self.report_no_subs_to_stream = function () {
$("#stream_subscription_error").text(i18n.t("You cannot create a stream with no subscribers!"));
$("#stream_subscription_error").show();
};
self.clear_errors = function () {
$("#stream_subscription_error").hide();
};
return self;
}());
var stream_name_error = (function () { var stream_name_error = (function () {
var self = {}; var self = {};
@@ -224,6 +240,7 @@ exports.show_new_stream_modal = function () {
stream_name_error.clear_errors(); stream_name_error.clear_errors();
$(".stream_create_info").hide(); $(".stream_create_info").hide();
stream_subscription_error.clear_errors();
$("#stream-checkboxes label.checkbox").on('change', function (e) { $("#stream-checkboxes label.checkbox").on('change', function (e) {
var elem = $(this); var elem = $(this);
@@ -326,6 +343,11 @@ $(function () {
} }
var principals = get_principals(); var principals = get_principals();
if (principals.length === 0) {
stream_subscription_error.report_no_subs_to_stream();
return;
}
if (principals.length >= 50) { if (principals.length >= 50) {
var invites_warning_modal = templates.render('subscription_invites_warning_modal', var invites_warning_modal = templates.render('subscription_invites_warning_modal',
{stream_name: stream_name, {stream_name: stream_name,

View File

@@ -241,7 +241,7 @@ form#add_new_subscription {
width: calc(100% - 15px); width: calc(100% - 15px);
} }
#stream_name_error { .stream_creation_error {
display: none; display: none;
margin-left: 2px; margin-left: 2px;
color: hsl(0, 100%, 50%); color: hsl(0, 100%, 50%);

View File

@@ -10,7 +10,7 @@
</div> </div>
<input type="text" name="stream_name" id="create_stream_name" <input type="text" name="stream_name" id="create_stream_name"
placeholder="{{t 'Stream name' }}" value="" autocomplete="off" /> placeholder="{{t 'Stream name' }}" value="" autocomplete="off" />
<div id="stream_name_error"></div> <div id="stream_name_error" class="stream_creation_error"></div>
</section> </section>
<section class="block"> <section class="block">
<div class="stream-title"> <div class="stream-title">
@@ -60,6 +60,7 @@
<label class="stream-title" for="people_to_add"> <label class="stream-title" for="people_to_add">
{{t "People to add" }} {{t "People to add" }}
</label> </label>
<div id="stream_subscription_error" class="stream_creation_error"></div>
<div class="controls" id="people_to_add"></div> <div class="controls" id="people_to_add"></div>
</section> </section>
</div> </div>