MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / userScopedPrismaClientExtension

Function userScopedPrismaClientExtension

packages/web/src/prisma.ts:31–68  ·  view source on GitHub ↗
(user?: UserWithAccounts)

Source from the content-addressed store, hash-verified

29 * a given user should be able to access.
30 */
31export const userScopedPrismaClientExtension = async (user?: UserWithAccounts) => {
32 const hasPermissionSyncing = env.PERMISSION_SYNC_ENABLED === 'true';
33
34 return Prisma.defineExtension(
35 (prisma) => {
36 return prisma.$extends({
37 query: {
38 ...getMcpPrismaQueryExtension(user),
39 ...(hasPermissionSyncing ? {
40 repo: {
41 async $allOperations({ args, query }) {
42 const argsWithWhere = args as Record<string, unknown> & {
43 where?: Prisma.RepoWhereInput;
44 }
45
46 argsWithWhere.where = {
47 ...(argsWithWhere.where || {}),
48 ...getRepoPermissionFilterForUser(user),
49 };
50
51 return query(args);
52 }
53 },
54 searchContext: {
55 async $allOperations({ args, query }) {
56 injectRepoPermissionFilterIntoRelation(
57 args as Record<string, unknown>,
58 getRepoPermissionFilterForUser(user),
59 );
60
61 return query(args);
62 }
63 }
64 } : {})
65 }
66 })
67 })
68}
69
70/**
71 * Injects a `Repo` permission filter into a nested `repos` relation referenced

Callers 1

getAuthContextFunction · 0.90

Calls 1

Tested by

no test coverage detected