Move per creator utils into backend core, allow creators to create apps
This commit is contained in:
parent
7984ecde05
commit
ce5d6267cc
|
@ -25,6 +25,7 @@ import {
|
|||
import { getGlobalDB } from "../context"
|
||||
import * as context from "../context"
|
||||
import { isCreator } from "./utils"
|
||||
import { UserDB } from "./db"
|
||||
|
||||
type GetOpts = { cleanup?: boolean }
|
||||
|
||||
|
@ -336,3 +337,19 @@ export function cleanseUserObject(user: User | ContextUser, base?: User) {
|
|||
}
|
||||
return user
|
||||
}
|
||||
|
||||
export async function addAppBuilder(user: User, appId: string) {
|
||||
const prodAppId = getProdAppID(appId)
|
||||
user.builder ??= {}
|
||||
user.builder.apps ??= []
|
||||
user.builder.apps.push(prodAppId)
|
||||
await UserDB.save(user, { hashPassword: false })
|
||||
}
|
||||
|
||||
export async function removeAppBuilder(user: User, appId: string) {
|
||||
const prodAppId = getProdAppID(appId)
|
||||
if (user.builder && user.builder.apps?.includes(prodAppId)) {
|
||||
user.builder.apps = user.builder.apps.filter(id => id !== prodAppId)
|
||||
}
|
||||
await UserDB.save(user, { hashPassword: false })
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@
|
|||
{#if enrichedApps.length}
|
||||
<Layout noPadding gap="L">
|
||||
<div class="title">
|
||||
{#if $auth.user && sdk.users.isGlobalBuilder($auth.user)}
|
||||
{#if $auth.user && sdk.users.canCreateApps($auth.user)}
|
||||
<div class="buttons">
|
||||
<Button
|
||||
size="M"
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 5e3d59fc4060fd44b14b2599269c207753d4e5be
|
||||
Subproject commit 13b15ecb28a147fe89e55314f7f8dfe837c7bdd1
|
|
@ -51,7 +51,6 @@ import {
|
|||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||
import sdk from "../../sdk"
|
||||
import { builderSocket } from "../../websockets"
|
||||
import * as userSdk from "../../sdk/users"
|
||||
import { sdk as sharedCoreSDK } from "@budibase/shared-core"
|
||||
|
||||
// utility function, need to do away with this
|
||||
|
@ -399,9 +398,8 @@ async function appPostCreate(ctx: UserCtx, app: App) {
|
|||
|
||||
// If the user is a creator, we need to give them access to the new app
|
||||
if (sharedCoreSDK.users.hasCreatorPermissions(ctx.user)) {
|
||||
let user = await users.UserDB.getUser(ctx.user._id!)
|
||||
user.roles[dbCore.getProdAppID(app.appId)] = roles.BUILTIN_ROLE_IDS.ADMIN
|
||||
await users.UserDB.save(user)
|
||||
const user = await users.UserDB.getUser(ctx.user._id!)
|
||||
await users.addAppBuilder(user, app.appId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,10 @@ export function isGlobalBuilder(user: User | ContextUser): boolean {
|
|||
return (isBuilder(user) && !hasAppBuilderPermissions(user)) || isAdmin(user)
|
||||
}
|
||||
|
||||
export function canCreateApps(user: User | ContextUser): boolean {
|
||||
return isGlobalBuilder(user) || hasCreatorPermissions(user)
|
||||
}
|
||||
|
||||
// alias for hasAdminPermission, currently do the same thing
|
||||
// in future whether someone has admin permissions and whether they are
|
||||
// an admin for a specific resource could be separated
|
||||
|
|
Loading…
Reference in New Issue