diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js index 8abfd5ceb7..e032bb726c 100644 --- a/frontend_tests/node_tests/settings_bots.js +++ b/frontend_tests/node_tests/settings_bots.js @@ -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(); }()); diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js index de27cf92da..93ff5d0125 100644 --- a/static/js/settings_bots.js +++ b/static/js/settings_bots.js @@ -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();