diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js index f8ae6f8035..2f4909e4d9 100644 --- a/frontend_tests/node_tests/bot_data.js +++ b/frontend_tests/node_tests/bot_data.js @@ -72,13 +72,14 @@ assert.equal(bot_data.get('bot0@zulip.com').full_name, 'Bot 0'); (function test_remove() { var bot; - bot_data.add(test_bot); + bot_data.add(_.extend({}, test_bot, {is_active: true})); bot = bot_data.get('bot1@zulip.com'); assert.equal('Bot 1', bot.full_name); - bot_data.remove('bot1@zulip.com'); + assert(bot.is_active); + bot_data.deactivate('bot1@zulip.com'); bot = bot_data.get('bot1@zulip.com'); - assert.equal(undefined, bot); + assert.equal(bot.is_active, false); }()); (function test_owner_can_admin() { @@ -110,9 +111,9 @@ assert.equal(bot_data.get('bot0@zulip.com').full_name, 'Bot 0'); (function test_get_editable() { var can_admin; - bot_data.add(_.extend({}, test_bot, {owner: 'owner@zulip.com'})); - bot_data.add(_.extend({}, test_bot, {email: 'bot2@zulip.com', owner: 'owner@zulip.com'})); - bot_data.add(_.extend({}, test_bot, {email: 'bot3@zulip.com', owner: 'not_owner@zulip.com'})); + bot_data.add(_.extend({}, test_bot, {owner: 'owner@zulip.com', is_active: true})); + bot_data.add(_.extend({}, test_bot, {email: 'bot2@zulip.com', owner: 'owner@zulip.com', is_active: true})); + bot_data.add(_.extend({}, test_bot, {email: 'bot3@zulip.com', owner: 'not_owner@zulip.com', is_active: true})); can_admin = _.pluck(bot_data.get_editable(), 'email'); assert.deepEqual(['bot1@zulip.com', 'bot2@zulip.com'], can_admin); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 26e12f9d0a..a3adad4d6a 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -541,7 +541,7 @@ run(function (override, capture, args) { assert_same(args.bot, event.bot); event = event_fixtures.realm_bot__remove; - override('bot_data', 'remove', capture(['email'])); + override('bot_data', 'deactivate', capture(['email'])); dispatch(event); assert_same(args.email, event.bot.email); diff --git a/static/js/bot_data.js b/static/js/bot_data.js index 7ff32917ac..8940bb35aa 100644 --- a/static/js/bot_data.js +++ b/static/js/bot_data.js @@ -27,8 +27,8 @@ var bot_data = (function () { send_change_event(); }; - exports.remove = function bot_data__remove(email) { - delete bots[email]; + exports.deactivate = function bot_data__deactivate(email) { + bots[email].is_active = false; send_change_event(); }; @@ -41,7 +41,7 @@ var bot_data = (function () { exports.get_editable = function bots_data__get_editable() { return _.filter(bots, function (bot) { - return people.is_current_user(bot.owner); + return bot.is_active && people.is_current_user(bot.owner); }); }; diff --git a/static/js/server_events.js b/static/js/server_events.js index 048d5186bb..e08fbe0996 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -94,7 +94,7 @@ function dispatch_normal_event(event) { if (event.op === 'add') { bot_data.add(event.bot); } else if (event.op === 'remove') { - bot_data.remove(event.bot.email); + bot_data.deactivate(event.bot.email); } else if (event.op === 'update') { if (_.has(event.bot, 'owner_id')) { event.bot.owner = people.get_person_from_user_id(event.bot.owner_id).email;