From 9b99991b2e1267bebd772a80d2001a844c302bf5 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 23 Nov 2023 14:01:58 +0000 Subject: [PATCH 01/27] Update SDK to account for new creator builder flag --- packages/shared-core/src/sdk/documents/users.ts | 10 +++++++++- packages/types/src/documents/global/user.ts | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/shared-core/src/sdk/documents/users.ts b/packages/shared-core/src/sdk/documents/users.ts index b58994aa46..ccd88bf854 100644 --- a/packages/shared-core/src/sdk/documents/users.ts +++ b/packages/shared-core/src/sdk/documents/users.ts @@ -87,13 +87,21 @@ export function hasAdminPermissions(user?: User | ContextUser): boolean { return !!user.admin?.global } +export function hasCreatorPermissions(user?: User | ContextUser): boolean { + if (!user) { + return false + } + return !!user.builder?.creator +} + export function isCreator(user?: User | ContextUser): boolean { if (!user) { return false } return ( - isGlobalBuilder(user) || + isGlobalBuilder(user!) || hasAdminPermissions(user) || + hasCreatorPermissions(user) || hasAppBuilderPermissions(user) || hasAppCreatorPermissions(user) ) diff --git a/packages/types/src/documents/global/user.ts b/packages/types/src/documents/global/user.ts index 9769661cd5..337855787f 100644 --- a/packages/types/src/documents/global/user.ts +++ b/packages/types/src/documents/global/user.ts @@ -44,6 +44,7 @@ export interface User extends Document { builder?: { global?: boolean apps?: string[] + creator?: boolean } admin?: { global: boolean From 35a35f92e61d6293a4f9648803e020a163065322 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 23 Nov 2023 14:02:29 +0000 Subject: [PATCH 02/27] Update constants and user invitation API to account for new creator flag --- packages/frontend-core/src/api/user.js | 26 ++++++++++++++++--------- packages/frontend-core/src/constants.js | 6 ++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/frontend-core/src/api/user.js b/packages/frontend-core/src/api/user.js index 95c2167721..3a815b768e 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -214,15 +214,23 @@ export const buildUserEndpoints = API => ({ inviteUsers: async users => { return await API.post({ url: "/api/global/users/multi/invite", - body: users.map(user => ({ - email: user.email, - userInfo: { - admin: user.admin ? { global: true } : undefined, - builder: user.admin || user.builder ? { global: true } : undefined, - userGroups: user.groups, - roles: user.apps ? user.apps : undefined, - }, - })), + body: users.map(user => { + let builder = undefined + if (user.admin || user.builder) { + builder = { global: true } + } else if (user.creator) { + builder = { creator: true } + } + return { + email: user.email, + userInfo: { + admin: user.admin ? { global: true } : undefined, + builder, + userGroups: user.groups, + roles: user.apps ? user.apps : undefined, + }, + } + }), }) }, diff --git a/packages/frontend-core/src/constants.js b/packages/frontend-core/src/constants.js index 344326065a..d8982276f2 100644 --- a/packages/frontend-core/src/constants.js +++ b/packages/frontend-core/src/constants.js @@ -20,6 +20,7 @@ export const TableNames = { export const BudibaseRoles = { AppUser: "appUser", Developer: "developer", + Creator: "creator", Admin: "admin", } @@ -29,8 +30,9 @@ export const BudibaseRoleOptionsOld = [ { label: "Admin", value: BudibaseRoles.Admin }, ] export const BudibaseRoleOptions = [ - { label: "Member", value: BudibaseRoles.AppUser }, - { label: "Admin", value: BudibaseRoles.Admin }, + { label: "App user", value: BudibaseRoles.AppUser }, + { label: "Creator", value: BudibaseRoles.Creator }, + { label: "Account admin", value: BudibaseRoles.Admin }, ] export const BudibaseRoleOptionsNew = [ From b72b93e5b28cc3fcf28220dc2bff0dd2ee6c77ce Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 23 Nov 2023 14:03:23 +0000 Subject: [PATCH 03/27] Update user invitation modal and details page to allow creating creator users --- .../portal/users/users/[userId].svelte | 23 +++++++++++++++---- .../users/_components/AddUserModal.svelte | 2 +- .../builder/portal/users/users/index.svelte | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte index ec10ec8316..07ed1b26f4 100644 --- a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte @@ -98,7 +98,17 @@ return y._id === userId }) }) - $: globalRole = sdk.users.isAdmin(user) ? "admin" : "appUser" + $: globalRole = getGlobalRole(user) + + const getGlobalRole = user => { + if (sdk.users.isAdmin(user)) { + return Constants.BudibaseRoles.Admin + } else if (sdk.users.isCreator(user)) { + return Constants.BudibaseRoles.Creator + } else { + return Constants.BudibaseRoles.AppUser + } + } const getAvailableApps = (appList, privileged, roles) => { let availableApps = appList.slice() @@ -177,12 +187,17 @@ } async function updateUserRole({ detail }) { - if (detail === "developer") { + if (detail === Constants.BudibaseRoles.Developer) { toggleFlags({ admin: { global: false }, builder: { global: true } }) - } else if (detail === "admin") { + } else if (detail === Constants.BudibaseRoles.Admin) { toggleFlags({ admin: { global: true }, builder: { global: true } }) - } else if (detail === "appUser") { + } else if (detail === Constants.BudibaseRoles.AppUser) { toggleFlags({ admin: { global: false }, builder: { global: false } }) + } else if (detail === Constants.BudibaseRoles.Creator) { + toggleFlags({ + admin: { global: false }, + builder: { global: false, creator: true }, + }) } } diff --git a/packages/builder/src/pages/builder/portal/users/users/_components/AddUserModal.svelte b/packages/builder/src/pages/builder/portal/users/users/_components/AddUserModal.svelte index 806468021f..0730c31674 100644 --- a/packages/builder/src/pages/builder/portal/users/users/_components/AddUserModal.svelte +++ b/packages/builder/src/pages/builder/portal/users/users/_components/AddUserModal.svelte @@ -98,7 +98,7 @@ align-items: center; flex-direction: row;" > -
+
({ email: user.email, builder: user.role === Constants.BudibaseRoles.Developer, + creator: user.role === Constants.BudibaseRoles.Creator, admin: user.role === Constants.BudibaseRoles.Admin, groups: userData.groups, })) From fd5dd8dd72563faf541fe73b1c0cea987bf212c4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 23 Nov 2023 14:12:10 +0000 Subject: [PATCH 04/27] Dedupe and clean up some role logic and constants, and display roles properly in user list --- .../_components/BuilderSidePanel.svelte | 4 +-- .../portal/users/users/[userId].svelte | 13 ++------- .../_components/RoleTableRenderer.svelte | 4 +-- packages/builder/src/stores/portal/users.js | 19 +++++++++---- packages/frontend-core/src/constants.js | 28 +++++++++---------- 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index a67c2d3c61..5c87c1c20c 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -804,8 +804,8 @@ option.value !== Constants.BudibaseRoles.Admin )} label="Role" diff --git a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte index 07ed1b26f4..8bb1ba5452 100644 --- a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte @@ -98,17 +98,7 @@ return y._id === userId }) }) - $: globalRole = getGlobalRole(user) - - const getGlobalRole = user => { - if (sdk.users.isAdmin(user)) { - return Constants.BudibaseRoles.Admin - } else if (sdk.users.isCreator(user)) { - return Constants.BudibaseRoles.Creator - } else { - return Constants.BudibaseRoles.AppUser - } - } + $: globalRole = users.getUserRole(user) const getAvailableApps = (appList, privileged, roles) => { let availableApps = appList.slice() @@ -310,6 +300,7 @@