Plugin helper function EnsureBot
doesn't compare bot details and only checks if a bot already exists for the plugin. This causes EnsureBot
to return invalid bot data when, for example, changing a bot username or trying to create multiple bots.
EnsureBot
to create a bot with username foo
.foo
.foo
with bar
in EnsureBot
. Re-run the updated plugin.On running EnsureBot
with an updated username, a new bot must be created with updated details and the corresponding ID be returned.
The existing bot foo
's ID is returned and no new bot user is created.
The problem is at this line - https://github.com/mattermost/mattermost-server/blob/0e1a9f7e530061cdd2c7c17899e458afe2c83a9b/plugin/helpers_bots.go#L234
Instead of merely checking the presence of some bot, it should verify the username or other items of the bot and ensure the requested bot is created.
Looks like this is indeed a bug in helpers_bots.go
. And your suggestion should fix the underlying issue. Turning this into a help-wanted issue.
On a second thought, i think this requires a bit more discussion as EnsureBot
semantics only expects to create a bot not update it. So it is working as expected. Started a discussion here for further clarification.
Confirmed that the semantics for EnsureBot
should be of CreateOrUpdate
. Turning this into a help-wanted.
@harshilsharma63 did you want to work on this before i make it available to public?
@ali-farooq0 I can pick this up over the weekend. Thanks!
@ali-farooq0 I've implemented the changes. Now I need to test this with an actual plugin. Should be done this week.
Great, thanks @harshilsharma!
@ali-farooq0 PR is ready and approved by @hanzei . I've tested this from an actual plugin as well and it works perfectly.