Skip to content

Commit 8e78a7b

Browse files
committed
fix(search): include Gmail in live connection inventory
1 parent 8714297 commit 8e78a7b

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎apps/sim/lib/knowledge/application/personal-search-integrations.test.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ vi.mock('@/lib/credential-groups/scoped-availability', () => ({
2424
vi.mock('@/lib/credential-groups/search-connection-completion', () => ({
2525
readSearchConnectionCompletion: m.completion,
2626
}))
27-
vi.mock('@/lib/oauth/utils', () => ({ providerIdsForService: (id: string) => [id] }))
28-
2927
vi.mock('@/lib/core/application/organization-authorization', () => ({
3028
authorizeOrganizationOperation: m.authorize,
3129
}))
@@ -54,7 +52,7 @@ vi.mock('@/lib/integrations/availability.server', () => ({
5452
vi.mock('@/lib/sim-search/connectors', () => ({
5553
SEARCH_CONNECTORS: ['gmail', 'slack', 'notion'].map((type) => ({
5654
type,
57-
providerId: type,
55+
providerId: type === 'gmail' ? 'google-email' : type,
5856
meta: { name: type },
5957
setupFields: [],
6058
})),
@@ -71,7 +69,7 @@ const principal = { kind: 'session', userId: 'person', sessionId: 'session' } as
7169
const input = { organizationId: 'org' }
7270
const target = {
7371
type: 'link',
74-
provider: 'gmail',
72+
provider: 'google-email',
7573
connectorType: 'gmail',
7674
connectorId: 'source',
7775
} as const
@@ -238,6 +236,42 @@ describe('live Search connection controls', () => {
238236
)
239237
})
240238

239+
it('offers Gmail when its Credential Group provider differs from its OAuth provider ID', async () => {
240+
m.group.mockResolvedValue({
241+
id: 'group',
242+
status: 'active',
243+
options: [
244+
{ id: 'gmail-option', provider: 'gmail', status: 'active', configurationStatus: 'ready' },
245+
],
246+
})
247+
m.accounts.mockResolvedValue([
248+
{
249+
optionId: 'gmail-option',
250+
credentialId: 'my-gmail',
251+
displayName: 'me@example.com',
252+
status: 'active',
253+
},
254+
])
255+
256+
const result = await listPersonalSearchIntegrations.execute({ principal, input })
257+
const addTarget = {
258+
type: 'link',
259+
provider: 'gmail',
260+
connectorType: 'gmail',
261+
connectionMode: 'live',
262+
optionId: 'gmail-option',
263+
}
264+
expect(result.available).toEqual([{ name: 'gmail', description: '', target: addTarget }])
265+
expect(result.connections[0].accounts).toEqual([
266+
{
267+
credentialId: 'my-gmail',
268+
displayName: 'me@example.com',
269+
status: 'connected',
270+
action: { ...addTarget, credentialId: 'my-gmail' },
271+
},
272+
])
273+
})
274+
241275
it('keeps adding an account distinct from reconnecting an owned account', async () => {
242276
m.accounts.mockResolvedValue([
243277
{ optionId: 'slack-option', credentialId: 'mine', displayName: 'My Slack', status: 'active' },

‎apps/sim/lib/knowledge/application/personal-search-integrations.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { credentialGroup, user } from '@sim/db/schema'
44
import { eq } from 'drizzle-orm'
55
import { isLiveEnterpriseSearchEnabled } from '@/lib/core/config/env-flags'
66
import { OrchestrationError } from '@/lib/core/orchestration/types'
7+
import { findCredentialGroupProviderFromProviderId } from '@/lib/credential-groups/providers'
78
import { isScopedCredentialGroupsAvailable } from '@/lib/credential-groups/scoped-availability'
89
import { readSearchConnectionCompletion } from '@/lib/credential-groups/search-connection-completion'
910
import { getOrganizationAccountsGroup } from '@/lib/credential-groups/service'
@@ -20,7 +21,6 @@ import { listConfiguredSearchProviderTypes } from '@/lib/knowledge/application/s
2021
import { listSearchSources } from '@/lib/knowledge/application/search-sources'
2122
import type { SearchConnectionTarget } from '@/lib/knowledge/search/connection-target'
2223
import { listOrganizationSearchApprovals } from '@/lib/knowledge/search/integration-policy'
23-
import { providerIdsForService } from '@/lib/oauth/utils'
2424
import { getConnectorAccessAvailability, SEARCH_CONNECTORS } from '@/lib/sim-search/connectors'
2525
import { LIVE_SEARCH_SCOPE_FIELDS } from '@/lib/sim-search/live/policy-schema'
2626
import { findSharedSlackSearchInstallation } from '@/lib/slack-search/shared-app'
@@ -64,8 +64,8 @@ export const listPersonalSearchIntegrations = defineAuthorizedKnowledgeUseCase({
6464
})
6565
: []
6666
const connections = (group?.options ?? []).flatMap((option) => {
67-
const connector = SEARCH_CONNECTORS.find((entry) =>
68-
providerIdsForService(entry.providerId).includes(option.provider)
67+
const connector = SEARCH_CONNECTORS.find(
68+
(entry) => findCredentialGroupProviderFromProviderId(entry.providerId) === option.provider
6969
)
7070
if (
7171
!connector ||

‎apps/sim/lib/mothership/tools/handlers/oauth.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('executeOAuthGetAuthLink', () => {
5959
async (mode) => {
6060
const target = {
6161
type: 'link',
62-
provider: 'google-email',
62+
provider: mode === 'live' ? 'gmail' : 'google-email',
6363
connectorType: 'gmail',
6464
...(mode === 'live'
6565
? { connectionMode: 'live', optionId: 'option' }

0 commit comments

Comments
 (0)