mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
bot_data.js: Replace remove() with deactivate().
On receiving a `remove` event of type `realm_bot`, instead of deleting the bot from `bots` dict, set it's `is_active` flag to false.
This commit is contained in:
committed by
Tim Abbott
parent
a900a2076a
commit
bbcd927375
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user