mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-13 12:55:19 +00:00
clear search contexts on init
This commit is contained in:
parent
fbe1073d0e
commit
969305fe89
2 changed files with 27 additions and 0 deletions
|
|
@ -1669,6 +1669,22 @@ export const getSearchContexts = async (domain: string) => sew(() =>
|
|||
}, /* minRequiredRole = */ OrgRole.GUEST), /* allowAnonymousAccess = */ true
|
||||
));
|
||||
|
||||
export const clearSearchContexts = async (domain: string) => sew(() =>
|
||||
withAuth((userId) =>
|
||||
withOrgMembership(userId, domain, async ({ org }) => {
|
||||
await prisma.searchContext.deleteMany({
|
||||
where: {
|
||||
orgId: org.id,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}, /* minRequiredRole = */ OrgRole.OWNER)
|
||||
)
|
||||
)
|
||||
|
||||
export const getRepoImage = async (repoId: number): Promise<ArrayBuffer | ServiceError> => sew(async () => {
|
||||
return await withOptionalAuthV2(async ({ org, prisma }) => {
|
||||
const repo = await prisma.repo.findUnique({
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { getOrgFromDomain } from './data/org';
|
|||
import { SINGLE_TENANT_ORG_DOMAIN, SINGLE_TENANT_ORG_ID, SOURCEBOT_GUEST_USER_ID } from './lib/constants';
|
||||
import { ServiceErrorException } from './lib/serviceError';
|
||||
import { getOrgMetadata, isServiceError } from './lib/utils';
|
||||
import { clearSearchContexts, getSearchContexts } from './actions';
|
||||
|
||||
const logger = createLogger('web-initialize');
|
||||
|
||||
|
|
@ -62,6 +63,16 @@ const initSingleTenancy = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
// If we don't have the search context entitlement then wipe any existing
|
||||
// search contexts that may be present in the DB
|
||||
const hasSearchContextEntitlement = hasEntitlement("search-contexts")
|
||||
if(!hasSearchContextEntitlement) {
|
||||
const searchContexts = await getSearchContexts(SINGLE_TENANT_ORG_DOMAIN);
|
||||
if (!isServiceError(searchContexts) && searchContexts.length > 0) {
|
||||
clearSearchContexts(SINGLE_TENANT_ORG_DOMAIN)
|
||||
}
|
||||
}
|
||||
|
||||
// Sync anonymous access config from the config file
|
||||
const config = await loadConfig(env.CONFIG_PATH);
|
||||
const forceEnableAnonymousAccess = config.settings?.enablePublicAccess ?? env.FORCE_ENABLE_ANONYMOUS_ACCESS === 'true';
|
||||
|
|
|
|||
Loading…
Reference in a new issue