mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	bot_data: Remove set_can_admin.
We stopped needing this with
0329b67048
(Dec 2016).
The function sets `bot.can_admin`,
which was only used in `bot_data.get_editable`.
We removed two tests (and then put back
some test setup that needed to leak down
to the last test).
			
			
This commit is contained in:
		@@ -109,45 +109,20 @@ run_test('test_basics', () => {
 | 
			
		||||
        assert.equal(bot, undefined);
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_owner_can_admin() {
 | 
			
		||||
        let bot;
 | 
			
		||||
 | 
			
		||||
        bot_data.add({owner: 'owner@zulip.com', ...test_bot});
 | 
			
		||||
 | 
			
		||||
        bot = bot_data.get(43);
 | 
			
		||||
        assert(bot.can_admin);
 | 
			
		||||
 | 
			
		||||
        bot_data.add({owner: 'notowner@zulip.com', ...test_bot});
 | 
			
		||||
 | 
			
		||||
        bot = bot_data.get(43);
 | 
			
		||||
        assert.equal(false, bot.can_admin);
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_admin_can_admin() {
 | 
			
		||||
        page_params.is_admin = true;
 | 
			
		||||
 | 
			
		||||
        bot_data.add(test_bot);
 | 
			
		||||
 | 
			
		||||
        const bot = bot_data.get(43);
 | 
			
		||||
        assert(bot.can_admin);
 | 
			
		||||
 | 
			
		||||
        page_params.is_admin = false;
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_get_editable() {
 | 
			
		||||
        let can_admin;
 | 
			
		||||
        let editable_bots;
 | 
			
		||||
 | 
			
		||||
        bot_data.add({...test_bot, user_id: 44, owner: 'owner@zulip.com', is_active: true});
 | 
			
		||||
        bot_data.add({...test_bot, user_id: 45, email: 'bot2@zulip.com', owner: 'owner@zulip.com', is_active: true});
 | 
			
		||||
        bot_data.add({...test_bot, user_id: 46, email: 'bot3@zulip.com', owner: 'not_owner@zulip.com', is_active: true});
 | 
			
		||||
 | 
			
		||||
        can_admin = bot_data.get_editable().map(bot => bot.email);
 | 
			
		||||
        assert.deepEqual(['bot1@zulip.com', 'bot2@zulip.com'], can_admin);
 | 
			
		||||
        editable_bots = bot_data.get_editable().map(bot => bot.email);
 | 
			
		||||
        assert.deepEqual(['bot1@zulip.com', 'bot2@zulip.com'], editable_bots);
 | 
			
		||||
 | 
			
		||||
        page_params.is_admin = true;
 | 
			
		||||
 | 
			
		||||
        can_admin = bot_data.get_editable().map(bot => bot.email);
 | 
			
		||||
        assert.deepEqual(['bot1@zulip.com', 'bot2@zulip.com'], can_admin);
 | 
			
		||||
        editable_bots = bot_data.get_editable().map(bot => bot.email);
 | 
			
		||||
        assert.deepEqual(['bot1@zulip.com', 'bot2@zulip.com'], editable_bots);
 | 
			
		||||
    }());
 | 
			
		||||
 | 
			
		||||
    (function test_get_all_bots_for_current_user() {
 | 
			
		||||
@@ -161,6 +136,7 @@ run_test('test_basics', () => {
 | 
			
		||||
    (function test_get_bot_owner_email() {
 | 
			
		||||
        let bot_owner_email = bot_data.get_bot_owner_email(test_embedded_bot.user_id);
 | 
			
		||||
        assert.equal('cordelia@zulip.com', bot_owner_email);
 | 
			
		||||
        bot_data.add(test_bot);
 | 
			
		||||
        bot_owner_email = bot_data.get_bot_owner_email(test_bot.user_id);
 | 
			
		||||
        assert.equal(undefined, bot_owner_email);
 | 
			
		||||
    }());
 | 
			
		||||
 
 | 
			
		||||
@@ -10,20 +10,9 @@ const send_change_event = _.debounce(function () {
 | 
			
		||||
    settings_bots.render_bots();
 | 
			
		||||
}, 50);
 | 
			
		||||
 | 
			
		||||
const set_can_admin = function (bot) {
 | 
			
		||||
    if (page_params.is_admin) {
 | 
			
		||||
        bot.can_admin = true;
 | 
			
		||||
    } else if (bot.owner !== undefined && people.is_current_user(bot.owner)) {
 | 
			
		||||
        bot.can_admin = true;
 | 
			
		||||
    } else {
 | 
			
		||||
        bot.can_admin = false;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.add = function (bot) {
 | 
			
		||||
    const clean_bot = _.pick(bot, bot_fields);
 | 
			
		||||
    bots.set(bot.user_id, clean_bot);
 | 
			
		||||
    set_can_admin(clean_bot);
 | 
			
		||||
    const clean_services = bot.services.map(service => _.pick(service, services_fields));
 | 
			
		||||
    services.set(bot.user_id, clean_services);
 | 
			
		||||
 | 
			
		||||
@@ -44,7 +33,6 @@ exports.del = function (bot_id) {
 | 
			
		||||
exports.update = function (bot_id, bot_update) {
 | 
			
		||||
    const bot = bots.get(bot_id);
 | 
			
		||||
    Object.assign(bot, _.pick(bot_update, bot_fields));
 | 
			
		||||
    set_can_admin(bot);
 | 
			
		||||
 | 
			
		||||
    // We currently only support one service per bot.
 | 
			
		||||
    const service = services.get(bot_id)[0];
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user