1
0
Fork 0
mirror of synced 2024-10-02 18:16:29 +13:00

Adding pro integration.

This commit is contained in:
mike12345567 2023-08-15 14:19:36 +01:00
parent 92dd5f1d85
commit b3e8989060
4 changed files with 39 additions and 18 deletions

@ -1 +1 @@
Subproject commit 9b9c8cc08f271bfc5dd401860f344f6eb336ab35
Subproject commit bf719cb968a13183225696a74fb40a78668a54a6

View file

@ -57,6 +57,40 @@ const userSchema = object(
"If set to true forces the user to reset their password on first login.",
type: "boolean",
},
builder: {
description:
"Describes if the user is a builder user or not. This field can only be set on a business or enterprise license.",
type: "object",
properties: {
global: {
description:
"If set to true the user will be able to build any app in the system.",
type: "boolean",
},
},
},
admin: {
description:
"Describes if the user is an admin user or not. This field can only be set on a business or enterprise license.",
type: "object",
properties: {
global: {
description:
"If set to true the user will be able to administrate the system.",
type: "boolean",
},
},
},
roles: {
description:
"Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license.",
type: "object",
additionalProperties: {
type: "string",
description:
"A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN.",
},
},
},
{ required: ["email", "roles"] }
)

View file

@ -9,21 +9,7 @@ import { db as dbCore } from "@budibase/backend-core"
import { search as stringSearch } from "./utils"
import { UserCtx, User } from "@budibase/types"
import { Next } from "koa"
function removeRoles(ctx: UserCtx, oldUser?: User) {
const user = ctx.request.body
if (user.builder) {
user.builder = oldUser?.builder || undefined
}
if (user.admin) {
user.admin = oldUser?.admin || undefined
}
if (user.roles) {
user.roles = oldUser?.roles || {}
}
ctx.request.body = user
return ctx
}
import { sdk } from "@budibase/pro"
function isLoggedInUser(ctx: UserCtx, user: User) {
const loggedInId = ctx.user?._id
@ -49,7 +35,7 @@ export async function search(ctx: UserCtx, next: Next) {
}
export async function create(ctx: UserCtx, next: Next) {
ctx = publicApiUserFix(removeRoles(ctx))
ctx = publicApiUserFix(await sdk.publicApi.userSaveUpdate(ctx))
const response = await saveGlobalUser(ctx)
ctx.body = await getUser(ctx, response._id)
await next()
@ -66,7 +52,7 @@ export async function update(ctx: UserCtx, next: Next) {
...ctx.request.body,
_rev: user._rev,
}
ctx = publicApiUserFix(removeRoles(ctx, user))
ctx = publicApiUserFix(await sdk.publicApi.userSaveUpdate(ctx, user))
const response = await saveGlobalUser(ctx)
ctx.body = await getUser(ctx, response._id)
await next()

View file

@ -11,6 +11,7 @@ export enum Feature {
SYNC_AUTOMATIONS = "syncAutomations",
APP_BUILDERS = "appBuilders",
OFFLINE = "offline",
USER_ROLE_PUBLIC_API = "userRolePublicApi",
}
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }