|
|
|
@ -1,10 +1,16 @@
|
|
|
|
|
import TestConfiguration from "../../../config/internal-api/TestConfiguration"
|
|
|
|
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
|
|
|
|
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
|
|
|
|
|
import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications"
|
|
|
|
|
import {
|
|
|
|
|
generateApp,
|
|
|
|
|
appFromTemplate,
|
|
|
|
|
} from "../../../config/internal-api/fixtures/applications"
|
|
|
|
|
import { generateUser } from "../../../config/internal-api/fixtures/userManagement"
|
|
|
|
|
import { User } from "@budibase/types"
|
|
|
|
|
import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table"
|
|
|
|
|
import {
|
|
|
|
|
generateNewColumnForTable,
|
|
|
|
|
generateTable,
|
|
|
|
|
} from "../../../config/internal-api/fixtures/table"
|
|
|
|
|
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
|
|
|
|
import { db } from "@budibase/backend-core"
|
|
|
|
|
|
|
|
|
@ -25,31 +31,37 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(
|
|
|
|
|
appUser
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const app = await config.applications.create(appFromTemplate())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "BASIC",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("Add ADMIN user to app", async () => {
|
|
|
|
|
const adminUser = generateUser(1, "admin")
|
|
|
|
|
expect(adminUser[0].builder?.global).toEqual(true)
|
|
|
|
|
expect(adminUser[0].admin?.global).toEqual(true)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(
|
|
|
|
|
adminUser
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//const app = await config.applications.create(generateApp())
|
|
|
|
|
//config.applications.api.appId = app.appId
|
|
|
|
@ -57,16 +69,19 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const app = await config.applications.create(appFromTemplate())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "ADMIN",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
|
|
|
|
|
|
|
|
|
@ -75,31 +90,34 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
// check published app renders
|
|
|
|
|
config.applications.api.appId = db.getProdAppID(app.appId!)
|
|
|
|
|
await config.applications.canRender()
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("Add POWER user to app", async () => {
|
|
|
|
|
const powerUser = generateUser(1, 'developer')
|
|
|
|
|
const powerUser = generateUser(1, "developer")
|
|
|
|
|
expect(powerUser[0].builder?.global).toEqual(true)
|
|
|
|
|
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(
|
|
|
|
|
powerUser
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "POWER",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("Check Access for default roles", () => {
|
|
|
|
@ -107,21 +125,25 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "BASIC",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("BASIC")
|
|
|
|
|
|
|
|
|
@ -130,37 +152,43 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
)
|
|
|
|
|
await config.login(<string>appUser[0].email, <string>appUser[0].password)
|
|
|
|
|
const newColumn = generateNewColumnForTable(createdTableData)
|
|
|
|
|
await config.tables.forbiddenSave(
|
|
|
|
|
newColumn)
|
|
|
|
|
await config.tables.forbiddenSave(newColumn)
|
|
|
|
|
await config.tables.forbiddenSave(generateTable())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("Check Table access for developer", async () => {
|
|
|
|
|
const developer = generateUser(1, 'developer')
|
|
|
|
|
const developer = generateUser(1, "developer")
|
|
|
|
|
expect(developer[0].builder?.global).toEqual(true)
|
|
|
|
|
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(developer)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(developer)
|
|
|
|
|
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "POWER",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("POWER")
|
|
|
|
|
|
|
|
|
|
const [createdTableResponse, createdTableData] = await config.tables.save(
|
|
|
|
|
generateTable()
|
|
|
|
|
)
|
|
|
|
|
await config.login(<string>developer[0].email, <string>developer[0].password)
|
|
|
|
|
await config.login(
|
|
|
|
|
<string>developer[0].email,
|
|
|
|
|
<string>developer[0].password
|
|
|
|
|
)
|
|
|
|
|
const newColumn = generateNewColumnForTable(createdTableData)
|
|
|
|
|
const [addColumnResponse, addColumnData] = await config.tables.save(
|
|
|
|
|
newColumn,
|
|
|
|
@ -172,25 +200,32 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const adminUser = generateUser(1, "admin")
|
|
|
|
|
expect(adminUser[0].builder?.global).toEqual(true)
|
|
|
|
|
expect(adminUser[0].admin?.global).toEqual(true)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(adminUser)
|
|
|
|
|
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const body: User = {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[<string>app.appId]: "ADMIN",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[<string>app.appId]).toEqual("ADMIN")
|
|
|
|
|
|
|
|
|
|
await config.login(<string>adminUser[0].email, <string>adminUser[0].password)
|
|
|
|
|
await config.login(
|
|
|
|
|
<string>adminUser[0].email,
|
|
|
|
|
<string>adminUser[0].password
|
|
|
|
|
)
|
|
|
|
|
const [createdTableResponse, createdTableData] = await config.tables.save(
|
|
|
|
|
generateTable()
|
|
|
|
|
)
|
|
|
|
@ -208,14 +243,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -223,11 +261,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: "BASIC",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual("BASIC")
|
|
|
|
|
|
|
|
|
@ -236,7 +275,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -245,7 +285,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC")
|
|
|
|
@ -256,14 +297,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -271,11 +315,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: "POWER",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual("POWER")
|
|
|
|
|
|
|
|
|
@ -284,7 +329,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -293,7 +339,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(2)
|
|
|
|
|
})
|
|
|
|
@ -303,14 +350,17 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
|
config.applications.api.appId = app.appId
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -318,11 +368,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: "ADMIN",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual("ADMIN")
|
|
|
|
|
|
|
|
|
@ -331,7 +382,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -340,7 +392,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(3)
|
|
|
|
|
})
|
|
|
|
@ -351,7 +404,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
@ -361,14 +415,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const role = {
|
|
|
|
|
inherits: "BASIC",
|
|
|
|
|
permissionId: "public",
|
|
|
|
|
name: "level 1"
|
|
|
|
|
name: "level 1",
|
|
|
|
|
}
|
|
|
|
|
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [createRoleResponse, createRoleJson] =
|
|
|
|
|
await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -376,11 +431,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: createRoleJson._id,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
|
|
|
|
|
|
|
|
|
@ -389,7 +445,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -398,15 +455,18 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
})
|
|
|
|
|
it("Custom role access for level 2 permissions", async () => {// Set up user
|
|
|
|
|
it("Custom role access for level 2 permissions", async () => {
|
|
|
|
|
// Set up user
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
@ -416,14 +476,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const role = {
|
|
|
|
|
inherits: "BASIC",
|
|
|
|
|
permissionId: "read_only",
|
|
|
|
|
name: "level 2"
|
|
|
|
|
name: "level 2",
|
|
|
|
|
}
|
|
|
|
|
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [createRoleResponse, createRoleJson] =
|
|
|
|
|
await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -431,11 +492,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: createRoleJson._id,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
|
|
|
|
|
|
|
|
|
@ -444,7 +506,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -453,7 +516,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
})
|
|
|
|
@ -461,7 +525,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
@ -471,14 +536,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const role = {
|
|
|
|
|
inherits: "BASIC",
|
|
|
|
|
permissionId: "write",
|
|
|
|
|
name: "level 3"
|
|
|
|
|
name: "level 3",
|
|
|
|
|
}
|
|
|
|
|
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [createRoleResponse, createRoleJson] =
|
|
|
|
|
await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -486,11 +552,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: createRoleJson._id,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
|
|
|
|
|
|
|
|
|
@ -499,7 +566,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -508,7 +576,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
})
|
|
|
|
@ -516,7 +585,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
@ -526,14 +596,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const role = {
|
|
|
|
|
inherits: "BASIC",
|
|
|
|
|
permissionId: "power",
|
|
|
|
|
name: "level 4"
|
|
|
|
|
name: "level 4",
|
|
|
|
|
}
|
|
|
|
|
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [createRoleResponse, createRoleJson] =
|
|
|
|
|
await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -541,11 +612,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: createRoleJson._id,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
|
|
|
|
|
|
|
|
|
@ -554,7 +626,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -563,7 +636,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
})
|
|
|
|
@ -571,7 +645,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const appUser = generateUser()
|
|
|
|
|
expect(appUser[0].builder?.global).toEqual(false)
|
|
|
|
|
expect(appUser[0].admin?.global).toEqual(false)
|
|
|
|
|
const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser)
|
|
|
|
|
const [createUserResponse, createUserJson] =
|
|
|
|
|
await config.users.addMultiple(appUser)
|
|
|
|
|
|
|
|
|
|
// Create App
|
|
|
|
|
const app = await config.applications.create(generateApp())
|
|
|
|
@ -581,14 +656,15 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const role = {
|
|
|
|
|
inherits: "BASIC",
|
|
|
|
|
permissionId: "admin",
|
|
|
|
|
name: "level 5"
|
|
|
|
|
name: "level 5",
|
|
|
|
|
}
|
|
|
|
|
const [createRoleResponse, createRoleJson] = await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [createRoleResponse, createRoleJson] =
|
|
|
|
|
await config.users.createRole(role)
|
|
|
|
|
|
|
|
|
|
// Update user roles
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [userInfoResponse, userInfoJson] = await config.users.getInfo(
|
|
|
|
|
createUserJson.created.successful[0]._id
|
|
|
|
|
)
|
|
|
|
|
const prodAppId = db.getProdAppID(app.appId!)
|
|
|
|
|
|
|
|
|
|
// Roles must always be set with prod appID
|
|
|
|
@ -596,11 +672,12 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
...userInfoJson,
|
|
|
|
|
roles: {
|
|
|
|
|
[prodAppId]: createRoleJson._id,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
await config.users.updateInfo(body)
|
|
|
|
|
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
const [changedUserInfoResponse, changedUserInfoJson] =
|
|
|
|
|
await config.users.getInfo(createUserJson.created.successful[0]._id)
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toBeDefined()
|
|
|
|
|
expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id)
|
|
|
|
|
|
|
|
|
@ -609,7 +686,8 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
await config.screen.create(generateScreen("ADMIN"))
|
|
|
|
|
|
|
|
|
|
await config.applications.publish(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
const [firstappPackageResponse, firstappPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(<string>app.appId)
|
|
|
|
|
expect(firstappPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(firstappPackageJson.screens.length).toEqual(3)
|
|
|
|
|
|
|
|
|
@ -618,10 +696,10 @@ describe("Internal API - App Specific Roles & Permissions", () => {
|
|
|
|
|
const [selfInfoResponse, selfInfoJson] = await config.users.getSelf()
|
|
|
|
|
|
|
|
|
|
// fetch app package
|
|
|
|
|
const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
const [appPackageResponse, appPackageJson] =
|
|
|
|
|
await config.applications.getAppPackage(app.appId!)
|
|
|
|
|
expect(appPackageJson.screens).toBeDefined()
|
|
|
|
|
expect(appPackageJson.screens.length).toEqual(1)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|