Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/sim/hooks/queries/oauth-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react'
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { requestJson } from '@/lib/api/client/request'
import {
Expand All @@ -7,7 +6,6 @@ import {
revokeAuthorizedAppContract,
} from '@/lib/api/contracts/user'
import { client } from '@/lib/auth/client'
import { OAUTH_SEARCH_READ_SCOPE, oauthScopeSatisfies } from '@/lib/auth/oauth-provider'

export const oauthProviderKeys = {
all: ['oauth-provider'] as const,
Expand Down
2 changes: 0 additions & 2 deletions apps/sim/hooks/queries/search-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
listSearchHistoryContract,
type RecordSearchHistoryBody,
recordSearchHistoryContract,
removeSearchHistorySourceContract,
type SearchHistoryResponse,
} from '@/lib/api/contracts/knowledge/search-history'
import {
SEARCH_HISTORY_STALE_TIME,
Expand Down
8 changes: 0 additions & 8 deletions apps/sim/lib/api/contracts/knowledge/search-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const searchHistoryResponseSchema = z.object({
.array(z.object({ query: z.string().min(1).max(4000), searchedAt: z.iso.datetime() }))
.max(SEARCH_HISTORY_LIMIT),
})
export type SearchHistoryResponse = z.output<typeof searchHistoryResponseSchema>

export const listSearchHistoryContract = defineRouteContract({
method: 'GET',
Expand All @@ -54,10 +53,3 @@ export const clearSearchHistoryContract = defineRouteContract({
params: searchHistoryParamsSchema,
response: { mode: 'json', schema: z.object({ success: z.literal(true) }) },
})
export const removeSearchHistorySourceContract = defineRouteContract({
method: 'DELETE',
path: '/api/organizations/[id]/search/history/sources',
params: searchHistoryParamsSchema,
body: z.object({ url: z.string().min(1).max(4096) }),
response: { mode: 'json', schema: z.object({ success: z.literal(true) }) },
})
20 changes: 1 addition & 19 deletions apps/sim/lib/knowledge/application/search-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,13 @@ export const searchHistoryOperations = {
principalKinds: ['session'],
capability: 'knowledge.use',
}),
removeSource: defineOrganizationOperation({
id: 'knowledge.search.history.remove_source',
minimumRole: 'member',
principalKinds: ['session'],
capability: 'knowledge.use',
}),
} as const

interface SearchHistoryInput {
organizationId: string
}
interface RecordSearchHistoryInput extends SearchHistoryInput {
event: Exclude<SearchHistoryEvent, { kind: 'remove-source' }>
}
interface RemoveSearchHistorySourceInput extends SearchHistoryInput {
url: string
event: SearchHistoryEvent
}

/**
Expand Down Expand Up @@ -78,12 +69,3 @@ export const clearSearchHistory = defineAuthorizedOrganizationUseCase({
return { success: true as const }
},
})
/** A removal only ever touches the viewer's own row; an absent URL leaves it as it was. */
export const removeSearchHistorySource = defineAuthorizedOrganizationUseCase({
operation: searchHistoryOperations.removeSource,
authorizeResource: ({ context }) => requireOrganizationSearchAvailable(context.organizationId),
async execute({ input, context }: OrganizationUseCaseContext<RemoveSearchHistorySourceInput>) {
await updateSearchHistory(context, { kind: 'remove-source', url: input.url })
return { success: true as const }
},
})
27 changes: 0 additions & 27 deletions apps/sim/lib/knowledge/search/history/history.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
clearSearchHistory,
listSearchHistory,
recordSearchHistory,
removeSearchHistorySource,
} from '@/lib/knowledge/application/search-history'
import { SEARCH_HISTORY_LIMIT } from '@/lib/knowledge/search/history/limits'

Expand Down Expand Up @@ -62,32 +61,6 @@ afterAll(async () => {
})

describe('private search navigation history', () => {
it('removes one source for the person who asked and no one else', async () => {
const colleague = { kind: 'session', userId: userIds[1], sessionId: 'history-test' } as const
const other = { ...source, url: 'https://docs.google.com/document/d/other-fixture' }
for (const viewed of [source, other]) {
await recordSearchHistory.execute({
principal,
input: { ...input, event: { kind: 'source', source: viewed } },
})
}
await recordSearchHistory.execute({
principal: colleague,
input: { ...input, event: { kind: 'source', source } },
})

await removeSearchHistorySource.execute({ principal, input: { ...input, url: source.url } })

expect(
(await listSearchHistory.execute({ principal, input })).sources.map((item) => item.url)
).toEqual([other.url])
expect(
(await listSearchHistory.execute({ principal: colleague, input })).sources.map(
(item) => item.url
)
).toEqual([source.url])
})

it('isolates users and organizations and revokes access with membership', async () => {
await recordSearchHistory.execute({
principal,
Expand Down
3 changes: 0 additions & 3 deletions apps/sim/lib/knowledge/search/history/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type SearchHistory = Pick<HistoryRow, 'sources' | 'queries'>
export type SearchHistoryEvent =
| { kind: 'source'; source: Omit<HistoryRow['sources'][number], 'viewedAt'> }
| { kind: 'query'; query: string }
| { kind: 'remove-source'; url: string }

interface HistoryOwner {
organizationId: string
Expand Down Expand Up @@ -73,8 +72,6 @@ export async function updateSearchHistory(
{ query: event.query, searchedAt: now },
...history.queries.filter((entry) => entry.query !== event.query),
].slice(0, SEARCH_HISTORY_LIMIT)
} else if (event?.kind === 'remove-source') {
history.sources = history.sources.filter((source) => source.url !== event.url)
}
await tx.update(organizationSearchHistory).set(history).where(ownerCondition(owner))
})
Expand Down
Loading