Adding fix for global user retrieval as part of admin creation.
This commit is contained in:
parent
e7ff299c63
commit
3344a756d7
|
@ -1,7 +1,6 @@
|
||||||
const {
|
const {
|
||||||
generateConfigID,
|
generateConfigID,
|
||||||
getConfigParams,
|
getConfigParams,
|
||||||
getGlobalUserParams,
|
|
||||||
getScopedFullConfig,
|
getScopedFullConfig,
|
||||||
getAllApps,
|
getAllApps,
|
||||||
} = require("@budibase/backend-core/db")
|
} = require("@budibase/backend-core/db")
|
||||||
|
@ -20,6 +19,7 @@ const {
|
||||||
bustCache,
|
bustCache,
|
||||||
} = require("@budibase/backend-core/cache")
|
} = require("@budibase/backend-core/cache")
|
||||||
const { events } = require("@budibase/backend-core")
|
const { events } = require("@budibase/backend-core")
|
||||||
|
const { checkAnyUserExists } = require("../../../utilities/users")
|
||||||
|
|
||||||
const BB_TENANT_CDN = "https://tenants.cdn.budi.live"
|
const BB_TENANT_CDN = "https://tenants.cdn.budi.live"
|
||||||
|
|
||||||
|
@ -405,12 +405,7 @@ exports.configChecklist = async function (ctx) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// They have set up an global user
|
// They have set up an global user
|
||||||
const users = await db.allDocs(
|
const userExists = await checkAnyUserExists()
|
||||||
getGlobalUserParams(null, {
|
|
||||||
include_docs: true,
|
|
||||||
limit: 1,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
apps: {
|
apps: {
|
||||||
checked: apps.length > 0,
|
checked: apps.length > 0,
|
||||||
|
@ -423,7 +418,7 @@ exports.configChecklist = async function (ctx) {
|
||||||
link: "/builder/portal/manage/email",
|
link: "/builder/portal/manage/email",
|
||||||
},
|
},
|
||||||
adminUser: {
|
adminUser: {
|
||||||
checked: users && users.rows.length >= 1,
|
checked: userExists,
|
||||||
label: "Create your first user",
|
label: "Create your first user",
|
||||||
link: "/builder/portal/manage/users",
|
link: "/builder/portal/manage/users",
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,16 +8,15 @@ import {
|
||||||
events,
|
events,
|
||||||
errors,
|
errors,
|
||||||
accounts,
|
accounts,
|
||||||
db as dbUtils,
|
|
||||||
users as usersCore,
|
users as usersCore,
|
||||||
tenancy,
|
tenancy,
|
||||||
cache,
|
cache,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
|
import { checkAnyUserExists } from "../../../utilities/users"
|
||||||
|
|
||||||
export const save = async (ctx: any) => {
|
export const save = async (ctx: any) => {
|
||||||
try {
|
try {
|
||||||
const user = await users.save(ctx.request.body)
|
ctx.body = await users.save(ctx.request.body)
|
||||||
ctx.body = user
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
ctx.throw(err.status || 400, err)
|
ctx.throw(err.status || 400, err)
|
||||||
}
|
}
|
||||||
|
@ -39,15 +38,8 @@ export const adminUser = async (ctx: any) => {
|
||||||
ctx.throw(403, "Organisation already exists.")
|
ctx.throw(403, "Organisation already exists.")
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await tenancy.doWithGlobalDB(tenantId, async (db: any) => {
|
const userExists = await checkAnyUserExists()
|
||||||
return db.allDocs(
|
if (userExists) {
|
||||||
dbUtils.getGlobalUserParams(null, {
|
|
||||||
include_docs: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.rows.some((row: any) => row.doc.admin)) {
|
|
||||||
ctx.throw(
|
ctx.throw(
|
||||||
403,
|
403,
|
||||||
"You cannot initialise once an global user has been created."
|
"You cannot initialise once an global user has been created."
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
||||||
|
const { getGlobalUserParams } = require("@budibase/backend-core/db")
|
||||||
|
|
||||||
|
exports.checkAnyUserExists = async () => {
|
||||||
|
try {
|
||||||
|
const db = getGlobalDB()
|
||||||
|
const users = await db.allDocs(
|
||||||
|
getGlobalUserParams(null, {
|
||||||
|
include_docs: true,
|
||||||
|
limit: 1,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return users && users.rows.length >= 1
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error("Unable to retrieve user list")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue