Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 1x 1x 1x 1x 1x 1x 1x |
import { appliableHooksForUser } from './appliableHookForUser'
import { DaoGenericMethods } from '../../types/core.types'
import { getProjectDatabaseDaosForModel } from '../../helpers/getProjectModelsAndDaos'
/** May throw a 403 unauthorized if user doesn't have access */
export async function hookInterpreterExpose(
ctx: Ctx,
dbId: string,
dbName: string,
method: DaoGenericMethods,
modelName
) {
if (ctx?.isSystem) return true
const dao = await getProjectDatabaseDaosForModel(dbName, modelName)
const hooks = dao.expose || []
const exposeHooks = await appliableHooksForUser(ctx, hooks, method, 'alwaysReturnTrue', 'matchStrict', 'alwaysReturnTrue')
const authorizedMethods = []
for (const { expose: exposedMethods } of exposeHooks) authorizedMethods.push(...exposedMethods)
if (!authorizedMethods.includes(method)) throw ctx.error.userDoNotHaveThePermission({
addintionalInfos: 'Wrong Method',
modelName,
userRole: ctx.role,
userId: ctx._id,
userPermissions: ctx.permissions,
method,
dbName,
dbId,
authorizedMethods,
fn: 'hookInterpreterExpose.checkMethod',
})
} |