Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bots: Sync data on bot ownership change. #8606

Closed
wants to merge 2 commits into from

Conversation

shubham-padia
Copy link
Member

Fixes #8577.

The issue mentioned above occurs in case of non-admin users as the bot hasn't been added to their bot_data. Also the bots for which ownership was changed were not being updated in real time for the non-admin users. For admin users, they already have the bot added, so everything works fine there.

Approach taken:

  • Add event is sent to the new bot owner in order to add the bot. Delete event is sent to the previous bot owner to remove the bot.
  • New event delete is added to remove the bot from data instead of deactivating it.
  • The existing remove sets the bot status to inactive if the bot is deleted. A non-admin user's bot_data contains only those bots that the user owns. Using the existing remove would have just set the bot to inactive, which is not the case and the bot should be removed from bot data.
  • In case of admins however, the bot data contains all the bots. Sending an add/delete event to admins would cause the same error being reported, but this time in case of admins.

@zulipbot
Copy link
Member

zulipbot commented Mar 6, 2018

Hello @zulip/ members, this pull request was labeled with the **** labels, so you may want to check it out!

update_users = update_users - {bot_owner.id, }

# Delete the bot from previous owner's bot data.
if not acting_user.is_realm_admin:
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acting_user may not be the previous owner -- e.g. an admin can re-assign the owner.

I think you want to save previous_owner variable above (before we overwrite it) and use that here.

@timabbott
Copy link
Sponsor Member

Posted one comment; othewise looks great!

Do we already correctly have the frontend remove a user from bot_data when that user is deactivated? That code path come to mind when reading your implementation.

@shubham-padia shubham-padia force-pushed the bot_sync3 branch 3 times, most recently from a07e5c8 to 3c5700a Compare March 8, 2018 14:43
Adds realm_bot delete event. On bot ownership change, add event is
sent to the bot_owner(if not admin) and delete event to the
previous bot owner(if not admin). For admin, update event is sent.
@shubham-padia
Copy link
Member Author

shubham-padia commented Mar 8, 2018

Do we already correctly have the frontend remove a user from bot_data when that user is deactivated?

@timabbott Yes, the remove event takes care of that.

I've made the requested changes. Also added a check if the previous owner and new owner are same.

@timabbott
Copy link
Sponsor Member

Nice, merged, thanks @shubham-padia!

@timabbott timabbott closed this Mar 8, 2018
@shubham-padia shubham-padia deleted the bot_sync3 branch September 8, 2018 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants