(user?: UserWithAccounts)
| 29 | * a given user should be able to access. |
| 30 | */ |
| 31 | export 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 |
no test coverage detected