From b3e89890606f3ca4c37d16dc906f129eaa05f22f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 15 Aug 2023 14:19:36 +0100 Subject: [PATCH] Adding pro integration. --- packages/pro | 2 +- packages/server/specs/resources/user.ts | 34 +++++++++++++++++++ .../src/api/controllers/public/users.ts | 20 ++--------- packages/types/src/sdk/licensing/feature.ts | 1 + 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/packages/pro b/packages/pro index 9b9c8cc08f..bf719cb968 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 9b9c8cc08f271bfc5dd401860f344f6eb336ab35 +Subproject commit bf719cb968a13183225696a74fb40a78668a54a6 diff --git a/packages/server/specs/resources/user.ts b/packages/server/specs/resources/user.ts index 9ec5388672..d00ed02f81 100644 --- a/packages/server/specs/resources/user.ts +++ b/packages/server/specs/resources/user.ts @@ -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"] } ) diff --git a/packages/server/src/api/controllers/public/users.ts b/packages/server/src/api/controllers/public/users.ts index 7aaf520dc4..ddaa7a678e 100644 --- a/packages/server/src/api/controllers/public/users.ts +++ b/packages/server/src/api/controllers/public/users.ts @@ -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() diff --git a/packages/types/src/sdk/licensing/feature.ts b/packages/types/src/sdk/licensing/feature.ts index 20f6813409..a1ace01e48 100644 --- a/packages/types/src/sdk/licensing/feature.ts +++ b/packages/types/src/sdk/licensing/feature.ts @@ -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 }