Skip to content

Commit 969305f

Browse files
committed
clear search contexts on init
1 parent fbe1073 commit 969305f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/web/src/actions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,22 @@ export const getSearchContexts = async (domain: string) => sew(() =>
16691669
}, /* minRequiredRole = */ OrgRole.GUEST), /* allowAnonymousAccess = */ true
16701670
));
16711671

1672+
export const clearSearchContexts = async (domain: string) => sew(() =>
1673+
withAuth((userId) =>
1674+
withOrgMembership(userId, domain, async ({ org }) => {
1675+
await prisma.searchContext.deleteMany({
1676+
where: {
1677+
orgId: org.id,
1678+
},
1679+
});
1680+
1681+
return {
1682+
success: true,
1683+
};
1684+
}, /* minRequiredRole = */ OrgRole.OWNER)
1685+
)
1686+
)
1687+
16721688
export const getRepoImage = async (repoId: number): Promise<ArrayBuffer | ServiceError> => sew(async () => {
16731689
return await withOptionalAuthV2(async ({ org, prisma }) => {
16741690
const repo = await prisma.repo.findUnique({

packages/web/src/initialize.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getOrgFromDomain } from './data/org';
77
import { SINGLE_TENANT_ORG_DOMAIN, SINGLE_TENANT_ORG_ID, SOURCEBOT_GUEST_USER_ID } from './lib/constants';
88
import { ServiceErrorException } from './lib/serviceError';
99
import { getOrgMetadata, isServiceError } from './lib/utils';
10+
import { clearSearchContexts, getSearchContexts } from './actions';
1011

1112
const logger = createLogger('web-initialize');
1213

@@ -62,6 +63,16 @@ const initSingleTenancy = async () => {
6263
}
6364
}
6465

66+
// If we don't have the search context entitlement then wipe any existing
67+
// search contexts that may be present in the DB
68+
const hasSearchContextEntitlement = hasEntitlement("search-contexts")
69+
if(!hasSearchContextEntitlement) {
70+
const searchContexts = await getSearchContexts(SINGLE_TENANT_ORG_DOMAIN);
71+
if (!isServiceError(searchContexts) && searchContexts.length > 0) {
72+
clearSearchContexts(SINGLE_TENANT_ORG_DOMAIN)
73+
}
74+
}
75+
6576
// Sync anonymous access config from the config file
6677
const config = await loadConfig(env.CONFIG_PATH);
6778
const forceEnableAnonymousAccess = config.settings?.enablePublicAccess ?? env.FORCE_ENABLE_ANONYMOUS_ACCESS === 'true';

0 commit comments

Comments
 (0)