Skip to content

Commit b30cf47

Browse files
committed
fix(slack): snapshot installations before choosing the member setup app
1 parent df1c8f4 commit b30cf47

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎apps/sim/lib/credential-groups/slack-managed-users.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('Slack managed-user authorization', () => {
9494
it('stores exact organization ownership in the encrypted setup attempt and rejects ambiguous ownership', async () => {
9595
dbChainMockFns.limit
9696
.mockResolvedValueOnce([{ id: 'group-1', updatedAt: new Date(1), options: [] }])
97+
.mockResolvedValueOnce([])
9798
.mockResolvedValueOnce([
9899
{
99100
app: {
@@ -148,6 +149,7 @@ describe('Slack managed-user authorization', () => {
148149
shared.flag.mockImplementation(async (_flag, context) => context?.orgId === 'org-1')
149150
dbChainMockFns.limit
150151
.mockResolvedValueOnce([{ id: 'group-1', updatedAt: new Date(1), options: [] }])
152+
.mockResolvedValueOnce([])
151153
.mockResolvedValueOnce([
152154
{
153155
app: {
@@ -272,6 +274,7 @@ describe('Slack managed-user authorization', () => {
272274
}
273275
dbChainMockFns.limit
274276
.mockResolvedValueOnce([group])
277+
.mockResolvedValueOnce([])
275278
.mockResolvedValueOnce([{ app, teamId: 'T123' }])
276279

277280
const created = await createSlackManagedUsersAttempt({

‎apps/sim/lib/credential-groups/slack-managed-users.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ export async function createSlackManagedUsersAttempt(params: {
633633
'Select the organization’s Slack app. Configure its credentials in Slack app setup.',
634634
'invalid_response'
635635
)
636+
/**
637+
* Read before choosing the app: an install committed earlier is visible to that choice, and
638+
* one committed later changes this snapshot, which completion re-checks under the lock.
639+
*/
640+
installationsRevision = await organizationInstallationsRevision(db, scope.organizationId)
636641
const app = params.appId
637642
? await resolveInstalledOrganizationSlackApp(
638643
scope.organizationId,
@@ -683,7 +688,6 @@ export async function createSlackManagedUsersAttempt(params: {
683688
}
684689
if (searchApproval.approved)
685690
requiredScopes = [...new Set([...requiredScopes, ...SLACK_SEARCH_USER_SCOPES])]
686-
installationsRevision = await organizationInstallationsRevision(db, scope.organizationId)
687691
} else {
688692
if (!params.slackBotCredentialId)
689693
throw new SlackManagedUsersError('Select a custom Slack bot.', 'invalid_response')

0 commit comments

Comments
 (0)