forked from tsai/budibase
73 changed files with 4212 additions and 1564 deletions
@ -1,9 +1,9 @@ |
|||||
{ |
{ |
||||
"baseUrl": "http://localhost:10000/builder/", |
"baseUrl": "http://localhost:10001/builder/", |
||||
"video": true, |
"video": true, |
||||
"projectId": "bmbemn", |
"projectId": "bmbemn", |
||||
"env": { |
"env": { |
||||
"PORT": "10000", |
"PORT": "10001", |
||||
"JWT_SECRET": "test" |
"JWT_SECRET": "test" |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,11 +1,10 @@ |
|||||
context("Create a User", () => { |
context("Create a User", () => { |
||||
before(() => { |
before(() => { |
||||
cy.login() |
cy.login() |
||||
cy.createTestApp() |
|
||||
}) |
}) |
||||
|
|
||||
it("should create a user", () => { |
it("should create a user", () => { |
||||
cy.createUser("bbuser@test.com", "test", "ADMIN") |
cy.createUser("bbuser@test.com") |
||||
cy.contains("bbuser").should("be.visible") |
cy.contains("bbuser").should("be.visible") |
||||
}) |
}) |
||||
}) |
}) |
||||
|
|||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,64 @@ |
|||||
|
const CouchDB = require("../db") |
||||
|
const { |
||||
|
getMultiIDParams, |
||||
|
getGlobalIDFromUserMetadataID, |
||||
|
StaticDatabases, |
||||
|
} = require("../db/utils") |
||||
|
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") |
||||
|
const { getDeployedAppID } = require("@budibase/auth/db") |
||||
|
const { getGlobalUserParams } = require("@budibase/auth/db") |
||||
|
|
||||
|
exports.updateAppRole = (appId, user) => { |
||||
|
if (!user.roles) { |
||||
|
return user |
||||
|
} |
||||
|
if (user.builder && user.builder.global) { |
||||
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN |
||||
|
} else { |
||||
|
// always use the deployed app
|
||||
|
user.roleId = user.roles[getDeployedAppID(appId)] |
||||
|
if (!user.roleId) { |
||||
|
user.roleId = BUILTIN_ROLE_IDS.PUBLIC |
||||
|
} |
||||
|
} |
||||
|
delete user.roles |
||||
|
return user |
||||
|
} |
||||
|
|
||||
|
exports.getGlobalUser = async (appId, userId) => { |
||||
|
const db = CouchDB(StaticDatabases.GLOBAL.name) |
||||
|
let user = await db.get(getGlobalIDFromUserMetadataID(userId)) |
||||
|
if (user) { |
||||
|
delete user.password |
||||
|
} |
||||
|
return exports.updateAppRole(appId, user) |
||||
|
} |
||||
|
|
||||
|
exports.getGlobalUsers = async (appId = null, users = null) => { |
||||
|
const db = CouchDB(StaticDatabases.GLOBAL.name) |
||||
|
let globalUsers |
||||
|
if (users) { |
||||
|
const globalIds = users.map(user => getGlobalIDFromUserMetadataID(user._id)) |
||||
|
globalUsers = (await db.allDocs(getMultiIDParams(globalIds))).rows.map( |
||||
|
row => row.doc |
||||
|
) |
||||
|
} else { |
||||
|
globalUsers = ( |
||||
|
await db.allDocs( |
||||
|
getGlobalUserParams(null, { |
||||
|
include_docs: true, |
||||
|
}) |
||||
|
) |
||||
|
).rows.map(row => row.doc) |
||||
|
} |
||||
|
globalUsers = globalUsers |
||||
|
.filter(user => user != null) |
||||
|
.map(user => { |
||||
|
delete user.password |
||||
|
return user |
||||
|
}) |
||||
|
if (!appId) { |
||||
|
return globalUsers |
||||
|
} |
||||
|
return globalUsers.map(user => exports.updateAppRole(appId, user)) |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue