Fixing issue found by test case.
This commit is contained in:
parent
ba9d6cf8f7
commit
75375be9f7
|
@ -5,7 +5,7 @@ import rowEndpoints from "./rows"
|
||||||
import userEndpoints from "./users"
|
import userEndpoints from "./users"
|
||||||
import usage from "../../../middleware/usageQuota"
|
import usage from "../../../middleware/usageQuota"
|
||||||
import authorized from "../../../middleware/authorized"
|
import authorized from "../../../middleware/authorized"
|
||||||
import publicApiMiddleware from "../../../middleware/publicApi"
|
import publicApi from "../../../middleware/publicApi"
|
||||||
import { paramResource, paramSubResource } from "../../../middleware/resourceId"
|
import { paramResource, paramSubResource } from "../../../middleware/resourceId"
|
||||||
import { CtxFn } from "./utils/Endpoint"
|
import { CtxFn } from "./utils/Endpoint"
|
||||||
import mapperMiddleware from "./middleware/mapper"
|
import mapperMiddleware from "./middleware/mapper"
|
||||||
|
@ -102,26 +102,23 @@ function applyRoutes(
|
||||||
const paramMiddleware = subResource
|
const paramMiddleware = subResource
|
||||||
? paramSubResource(resource, subResource)
|
? paramSubResource(resource, subResource)
|
||||||
: paramResource(resource)
|
: paramResource(resource)
|
||||||
function both(middleware: any, opts?: any) {
|
const publicApiMiddleware = publicApi({
|
||||||
addMiddleware(endpoints.read, middleware, opts)
|
requiresAppId:
|
||||||
addMiddleware(endpoints.write, paramMiddleware, opts)
|
permType !== PermissionTypes.APP && permType !== PermissionTypes.USER,
|
||||||
}
|
})
|
||||||
// add the public API headers check
|
addMiddleware(endpoints.read, publicApiMiddleware)
|
||||||
both(
|
addMiddleware(endpoints.write, publicApiMiddleware)
|
||||||
publicApiMiddleware({
|
|
||||||
requiresAppId:
|
|
||||||
permType !== PermissionTypes.APP && permType !== PermissionTypes.USER,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
// add the output mapper middleware
|
|
||||||
both(mapperMiddleware, { output: true })
|
|
||||||
// add the parameter capture middleware
|
// add the parameter capture middleware
|
||||||
both(paramMiddleware)
|
addMiddleware(endpoints.read, paramMiddleware)
|
||||||
|
addMiddleware(endpoints.write, paramMiddleware)
|
||||||
// add the authorization middleware, using the correct perm type
|
// add the authorization middleware, using the correct perm type
|
||||||
addMiddleware(endpoints.read, authorized(permType, PermissionLevels.READ))
|
addMiddleware(endpoints.read, authorized(permType, PermissionLevels.READ))
|
||||||
addMiddleware(endpoints.write, authorized(permType, PermissionLevels.WRITE))
|
addMiddleware(endpoints.write, authorized(permType, PermissionLevels.WRITE))
|
||||||
// add the usage quota middleware
|
// add the usage quota middleware
|
||||||
addMiddleware(endpoints.write, usage)
|
addMiddleware(endpoints.write, usage)
|
||||||
|
// add the output mapper middleware
|
||||||
|
addMiddleware(endpoints.read, mapperMiddleware, { output: true })
|
||||||
|
addMiddleware(endpoints.write, mapperMiddleware, { output: true })
|
||||||
addToRouter(endpoints.read)
|
addToRouter(endpoints.read)
|
||||||
addToRouter(endpoints.write)
|
addToRouter(endpoints.write)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue