From 5b7be7dab8fb1f5795d51a759e3acf1fdef0459f Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 6 Nov 2026 11:36:29 -0800 Subject: [PATCH] fix(org): drop leftovers of the reverted search history source removal #9740 deleted the search history sources route but kept the code that only it reached: the remove-source use case, operation, repository event and contract, plus unused imports in the oauth-provider and search-history hooks. Restore those files to their main versions. --- apps/sim/hooks/queries/oauth-provider.ts | 2 -- apps/sim/hooks/queries/search-history.ts | 2 -- .../api/contracts/knowledge/search-history.ts | 8 ------ .../knowledge/application/search-history.ts | 20 +------------- .../search/history/history.integration.ts | 27 ------------------- .../knowledge/search/history/repository.ts | 3 --- 6 files changed, 1 insertion(+), 61 deletions(-) diff --git a/apps/sim/hooks/queries/oauth-provider.ts b/apps/sim/hooks/queries/oauth-provider.ts index d5ace0d7638..0e33d5ab94e 100644 --- a/apps/sim/hooks/queries/oauth-provider.ts +++ b/apps/sim/hooks/queries/oauth-provider.ts @@ -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 { @@ -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, diff --git a/apps/sim/hooks/queries/search-history.ts b/apps/sim/hooks/queries/search-history.ts index 919709decfd..a8fabc17494 100644 --- a/apps/sim/hooks/queries/search-history.ts +++ b/apps/sim/hooks/queries/search-history.ts @@ -5,8 +5,6 @@ import { listSearchHistoryContract, type RecordSearchHistoryBody, recordSearchHistoryContract, - removeSearchHistorySourceContract, - type SearchHistoryResponse, } from '@/lib/api/contracts/knowledge/search-history' import { SEARCH_HISTORY_STALE_TIME, diff --git a/apps/sim/lib/api/contracts/knowledge/search-history.ts b/apps/sim/lib/api/contracts/knowledge/search-history.ts index b6c1c00ba19..8c869edfa52 100644 --- a/apps/sim/lib/api/contracts/knowledge/search-history.ts +++ b/apps/sim/lib/api/contracts/knowledge/search-history.ts @@ -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 export const listSearchHistoryContract = defineRouteContract({ method: 'GET', @@ -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) }) }, -}) diff --git a/apps/sim/lib/knowledge/application/search-history.ts b/apps/sim/lib/knowledge/application/search-history.ts index a4227448563..6d700600a70 100644 --- a/apps/sim/lib/knowledge/application/search-history.ts +++ b/apps/sim/lib/knowledge/application/search-history.ts @@ -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 -} -interface RemoveSearchHistorySourceInput extends SearchHistoryInput { - url: string + event: SearchHistoryEvent } /** @@ -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) { - await updateSearchHistory(context, { kind: 'remove-source', url: input.url }) - return { success: true as const } - }, -}) diff --git a/apps/sim/lib/knowledge/search/history/history.integration.ts b/apps/sim/lib/knowledge/search/history/history.integration.ts index 93676197e67..193ad79ea35 100644 --- a/apps/sim/lib/knowledge/search/history/history.integration.ts +++ b/apps/sim/lib/knowledge/search/history/history.integration.ts @@ -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' @@ -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, diff --git a/apps/sim/lib/knowledge/search/history/repository.ts b/apps/sim/lib/knowledge/search/history/repository.ts index 1c28aa135fd..d13f84ab040 100644 --- a/apps/sim/lib/knowledge/search/history/repository.ts +++ b/apps/sim/lib/knowledge/search/history/repository.ts @@ -11,7 +11,6 @@ export type SearchHistory = Pick export type SearchHistoryEvent = | { kind: 'source'; source: Omit } | { kind: 'query'; query: string } - | { kind: 'remove-source'; url: string } interface HistoryOwner { organizationId: string @@ -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)) })