server_events_dispatch: Update bots list only if needed.

After b21f533af, we now update the organization bots
list on receiving realm_user events since non-admins
can also see bots not owned by them in the list.

But the functions to update bot list should be called
only for bot users and not for others, otherwise it
results in an error.

This can be reproduced by first opening the organization
bots list and then just updating the name of the user.
Calling `redraw_bots_list` on receiving "realm_user/add"
event for non bot users will not raise any error but
still we avoid redrawing the whole list when not required.

This commit fixes the code to call functions to update
bot list only when the event is received for a bot.
This commit is contained in:
Sahil Batra
2023-03-02 16:51:13 +05:30
committed by Tim Abbott
parent 6eeeb70570
commit 734d1848c0
5 changed files with 57 additions and 13 deletions

View File

@@ -435,7 +435,9 @@ export function dispatch_normal_event(event) {
case "add":
people.add_active_user(event.person);
settings_account.maybe_update_deactivate_account_button();
settings_users.redraw_bots_list();
if (event.person.is_bot) {
settings_users.redraw_bots_list();
}
break;
case "remove":
people.deactivate(event.person);
@@ -443,12 +445,16 @@ export function dispatch_normal_event(event) {
settings_users.update_view_on_deactivate(event.person.user_id);
buddy_list.maybe_remove_key({key: event.person.user_id});
settings_account.maybe_update_deactivate_account_button();
settings_users.update_bot_data(event.person.user_id);
if (people.user_is_bot(event.person.user_id)) {
settings_users.update_bot_data(event.person.user_id);
}
break;
case "update":
user_events.update_person(event.person);
settings_account.maybe_update_deactivate_account_button();
settings_users.update_bot_data(event.person.user_id);
if (people.user_is_bot(event.person.user_id)) {
settings_users.update_bot_data(event.person.user_id);
}
break;
default:
blueslip.error("Unexpected event type realm_user/" + event.op);