few changes from code review
This commit is contained in:
parent
348eaab73c
commit
473468b481
|
@ -41,7 +41,7 @@ exports.createModel = async (request, instanceId, model) => {
|
||||||
return res.body
|
return res.body
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createRecord = async (request, instanceId, modelId, record) => {
|
exports.createRecord = async ({ request, instanceId, modelId, record }) => {
|
||||||
record = record || {
|
record = record || {
|
||||||
modelId,
|
modelId,
|
||||||
name: "test name",
|
name: "test name",
|
||||||
|
@ -108,7 +108,7 @@ exports.createUser = async (
|
||||||
return res.body
|
return res.body
|
||||||
}
|
}
|
||||||
|
|
||||||
const createUser_WithOnePermission = async (
|
const createUserWithOnePermission = async (
|
||||||
request,
|
request,
|
||||||
instanceId,
|
instanceId,
|
||||||
permName,
|
permName,
|
||||||
|
@ -127,7 +127,7 @@ const createUser_WithOnePermission = async (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createUser_WithAdminPermissions = async (request, instanceId) => {
|
const createUserWithAdminPermissions = async (request, instanceId) => {
|
||||||
let permissions = await generateAdminPermissions(instanceId)
|
let permissions = await generateAdminPermissions(instanceId)
|
||||||
|
|
||||||
return await createUserWithPermissions(
|
return await createUserWithPermissions(
|
||||||
|
@ -138,7 +138,7 @@ const createUser_WithAdminPermissions = async (request, instanceId) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createUser_WithAllPermissionExceptOne = async (
|
const createUserWithAllPermissionExceptOne = async (
|
||||||
request,
|
request,
|
||||||
instanceId,
|
instanceId,
|
||||||
permName,
|
permName,
|
||||||
|
@ -203,7 +203,7 @@ exports.testPermissionsForEndpoint = async ({
|
||||||
permissionName,
|
permissionName,
|
||||||
itemId,
|
itemId,
|
||||||
}) => {
|
}) => {
|
||||||
const headers = await createUser_WithOnePermission(
|
const headers = await createUserWithOnePermission(
|
||||||
request,
|
request,
|
||||||
instanceId,
|
instanceId,
|
||||||
permissionName,
|
permissionName,
|
||||||
|
@ -214,7 +214,7 @@ exports.testPermissionsForEndpoint = async ({
|
||||||
.set(headers)
|
.set(headers)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
const noPermsHeaders = await createUser_WithAllPermissionExceptOne(
|
const noPermsHeaders = await createUserWithAllPermissionExceptOne(
|
||||||
request,
|
request,
|
||||||
instanceId,
|
instanceId,
|
||||||
permissionName,
|
permissionName,
|
||||||
|
@ -233,7 +233,7 @@ exports.builderEndpointShouldBlockNormalUsers = async ({
|
||||||
body,
|
body,
|
||||||
instanceId,
|
instanceId,
|
||||||
}) => {
|
}) => {
|
||||||
const headers = await createUser_WithAdminPermissions(request, instanceId)
|
const headers = await createUserWithAdminPermissions(request, instanceId)
|
||||||
|
|
||||||
await createRequest(request, method, url, body)
|
await createRequest(request, method, url, body)
|
||||||
.set(headers)
|
.set(headers)
|
||||||
|
|
|
@ -105,8 +105,8 @@ describe("/views", () => {
|
||||||
|
|
||||||
it("should return records from custom view", async () => {
|
it("should return records from custom view", async () => {
|
||||||
await createView()
|
await createView()
|
||||||
const rec1 = await createRecord(request, instance._id, model._id)
|
const rec1 = await createRecord({ request, instanceId: instance._id, modelId: model._id })
|
||||||
await createRecord(request, instance._id, model._id)
|
await createRecord({ request, instanceId: instance._id, modelId: model._id })
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/${instance._id}/views/TestView`)
|
.get(`/api/${instance._id}/views/TestView`)
|
||||||
.set(defaultHeaders)
|
.set(defaultHeaders)
|
||||||
|
|
|
@ -2,29 +2,29 @@ const viewController = require("../api/controllers/view")
|
||||||
const modelController = require("../api/controllers/model")
|
const modelController = require("../api/controllers/model")
|
||||||
const workflowController = require("../api/controllers/workflow")
|
const workflowController = require("../api/controllers/workflow")
|
||||||
|
|
||||||
exports.ADMIN_LEVEL_ID = "ADMIN"
|
const ADMIN_LEVEL_ID = "ADMIN"
|
||||||
exports.POWERUSER_LEVEL_ID = "POWER_USER"
|
const POWERUSER_LEVEL_ID = "POWER_USER"
|
||||||
|
|
||||||
exports.READ_MODEL = "read-model"
|
const READ_MODEL = "read-model"
|
||||||
exports.WRITE_MODEL = "write-model"
|
const WRITE_MODEL = "write-model"
|
||||||
exports.READ_VIEW = "read-view"
|
const READ_VIEW = "read-view"
|
||||||
exports.EXECUTE_WORKFLOW = "execute-workflow"
|
const EXECUTE_WORKFLOW = "execute-workflow"
|
||||||
exports.USER_MANAGEMENT = "user-management"
|
const USER_MANAGEMENT = "user-management"
|
||||||
exports.BUILDER = "builder"
|
const BUILDER = "builder"
|
||||||
exports.LIST_USERS = "list-users"
|
const LIST_USERS = "list-users"
|
||||||
|
|
||||||
exports.adminPermissions = [
|
const adminPermissions = [
|
||||||
{
|
{
|
||||||
name: exports.USER_MANAGEMENT,
|
name: USER_MANAGEMENT,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
exports.generateAdminPermissions = async instanceId => [
|
const generateAdminPermissions = async instanceId => [
|
||||||
...exports.adminPermissions,
|
...adminPermissions,
|
||||||
...(await exports.generatePowerUserPermissions(instanceId)),
|
...(await generatePowerUserPermissions(instanceId)),
|
||||||
]
|
]
|
||||||
|
|
||||||
exports.generatePowerUserPermissions = async instanceId => {
|
const generatePowerUserPermissions = async instanceId => {
|
||||||
const fetchModelsCtx = {
|
const fetchModelsCtx = {
|
||||||
params: {
|
params: {
|
||||||
instanceId,
|
instanceId,
|
||||||
|
@ -51,22 +51,22 @@ exports.generatePowerUserPermissions = async instanceId => {
|
||||||
|
|
||||||
const readModelPermissions = models.map(m => ({
|
const readModelPermissions = models.map(m => ({
|
||||||
itemId: m._id,
|
itemId: m._id,
|
||||||
name: exports.READ_MODEL,
|
name: READ_MODEL,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const writeModelPermissions = models.map(m => ({
|
const writeModelPermissions = models.map(m => ({
|
||||||
itemId: m._id,
|
itemId: m._id,
|
||||||
name: exports.WRITE_MODEL,
|
name: WRITE_MODEL,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const viewPermissions = views.map(v => ({
|
const viewPermissions = views.map(v => ({
|
||||||
itemId: v.name,
|
itemId: v.name,
|
||||||
name: exports.READ_VIEW,
|
name: READ_VIEW,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const executeWorkflowPermissions = workflows.map(w => ({
|
const executeWorkflowPermissions = workflows.map(w => ({
|
||||||
itemId: w._id,
|
itemId: w._id,
|
||||||
name: exports.EXECUTE_WORKFLOW,
|
name: EXECUTE_WORKFLOW,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -74,6 +74,20 @@ exports.generatePowerUserPermissions = async instanceId => {
|
||||||
...writeModelPermissions,
|
...writeModelPermissions,
|
||||||
...viewPermissions,
|
...viewPermissions,
|
||||||
...executeWorkflowPermissions,
|
...executeWorkflowPermissions,
|
||||||
{ name: exports.LIST_USERS },
|
{ name: LIST_USERS },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ADMIN_LEVEL_ID,
|
||||||
|
POWERUSER_LEVEL_ID,
|
||||||
|
READ_MODEL,
|
||||||
|
WRITE_MODEL,
|
||||||
|
READ_VIEW,
|
||||||
|
EXECUTE_WORKFLOW,
|
||||||
|
USER_MANAGEMENT,
|
||||||
|
BUILDER,
|
||||||
|
LIST_USERS,
|
||||||
|
generateAdminPermissions,
|
||||||
|
generatePowerUserPermissions,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue