slack-bolt-extensions icon indicating copy to clipboard operation
slack-bolt-extensions copied to clipboard

Installation queries use enterpriseId even when not an enterprise install

Open omermizr opened this issue 1 year ago • 1 comments

The problem

Our app stops working for organizations that upgrade to Enterprise Grid.

The cause

This happens when an organization installs an app before they have an enterprise plan (where InstallationQuery.enterprise doesn't exist), and then upgrade to an enterprise plan (where InstallationQuery.enterprise does exist). In that scenario, a previously stored installation wouldn't have the enterpriseId field, but new requests (events, actions etc.) will have the enterprise object on the InstallationQuery, so fetchInstallation won't find it.

The solution(?)

I think it would make sense to only use enterpriseId when isEnterpriseInstall is false, but I don't know all the considerations intimately like @seratch does. For Mongoose, where the queries are made against a single string field (__appOrgWorkspace__, see here: https://github.com/seratch/slack-bolt-extensions/blob/ef15b443dc429204b757c18bb017ea3047e7a183/packages/bolt-mongoose/src/MongooseInstallationStore.ts#L217) this will probably require a DB migration to work properly for existing installations (or more complex code to query by regex and filter in JS or something similar). For us, we have previously ported one of the packages here so we can just make a change in our codebase, but we wanted to be good Samaritans and report this, and also get feedback.

omermizr avatar Sep 01 '24 10:09 omermizr

Thanks for letting me know this, and I am sorry for my delayed response here. Indeed, supporting this use case would be a great plus.

seratch avatar Dec 23 '24 06:12 seratch