settings: Focus "Add a new bot" tab when there is no active bot.

Fixes: #8872.
This commit is contained in:
Shubham Dhama 2018-03-30 01:41:32 +05:30
parent 0ef195ecc2
commit aca2364455
2 changed files with 15 additions and 1 deletions

View File

@ -9,6 +9,7 @@ set_global("page_params", {
set_global("avatar", {});
set_global('$', global.make_zjquery());
set_global('i18n', global.stub_i18n);
set_global('document', 'document-stub');
zrequire('bot_data');
@ -112,6 +113,7 @@ function test_create_bot_type_input_box_toggle(f) {
global.compile_template('embedded_bot_config_item');
avatar.build_bot_create_widget = function () {};
avatar.build_bot_edit_widget = function () {};
settings_bots.setup_bot_creation_policy_values();
settings_bots.set_up();
}());

View File

@ -55,7 +55,10 @@ function render_bots() {
$('#active_bots_list').empty();
$('#inactive_bots_list').empty();
_.each(bot_data.get_all_bots_for_current_user(), function (elem) {
var all_bots_for_current_user = bot_data.get_all_bots_for_current_user();
var user_owns_an_active_bot = false;
_.each(all_bots_for_current_user, function (elem) {
add_bot_row({
name: elem.full_name,
email: elem.email,
@ -66,8 +69,17 @@ function render_bots() {
is_active: elem.is_active,
zuliprc: 'zuliprc', // Most browsers do not allow filename starting with `.`
});
user_owns_an_active_bot = user_owns_an_active_bot || elem.is_active;
});
if (page_params.is_admin || page_params.realm_bot_creation_policy !==
exports.bot_creation_policy_values.admins_only.code) {
if (!user_owns_an_active_bot) {
focus_tab.add_a_new_bot_tab();
return;
}
}
if ($("#bots_lists_navbar .add-a-new-bot-tab").hasClass("active")) {
$("#add-a-new-bot-form").show();
$("#active_bots_list").hide();