From 206af376fdd06df407958abcf6d5653dff9ae4f1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 11:06:49 +0100 Subject: [PATCH 001/155] Update groups list and groups details pages to new designs. Multiple fixes and improvements. Standardise divider thickness --- packages/bbui/src/Modal/ModalContent.svelte | 2 +- .../PlusConfigForm.svelte | 4 +- .../rest/RestExtraConfigForm.svelte | 6 +- .../settings/controls/DataSourceSelect.svelte | 14 +- .../[selectedDatasource]/index.svelte | 4 +- .../rest/[query]/index.svelte | 2 +- .../pages/builder/portal/apps/create.svelte | 2 +- .../builder/portal/manage/_layout.svelte | 4 +- .../builder/portal/manage/auth/index.svelte | 4 +- .../builder/portal/manage/email/index.svelte | 4 +- .../portal/manage/groups/[groupId].svelte | 238 ++++++++++-------- .../groups/_components/GroupIcon.svelte | 20 ++ .../GroupNameTableRenderer.svelte} | 19 +- .../groups/_components/UserGroupsRow.svelte | 48 +--- .../_components/UsersTableRenderer.svelte | 22 ++ .../builder/portal/manage/groups/index.svelte | 168 +++++++------ .../portal/manage/users/[userId].svelte | 2 +- .../_components/AppsTableRenderer.svelte | 1 - .../_components/GroupsTableRenderer.svelte | 2 - .../builder/portal/manage/users/index.svelte | 2 +- .../portal/settings/organisation.svelte | 6 +- .../builder/portal/settings/theming.svelte | 2 +- .../builder/portal/settings/update.svelte | 2 +- .../builder/portal/settings/upgrade.svelte | 4 +- .../builder/portal/settings/usage.svelte | 2 +- 25 files changed, 313 insertions(+), 271 deletions(-) create mode 100644 packages/builder/src/pages/builder/portal/manage/groups/_components/GroupIcon.svelte rename packages/builder/src/pages/builder/portal/manage/{users/_components/NameTableRenderer.svelte => groups/_components/GroupNameTableRenderer.svelte} (50%) create mode 100644 packages/builder/src/pages/builder/portal/manage/groups/_components/UsersTableRenderer.svelte diff --git a/packages/bbui/src/Modal/ModalContent.svelte b/packages/bbui/src/Modal/ModalContent.svelte index 6d609d6f1b..17a251ff55 100644 --- a/packages/bbui/src/Modal/ModalContent.svelte +++ b/packages/bbui/src/Modal/ModalContent.svelte @@ -80,7 +80,7 @@ {/if} {#if showDivider} - + {/if} {/if} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte index cd19523476..93ded3a0ab 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte @@ -156,7 +156,7 @@ - +
Tables
@@ -192,7 +192,7 @@ {:else} No tables found. {/if} - +
Relationships @@ -111,7 +111,7 @@ {#if datasource.plus} {/if} - +
Queries
diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 5ccc173318..58f6905cd4 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -548,7 +548,7 @@
- + {#if !response && Object.keys(schema).length === 0} Response
diff --git a/packages/builder/src/pages/builder/portal/apps/create.svelte b/packages/builder/src/pages/builder/portal/apps/create.svelte index 4fd69bc815..ac06df933b 100644 --- a/packages/builder/src/pages/builder/portal/apps/create.svelte +++ b/packages/builder/src/pages/builder/portal/apps/create.svelte @@ -105,7 +105,7 @@
- + {#if loaded && $templates?.length} diff --git a/packages/builder/src/pages/builder/portal/manage/_layout.svelte b/packages/builder/src/pages/builder/portal/manage/_layout.svelte index 47d9aaf59e..3df77abd44 100644 --- a/packages/builder/src/pages/builder/portal/manage/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/manage/_layout.svelte @@ -10,9 +10,7 @@ } } - $: wide = - $page.path.includes("email/:template") || - ($page.path.includes("groups") && !$page.path.includes(":groupId")) + $: wide = $page.path.includes("email/:template") {#if $auth.isAdmin} diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index bc77329a32..5029cc6517 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -295,7 +295,7 @@ {#if providers.google} - +
@@ -334,7 +334,7 @@ {/if} {#if providers.oidc} - +
diff --git a/packages/builder/src/pages/builder/portal/manage/email/index.svelte b/packages/builder/src/pages/builder/portal/manage/email/index.svelte index 812aa5b014..71583222da 100644 --- a/packages/builder/src/pages/builder/portal/manage/email/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/email/index.svelte @@ -132,7 +132,7 @@ values below and click activate. - + {#if smtpConfig} SMTP @@ -186,7 +186,7 @@ Reset
- + Templates diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 17c16c639b..e526f7462b 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -5,13 +5,16 @@ Button, Layout, Heading, - Body, Icon, Popover, notifications, List, ListItem, StatusLight, + Divider, + ActionMenu, + MenuItem, + Modal, } from "@budibase/bbui" import UserGroupPicker from "components/settings/UserGroupPicker.svelte" import { createPaginationStore } from "helpers/pagination" @@ -19,6 +22,9 @@ import { onMount } from "svelte" import { RoleUtils } from "@budibase/frontend-core" import { roles } from "stores/backend" + import ConfirmDialog from "components/common/ConfirmDialog.svelte" + import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" + import GroupIcon from "./_components/GroupIcon.svelte" export let groupId @@ -29,10 +35,16 @@ let prevSearch = undefined let pageInfo = createPaginationStore() let loaded = false + let editModal + let deleteModal $: page = $pageInfo.page $: fetchUsers(page, searchTerm) $: group = $groups.find(x => x._id === groupId) + $: filtered = + $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) || + [] + $: groupApps = $apps.filter(x => group?.apps.includes(x.appId)) async function addAll() { selectedUsers = [...selectedUsers, ...filtered.map(u => u._id)] @@ -88,11 +100,7 @@ userGroups, }) } - $: filtered = - $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) || - [] - $: groupApps = $apps.filter(x => group.apps.includes(x.appId)) async function removeUser(id) { let newUsers = group.users.filter(user => user._id !== id) group.users = newUsers @@ -131,6 +139,25 @@ return role?.name || "Custom role" } + async function deleteGroup() { + try { + await groups.actions.delete(group) + notifications.success("User group deleted successfully") + $goto("./") + } catch (error) { + console.log(error) + notifications.error(`Failed to delete user group`) + } + } + + async function saveGroup(group) { + try { + await groups.actions.save(group) + } catch (error) { + notifications.error(`Failed to save user group`) + } + } + onMount(async () => { try { await Promise.all([groups.actions.init(), apps.load(), roles.fetch()]) @@ -142,119 +169,132 @@ {#if loaded} - +
- $goto("../groups")} - size="S" - icon="ArrowLeft" - > + $goto("../groups")} icon="ArrowLeft"> Back
-
-
-
-
- + + +
+
+ +
+ {group?.name}
-
- {group?.name} +
+ + + + + editModal.show()}> + Edit + + deleteModal.show()}> + Delete + +
-
- -
- - - -
- - {#if group?.users.length} - {#each group.users as user} - removeUser(user?._id)} - hoverable - size="L" - name="Close" - /> - {/each} - {:else} - - {/if} - -
- Apps -
- Manage apps that this User group has been assigned to -
-
+ - - {#if groupApps.length} - {#each groupApps as app} - -
- - {getRoleLabel(app.appId)} - -
-
- {/each} - {:else} - - {/if} -
+ +
+ Users +
+ +
+ + + +
+ + {#if group?.users.length} + {#each group.users as user} + + removeUser(user?._id)} + hoverable + size="S" + name="Close" + /> + + {/each} + {:else} + + {/if} + +
+
+ + + Apps + + {#if groupApps.length} + {#each groupApps as app} + +
+ + {getRoleLabel(app.appId)} + +
+
+ {/each} + {:else} + + {/if} +
+
{/if} - diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupIcon.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupIcon.svelte new file mode 100644 index 0000000000..b4da6b4440 --- /dev/null +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupIcon.svelte @@ -0,0 +1,20 @@ + + +
+ +
+ + diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/NameTableRenderer.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupNameTableRenderer.svelte similarity index 50% rename from packages/builder/src/pages/builder/portal/manage/users/_components/NameTableRenderer.svelte rename to packages/builder/src/pages/builder/portal/manage/groups/_components/GroupNameTableRenderer.svelte index a4b65c4d62..e14458d12a 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/NameTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/GroupNameTableRenderer.svelte @@ -1,20 +1,13 @@
{#if value} -
- x[0]) - .join("")} - /> -
+ {value} {:else}
-
@@ -26,12 +19,8 @@ display: flex; align-items: center; overflow: hidden; + gap: var(--spacing-m); } - - .spacing { - margin-right: var(--spacing-m); - } - .text { opacity: 0.8; } diff --git a/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte b/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte index e00123614a..73763fc466 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/_components/UserGroupsRow.svelte @@ -21,11 +21,6 @@
-
-
- -
-
{group.name}
@@ -50,31 +45,12 @@ : "s"}
-
-
-
- -
-
- - - - - deleteGroup(group)} icon="Delete" - >Delete - editGroup(group)} icon="Edit">Edit - -
-
-
- - - + + + + diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index ddd734dd69..cac6a28275 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -4,16 +4,23 @@ Heading, Body, Button, + ButtonGroup, Modal, Tag, Tags, + Table, + Divider, + Search, notifications, } from "@budibase/bbui" import { groups, auth } from "stores/portal" import { onMount } from "svelte" import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" - import UserGroupsRow from "./_components/UserGroupsRow.svelte" import { cloneDeep } from "lodash/fp" + import AppsTableRenderer from "../users/_components/AppsTableRenderer.svelte" + import UsersTableRenderer from "./_components/UsersTableRenderer.svelte" + import GroupNameTableRenderer from "./_components/GroupNameTableRenderer.svelte" + import { goto } from "@roxi/routify" const DefaultGroup = { name: "", @@ -23,22 +30,39 @@ apps: [], roles: {}, } - let modal - let group = cloneDeep(DefaultGroup) - async function deleteGroup(group) { - try { - groups.actions.delete(group) - } catch (error) { - notifications.error(`Failed to delete group`) + let modal + let searchString + let group = cloneDeep(DefaultGroup) + let customRenderers = [ + { column: "name", component: GroupNameTableRenderer }, + { column: "users", component: UsersTableRenderer }, + { column: "apps", component: AppsTableRenderer }, + ] + + $: schema = { + name: {}, + users: { sortable: false }, + apps: { sortable: false }, + } + $: filteredGroups = filterGroups($groups, searchString) + + const filterGroups = (groups, searchString) => { + if (!searchString) { + return groups } + searchString = searchString.toLocaleLowerCase() + return groups?.filter(group => { + return group.name?.toLowerCase().includes(searchString) + }) } async function saveGroup(group) { try { await groups.actions.save(group) + notifications.success(`User group created successfully`) } catch (error) { - notifications.error(`Failed to save group`) + notifications.error(`Failed to save user group`) } } @@ -53,58 +77,63 @@ await groups.actions.init() } } catch (error) { - notifications.error("Error getting User groups") + notifications.error("Error getting user groups") } }) - + -
- User groups - {#if !$auth.groupsEnabled} - -
-
- Pro plan -
+ User groups + {#if !$auth.groupsEnabled} + +
+
+ Pro plan
- - {/if} -
+
+
+ {/if} Easily assign and manage your users access with User Groups -
- - {#if !$auth.groupsEnabled} + +
+ - {/if} -
- - {#if $auth.groupsEnabled && $groups.length} -
- {#each $groups as group} -
- -
- {/each} + {$auth.groupsEnabled ? "Create user group" : "Upgrade Account"} + + {#if !$auth.groupsEnabled} + + {/if} + +
+
- {/if} +
+ $goto(`./${detail._id}`)} + {schema} + data={filteredGroups} + allowEditColumns={false} + allowEditRows={false} + showHeaderBorder={false} + {customRenderers} + /> @@ -112,37 +141,24 @@ diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 8f7b24f1b6..0d22e78ccc 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -247,7 +247,7 @@ {/if} - + Details
diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/AppsTableRenderer.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/AppsTableRenderer.svelte index d348082ffa..895507e063 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/AppsTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/AppsTableRenderer.svelte @@ -15,7 +15,6 @@ display: flex; overflow: hidden; } - .spacing { margin-right: var(--spacing-m); } diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/GroupsTableRenderer.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/GroupsTableRenderer.svelte index b334575669..763b6b6dc9 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/GroupsTableRenderer.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/GroupsTableRenderer.svelte @@ -18,11 +18,9 @@ display: flex; overflow: hidden; } - .opacity { opacity: 0.8; } - .spacing { margin-right: var(--spacing-m); } diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index 73cf5e26fa..b48824f294 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -210,7 +210,7 @@ Users Add users and control who gets access to your published apps - +
{#if !$admin.cloud} - + Platform Here you can set up general platform settings. @@ -127,7 +127,7 @@ {/if} {#if !$admin.cloud} - + Analytics Choose whether to opt-in or opt-out of analytics. diff --git a/packages/builder/src/pages/builder/portal/settings/theming.svelte b/packages/builder/src/pages/builder/portal/settings/theming.svelte index ac5398a032..815c0d2813 100644 --- a/packages/builder/src/pages/builder/portal/settings/theming.svelte +++ b/packages/builder/src/pages/builder/portal/settings/theming.svelte @@ -9,7 +9,7 @@ Theming Customize how Budibase looks and feels. - +
diff --git a/packages/builder/src/pages/builder/portal/settings/update.svelte b/packages/builder/src/pages/builder/portal/settings/update.svelte index d87736144d..1e25a04da2 100644 --- a/packages/builder/src/pages/builder/portal/settings/update.svelte +++ b/packages/builder/src/pages/builder/portal/settings/update.svelte @@ -60,7 +60,7 @@ latest features, security updates and much more. - + {#if version}
diff --git a/packages/builder/src/pages/builder/portal/settings/upgrade.svelte b/packages/builder/src/pages/builder/portal/settings/upgrade.svelte index 5200834ffa..15c1a2bc52 100644 --- a/packages/builder/src/pages/builder/portal/settings/upgrade.svelte +++ b/packages/builder/src/pages/builder/portal/settings/upgrade.svelte @@ -88,7 +88,7 @@ {/if} - + Activate Enter your license key below to activate your plan @@ -111,7 +111,7 @@ >
- + Plan diff --git a/packages/builder/src/pages/builder/portal/settings/usage.svelte b/packages/builder/src/pages/builder/portal/settings/usage.svelte index 069c37b555..70b4abb378 100644 --- a/packages/builder/src/pages/builder/portal/settings/usage.svelte +++ b/packages/builder/src/pages/builder/portal/settings/usage.svelte @@ -96,7 +96,7 @@ - + From df0c1df86814a385a46441a1fd65f1ff956bef12 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 11:11:44 +0100 Subject: [PATCH 002/155] Make users and apps in group details page clickable --- .../builder/portal/manage/groups/[groupId].svelte | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index e526f7462b..5ddb82ca30 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -224,9 +224,14 @@ {#if group?.users.length} {#each group.users as user} - + $goto(`../users/${user._id}`)} + hoverable + > removeUser(user?._id)} + on:click={() => removeUser(user._id)} hoverable size="S" name="Close" @@ -252,6 +257,8 @@ title={app.name} icon={app?.icon?.name || "Apps"} iconBackground={app?.icon?.color || ""} + on:click={() => $goto(`../../overview/${app.devId}`)} + hoverable >
Date: Thu, 4 Aug 2022 11:20:13 +0100 Subject: [PATCH 003/155] Update text to be consistent --- .../builder/portal/manage/groups/[groupId].svelte | 10 +++++----- .../pages/builder/portal/manage/groups/index.svelte | 2 +- .../pages/builder/portal/manage/users/[userId].svelte | 4 ++-- .../src/pages/builder/portal/manage/users/index.svelte | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 5ddb82ca30..a088d148c3 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -239,10 +239,7 @@ {/each} {:else} - + {/if} @@ -273,7 +270,10 @@ {/each} {:else} - + {/if} diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index cac6a28275..df44a1a333 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -94,7 +94,7 @@
{/if} - Easily assign and manage your users access with User Groups + Easily assign and manage your users' access with user groups
diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 0d22e78ccc..a77f8a4872 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -330,7 +330,7 @@ {/each} {:else} - + {/if} @@ -359,7 +359,7 @@ {/each} {:else} - + {/if} diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index b48824f294..a474ca708d 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -50,7 +50,7 @@ sortable: false, }, ...($auth.groupsEnabled && { - userGroups: { sortable: false, displayName: "Groups" }, + userGroups: { sortable: false, displayName: "User groups" }, }), apps: {}, } @@ -229,7 +229,7 @@
- + {#if selectedRows.length > 0} Date: Thu, 4 Aug 2022 11:21:31 +0100 Subject: [PATCH 004/155] Fix issue when using an invalid user ID in url --- .../src/pages/builder/portal/manage/users/[userId].svelte | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index a77f8a4872..686223ff39 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -188,6 +188,9 @@ async function fetchUser(userId) { let userPromise = users.get(userId) user = await userPromise + if (!user?._id) { + $goto("./") + } } async function toggleFlags(detail) { From fbb4692ba53ba72acb7803bee30af87b960175fe Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 11:28:55 +0100 Subject: [PATCH 005/155] Fix issue when using an invalid group ID in url --- .../portal/apps/_components/AcessFilter.svelte | 12 ++---------- .../builder/portal/manage/groups/[groupId].svelte | 5 +++++ .../pages/builder/portal/manage/groups/index.svelte | 4 +--- packages/builder/src/stores/portal/groups.js | 5 +---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte b/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte index d0662e7b41..a75ed7c4de 100644 --- a/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte +++ b/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte @@ -1,7 +1,7 @@ !group?.users.map(y => y._id).includes(x._id)) || [] $: groupApps = $apps.filter(x => group?.apps.includes(x.appId)) + $: { + if (loaded && !group?._id) { + $goto("./") + } + } async function addAll() { selectedUsers = [...selectedUsers, ...filtered.map(u => u._id)] diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index df44a1a333..b8e0bb3df2 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -73,9 +73,7 @@ onMount(async () => { try { - if ($auth.groupsEnabled) { - await groups.actions.init() - } + await groups.actions.init() } catch (error) { notifications.error("Error getting user groups") } diff --git a/packages/builder/src/stores/portal/groups.js b/packages/builder/src/stores/portal/groups.js index ca814ac057..8d9f6fa132 100644 --- a/packages/builder/src/stores/portal/groups.js +++ b/packages/builder/src/stores/portal/groups.js @@ -1,7 +1,6 @@ import { writable, get } from "svelte/store" import { API } from "api" import { auth } from "stores/portal" -import { Constants } from "@budibase/frontend-core" export function createGroupsStore() { const store = writable([]) @@ -10,9 +9,7 @@ export function createGroupsStore() { init: async () => { // only init if these is a groups license, just to be sure but the feature will be blocked // on the backend anyway - if ( - get(auth).user.license.features.includes(Constants.Features.USER_GROUPS) - ) { + if (get(auth).groupsEnabled) { const users = await API.getGroups() store.set(users) } From 4d475c3cd493f30d930578ca18e540dc5eaa7ccf Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 11:31:06 +0100 Subject: [PATCH 006/155] Navigate to group upon creation --- .../src/pages/builder/portal/manage/groups/index.svelte | 3 ++- packages/builder/src/stores/portal/groups.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index b8e0bb3df2..ad16c45047 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -59,7 +59,8 @@ async function saveGroup(group) { try { - await groups.actions.save(group) + group = await groups.actions.save(group) + $goto(`./${group._id}`) notifications.success(`User group created successfully`) } catch (error) { notifications.error(`Failed to save user group`) diff --git a/packages/builder/src/stores/portal/groups.js b/packages/builder/src/stores/portal/groups.js index 8d9f6fa132..74bfcccacf 100644 --- a/packages/builder/src/stores/portal/groups.js +++ b/packages/builder/src/stores/portal/groups.js @@ -28,6 +28,7 @@ export function createGroupsStore() { } return state }) + return group }, delete: async group => { From 095bb83202d44f1dbb5405089db749bdc9dcb70e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 13:25:44 +0100 Subject: [PATCH 007/155] Fix adding/removing users to group. Remove add all button --- .../settings/UserGroupPicker.svelte | 140 +++++++++++------- .../portal/manage/groups/[groupId].svelte | 98 +++++------- 2 files changed, 122 insertions(+), 116 deletions(-) diff --git a/packages/builder/src/components/settings/UserGroupPicker.svelte b/packages/builder/src/components/settings/UserGroupPicker.svelte index 6eef15efe6..67b970d1bf 100644 --- a/packages/builder/src/components/settings/UserGroupPicker.svelte +++ b/packages/builder/src/components/settings/UserGroupPicker.svelte @@ -1,75 +1,109 @@ -
- -
-
- {filtered.length} {title}{filtered.length === 1 ? "" : "s"} +
+ +
+
-
- Add all -
-
- -
- {#each filtered as item} -
{ - select(item._id) - }} - style="padding-bottom: var(--spacing-m)" - class="selection" - > -
- {item[key]} -
- - {#if selected.includes(item._id)} -
- + +
+ {#each sortedList as item} +
{ + dispatch(item.selected ? "deselect" : "select", item._id) + }} + class="item" + > +
+ {item[labelKey]}
- {/if} -
- {/each} -
+ {#if item.selected} +
+ +
+ {/if} +
+ {/each} +
+
diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 962fed800a..948e77a66e 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -31,7 +31,6 @@ let popoverAnchor let popover let searchTerm = "" - let selectedUsers = [] let prevSearch = undefined let pageInfo = createPaginationStore() let loaded = false @@ -41,9 +40,7 @@ $: page = $pageInfo.page $: fetchUsers(page, searchTerm) $: group = $groups.find(x => x._id === groupId) - $: filtered = - $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) || - [] + $: filtered = $users.data $: groupApps = $apps.filter(x => group?.apps.includes(x.appId)) $: { if (loaded && !group?._id) { @@ -51,53 +48,24 @@ } } - async function addAll() { - selectedUsers = [...selectedUsers, ...filtered.map(u => u._id)] - - let reducedUserObjects = filtered.map(u => { - return { - _id: u._id, - email: u.email, - } - }) - group.users = [...reducedUserObjects, ...group.users] - - await groups.actions.save(group) - - $users.data.forEach(async user => { - let userToEdit = await users.get(user._id) - let userGroups = userToEdit.userGroups || [] - userGroups.push(groupId) - await users.save({ - ...userToEdit, - userGroups, - }) - }) - } - - async function selectUser(id) { - let selectedUser = selectedUsers.includes(id) - if (selectedUser) { - selectedUsers = selectedUsers.filter(id => id !== selectedUser) - let newUsers = group.users.filter(user => user._id !== id) - group.users = newUsers - } else { - let enrichedUser = $users.data - .filter(user => user._id === id) - .map(u => { - return { - _id: u._id, - email: u.email, - } - })[0] - selectedUsers = [...selectedUsers, id] - group.users.push(enrichedUser) + const adduserToGroup = async id => { + const user = await users.get(id) + if (!user?._id) { + return } - await groups.actions.save(group) + // Check we haven't already been added + if (group.users?.find(x => x._id === user._id)) { + return + } - let user = await users.get(id) + // Update group + await groups.actions.save({ + ...group, + users: [...group.users, { _id: user._id, email: user.email }], + }) + // Update user let userGroups = user.userGroups || [] userGroups.push(groupId) await users.save({ @@ -106,17 +74,23 @@ }) } - async function removeUser(id) { - let newUsers = group.users.filter(user => user._id !== id) - group.users = newUsers - let user = await users.get(id) + const removeUserFromGroup = async id => { + const user = await users.get(id) + if (!user?._id) { + return + } - await users.save({ - ...user, - userGroups: [], + // Update group + await groups.actions.save({ + ...group, + users: group.users.filter(x => x._id !== id), }) - await groups.actions.save(group) + // Update user + await users.save({ + ...user, + userGroups: user.userGroups.filter(x => x !== groupId), + }) } async function fetchUsers(page, search) { @@ -150,7 +124,6 @@ notifications.success("User group deleted successfully") $goto("./") } catch (error) { - console.log(error) notifications.error(`Failed to delete user group`) } } @@ -216,13 +189,12 @@
adduserToGroup(e.detail)} + on:deselect={e => removeUserFromGroup(e.detail)} />
@@ -236,7 +208,7 @@ hoverable > removeUser(user._id)} + on:click={() => removeUserFromGroup(user._id)} hoverable size="S" name="Close" From 23194c91f18581182c720c7e10b86dbc873dd19d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 13:27:44 +0100 Subject: [PATCH 008/155] Fix click propagation in group user list --- packages/backend-core/src/environment.ts | 2 +- .../src/pages/builder/portal/manage/groups/[groupId].svelte | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index 37804b31a6..563d9a9243 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -43,7 +43,7 @@ const env = { PLATFORM_URL: process.env.PLATFORM_URL || "", POSTHOG_TOKEN: process.env.POSTHOG_TOKEN, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, - TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS, + TENANT_FEATURE_FLAGS: "default:USER_GROUPS", BACKUPS_BUCKET_NAME: process.env.BACKUPS_BUCKET_NAME || "backups", APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || "prod-budi-app-assets", TEMPLATES_BUCKET_NAME: process.env.TEMPLATES_BUCKET_NAME || "templates", diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 948e77a66e..45bd8ed1b4 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -208,7 +208,10 @@ hoverable > removeUserFromGroup(user._id)} + on:click={e => { + removeUserFromGroup(user._id) + e.stopPropagation() + }} hoverable size="S" name="Close" From 7e506fd60122ffcdf1385d930c8cb814e84c9c6f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 15:32:26 +0100 Subject: [PATCH 009/155] Revert env changes --- packages/backend-core/src/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index 563d9a9243..37804b31a6 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -43,7 +43,7 @@ const env = { PLATFORM_URL: process.env.PLATFORM_URL || "", POSTHOG_TOKEN: process.env.POSTHOG_TOKEN, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, - TENANT_FEATURE_FLAGS: "default:USER_GROUPS", + TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS, BACKUPS_BUCKET_NAME: process.env.BACKUPS_BUCKET_NAME || "backups", APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || "prod-budi-app-assets", TEMPLATES_BUCKET_NAME: process.env.TEMPLATES_BUCKET_NAME || "templates", From ea6356147b70e338def8462f13c4cbe22ecef582 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 15:32:51 +0100 Subject: [PATCH 010/155] Fix access filter not working --- .../pages/builder/portal/apps/_components/AcessFilter.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte b/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte index a75ed7c4de..61e9609cc3 100644 --- a/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte +++ b/packages/builder/src/pages/builder/portal/apps/_components/AcessFilter.svelte @@ -22,7 +22,7 @@ if (!detail) return const groupSelected = $groups.find(x => x._id === detail) - const appIds = groupSelected?.apps.map(x => x.appId) || null + const appIds = groupSelected?.apps || null dispatch("change", appIds) } From f5f510a482424a18f0e2e02d2828093ac3dcb637 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 15:33:51 +0100 Subject: [PATCH 011/155] Fix multiple issues in user details page --- .../settings/UserGroupPicker.svelte | 2 +- .../portal/manage/groups/[groupId].svelte | 53 +------ .../portal/manage/users/[userId].svelte | 139 ++++++++---------- packages/builder/src/stores/portal/groups.js | 55 ++++++- 4 files changed, 115 insertions(+), 134 deletions(-) diff --git a/packages/builder/src/components/settings/UserGroupPicker.svelte b/packages/builder/src/components/settings/UserGroupPicker.svelte index 67b970d1bf..3d49b8561d 100644 --- a/packages/builder/src/components/settings/UserGroupPicker.svelte +++ b/packages/builder/src/components/settings/UserGroupPicker.svelte @@ -16,7 +16,7 @@ return list.map(item => { return { ...item, - selected: selected.find(x => x._id === item._id) != null, + selected: selected.find(x => x === item._id) != null, } }) } diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index 45bd8ed1b4..8d7d9c927d 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -48,51 +48,6 @@ } } - const adduserToGroup = async id => { - const user = await users.get(id) - if (!user?._id) { - return - } - - // Check we haven't already been added - if (group.users?.find(x => x._id === user._id)) { - return - } - - // Update group - await groups.actions.save({ - ...group, - users: [...group.users, { _id: user._id, email: user.email }], - }) - - // Update user - let userGroups = user.userGroups || [] - userGroups.push(groupId) - await users.save({ - ...user, - userGroups, - }) - } - - const removeUserFromGroup = async id => { - const user = await users.get(id) - if (!user?._id) { - return - } - - // Update group - await groups.actions.save({ - ...group, - users: group.users.filter(x => x._id !== id), - }) - - // Update user - await users.save({ - ...user, - userGroups: user.userGroups.filter(x => x !== groupId), - }) - } - async function fetchUsers(page, search) { if ($pageInfo.loading) { return @@ -191,10 +146,10 @@ user._id)} list={$users.data} - on:select={e => adduserToGroup(e.detail)} - on:deselect={e => removeUserFromGroup(e.detail)} + on:select={e => groups.actions.addUser(groupId, e.detail)} + on:deselect={e => groups.actions.removeUser(groupId, e.detail)} />
@@ -209,7 +164,7 @@ > { - removeUserFromGroup(user._id) + groups.actions.removeUser(groupId, user._id) e.stopPropagation() }} hoverable diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 686223ff39..8ce83d93ad 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -22,7 +22,6 @@ StatusLight, } from "@budibase/bbui" import { onMount } from "svelte" - import { fetchData } from "helpers" import { users, auth, groups, apps } from "stores/portal" import { roles } from "stores/backend" import { Constants } from "@budibase/frontend-core" @@ -38,28 +37,23 @@ let popoverAnchor let searchTerm = "" let popover - let selectedGroups = [] let allAppList = [] let user let loaded = false - $: fetchUser(userId) - $: fullName = $userFetch?.data?.firstName - ? $userFetch?.data?.firstName + " " + $userFetch?.data?.lastName - : "" - $: nameLabel = getNameLabel($userFetch) + $: fullName = user?.firstName ? user?.firstName + " " + user?.lastName : "" + $: nameLabel = getNameLabel(user) $: initials = getInitials(nameLabel) + $: filteredGroups = getFilteredGroups($groups, searchTerm) $: allAppList = $apps .filter(x => { - if ($userFetch.data?.roles) { - return Object.keys($userFetch.data.roles).find(y => { - return x.appId === apps.extractAppId(y) - }) - } + return Object.keys(user?.roles || {}).find(y => { + return x.appId === apps.extractAppId(y) + }) }) .map(app => { let roles = Object.fromEntries( - Object.entries($userFetch.data.roles).filter(([key]) => { + Object.entries(user?.roles).filter(([key]) => { return apps.extractAppId(key) === app.appId }) ) @@ -70,27 +64,27 @@ roles, } }) - // Used for searching through groups in the add group popover - $: filteredGroups = $groups.filter( - group => - selectedGroups && - group?.name?.toLowerCase().includes(searchTerm.toLowerCase()) - ) $: userGroups = $groups.filter(x => { return x.users?.find(y => { return y._id === userId }) }) - $: globalRole = $userFetch?.data?.admin?.global + $: globalRole = user?.admin?.global ? "admin" - : $userFetch?.data?.builder?.global + : user?.builder?.global ? "developer" : "appUser" - const userFetch = fetchData(`/api/global/users/${userId}`) + const getFilteredGroups = (groups, search) => { + if (!search) { + return groups + } + search = search.toLowerCase() + return groups.filter(group => group.name?.toLowerCase().includes(search)) + } - const getNameLabel = userFetch => { - const { firstName, lastName, email } = userFetch?.data || {} + const getNameLabel = user => { + const { firstName, lastName, email } = user || {} if (!firstName && !lastName) { return email || "" } @@ -136,24 +130,17 @@ } async function updateUserFirstName(evt) { try { - await users.save({ ...$userFetch?.data, firstName: evt.target.value }) - await userFetch.refresh() + await users.save({ ...user, firstName: evt.target.value }) + await fetchUser() } catch (error) { notifications.error("Error updating user") } } - async function removeGroup(id) { - let updatedGroup = $groups.find(x => x._id === id) - let newUsers = updatedGroup.users.filter(user => user._id !== userId) - updatedGroup.users = newUsers - groups.actions.save(updatedGroup) - } - async function updateUserLastName(evt) { try { - await users.save({ ...$userFetch?.data, lastName: evt.target.value }) - await userFetch.refresh() + await users.save({ ...user, lastName: evt.target.value }) + await fetchUser() } catch (error) { notifications.error("Error updating user") } @@ -169,25 +156,8 @@ } } - async function addGroup(groupId) { - let selectedGroup = selectedGroups.includes(groupId) - let group = $groups.find(group => group._id === groupId) - - if (selectedGroup) { - selectedGroups = selectedGroups.filter(id => id === selectedGroup) - let newUsers = group.users.filter(groupUser => user._id !== groupUser._id) - group.users = newUsers - } else { - selectedGroups = [...selectedGroups, groupId] - group.users.push(user) - } - - await groups.actions.save(group) - } - - async function fetchUser(userId) { - let userPromise = users.get(userId) - user = await userPromise + async function fetchUser() { + user = await users.get(userId) if (!user?._id) { $goto("./") } @@ -195,17 +165,31 @@ async function toggleFlags(detail) { try { - await users.save({ ...$userFetch?.data, ...detail }) - await userFetch.refresh() + await users.save({ ...user, ...detail }) + await fetchUser() } catch (error) { notifications.error("Error updating user") } } - function addAll() {} + const addGroup = async groupId => { + await groups.actions.addUser(groupId, userId) + await fetchUser() + } + + const removeGroup = async groupId => { + await groups.actions.removeUser(groupId, userId) + await fetchUser() + } + onMount(async () => { try { - await Promise.all([groups.actions.init(), apps.load(), roles.fetch()]) + await Promise.all([ + fetchUser(), + groups.actions.init(), + apps.load(), + roles.fetch(), + ]) loaded = true } catch (error) { notifications.error("Error getting user groups") @@ -228,8 +212,8 @@
{nameLabel} - {#if nameLabel !== $userFetch?.data?.email} - {$userFetch?.data?.email} + {#if nameLabel !== user?.email} + {user?.email} {/if}
@@ -256,21 +240,15 @@
- +
- +
- +
{#if userId !== $auth.user._id} @@ -304,13 +282,12 @@
addGroup(e.detail)} + on:deselect={e => removeGroup(e.detail)} />
@@ -325,7 +302,10 @@ on:click={() => $goto(`../groups/${group._id}`)} > { + removeGroup(group._id) + e.stopPropagation() + }} hoverable size="S" name="Close" @@ -370,13 +350,10 @@ {/if} - + - + diff --git a/packages/bbui/src/List/ListItem.svelte b/packages/bbui/src/List/ListItem.svelte index c9e4e397e2..40d3c5541c 100644 --- a/packages/bbui/src/List/ListItem.svelte +++ b/packages/bbui/src/List/ListItem.svelte @@ -1,11 +1,12 @@ -
- -
- - + diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 19e0321b5b..6c7f27aec8 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -29,6 +29,7 @@ import { RoleUtils } from "@budibase/frontend-core" import UserGroupPicker from "components/settings/UserGroupPicker.svelte" import DeleteUserModal from "./_components/DeleteUserModal.svelte" + import GroupIcon from "../groups/_components/GroupIcon.svelte" export let userId @@ -207,7 +208,7 @@
- {#if userId !== $auth.user._id} + {#if userId !== $auth.user?._id}
@@ -277,6 +278,8 @@ selected={user.userGroups} on:select={e => addGroup(e.detail)} on:deselect={e => removeGroup(e.detail)} + iconComponent={GroupIcon} + extractIconProps={item => ({ group: item, size: "S" })} />
@@ -320,7 +323,7 @@ {#each availableApps as app} $goto(`../../overview/${app.devId}`)} From 0b04dc51720832d15fb78ede8ca330dcf4a16ff6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 5 Aug 2022 10:37:35 +0100 Subject: [PATCH 015/155] Use core icon component for app rows --- packages/bbui/src/Icon/IconAvatar.svelte | 4 ++-- packages/builder/src/components/start/AppRow.svelte | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/bbui/src/Icon/IconAvatar.svelte b/packages/bbui/src/Icon/IconAvatar.svelte index 8ae2774dbb..b404cdea9f 100644 --- a/packages/bbui/src/Icon/IconAvatar.svelte +++ b/packages/bbui/src/Icon/IconAvatar.svelte @@ -24,8 +24,8 @@ border-radius: 50%; } .icon :global(.spectrum-Icon) { - width: 20px; - height: 20px; + width: 22px; + height: 22px; } .icon.filled :global(.spectrum-Icon) { width: 16px; diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index 49f99c9f77..f6f9f70975 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -1,5 +1,5 @@
$goto(`./${detail._id}`)} - {schema} - bind:selectedRows - data={enrichedUsers} - allowEditColumns={false} - allowEditRows={false} - allowSelectRows={true} - showHeaderBorder={false} - {customRenderers} - /> - - + + +{/if} @@ -272,11 +281,11 @@ title="Invites sent!" confirmText="Done" > - Your users should now recieve an email invite to get access to their - Budibase account + + Your users should now recieve an email invite to get access to their + Budibase account + + diff --git a/packages/frontend-core/src/fetch/DataFetch.js b/packages/frontend-core/src/fetch/DataFetch.js index 338e6e0405..e875219e88 100644 --- a/packages/frontend-core/src/fetch/DataFetch.js +++ b/packages/frontend-core/src/fetch/DataFetch.js @@ -158,6 +158,8 @@ export default class DataFetch { schema, query, loading: true, + cursors: [], + cursor: null, })) // Actually fetch data diff --git a/packages/frontend-core/src/fetch/UserFetch.js b/packages/frontend-core/src/fetch/UserFetch.js new file mode 100644 index 0000000000..3bd0cdbaa4 --- /dev/null +++ b/packages/frontend-core/src/fetch/UserFetch.js @@ -0,0 +1,46 @@ +import { get } from "svelte/store" +import DataFetch from "./DataFetch.js" +import { TableNames } from "../constants" + +export default class UserFetch extends DataFetch { + constructor(opts) { + super({ + ...opts, + datasource: { + tableId: TableNames.USERS, + }, + }) + } + + determineFeatureFlags() { + return { + supportsSearch: true, + supportsSort: false, + supportsPagination: true, + } + } + + async getData() { + const { cursor, query } = get(this.store) + try { + // "query" normally contains a lucene query, but users uses a non-standard + // search endpoint so we use query uniquely here + const res = await this.API.searchUsers({ + page: cursor, + email: query.email, + appId: query.appId, + }) + return { + rows: res?.data || [], + hasNextPage: res?.hasNextPage || false, + cursor: res?.nextPage || null, + } + } catch (error) { + return { + rows: [], + hasNextPage: false, + error, + } + } + } +} diff --git a/packages/frontend-core/src/fetch/fetchData.js b/packages/frontend-core/src/fetch/fetchData.js index e914ff863f..4974816496 100644 --- a/packages/frontend-core/src/fetch/fetchData.js +++ b/packages/frontend-core/src/fetch/fetchData.js @@ -5,12 +5,14 @@ import RelationshipFetch from "./RelationshipFetch.js" import NestedProviderFetch from "./NestedProviderFetch.js" import FieldFetch from "./FieldFetch.js" import JSONArrayFetch from "./JSONArrayFetch.js" +import UserFetch from "./UserFetch.js" const DataFetchMap = { table: TableFetch, view: ViewFetch, query: QueryFetch, link: RelationshipFetch, + user: UserFetch, // Client specific datasource types provider: NestedProviderFetch, diff --git a/packages/frontend-core/src/utils/utils.js b/packages/frontend-core/src/utils/utils.js index 71688981a9..c31b3d5111 100644 --- a/packages/frontend-core/src/utils/utils.js +++ b/packages/frontend-core/src/utils/utils.js @@ -19,3 +19,25 @@ export const sequential = fn => { } } } + +/** + * Utility to debounce an async function and ensure a minimum delay between + * invocations is enforced. + * @param callback an async function to run + * @param minDelay the minimum delay between invocations + * @returns {Promise} a debounced version of the callback + */ +export const debounce = (callback, minDelay = 1000) => { + let timeout + return async (...params) => { + return new Promise(resolve => { + if (timeout) { + clearTimeout(timeout) + } + timeout = setTimeout(async () => { + console.log("timeout reached!") + resolve(await callback(...params)) + }, minDelay) + }) + } +} From 8f63abe9236edaf65f2fdce67cab7d4f1a1cdf71 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 8 Aug 2022 11:39:32 +0100 Subject: [PATCH 023/155] Show that admins and builders can access all apps --- .../builder/portal/manage/users/[userId].svelte | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 6c7f27aec8..59059663b9 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -19,6 +19,7 @@ Modal, notifications, Divider, + Banner, StatusLight, } from "@budibase/bbui" import { onMount } from "svelte" @@ -312,14 +313,13 @@ {/if} -
- Apps - {#if privileged} - This user's role grants admin access to all apps - {/if} -
+ Apps - {#if availableApps.length} + {#if privileged} + + This user's role grants admin access to all apps + + {:else if availableApps.length} {#each availableApps as app} Date: Mon, 8 Aug 2022 11:40:13 +0100 Subject: [PATCH 024/155] Prevent rendering overview until selected app has loaded --- .../overview/[application]/index.svelte | 297 +++++++++--------- 1 file changed, 151 insertions(+), 146 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/overview/[application]/index.svelte b/packages/builder/src/pages/builder/portal/overview/[application]/index.svelte index 0de8fd95ce..58e22ae330 100644 --- a/packages/builder/src/pages/builder/portal/overview/[application]/index.svelte +++ b/packages/builder/src/pages/builder/portal/overview/[application]/index.svelte @@ -206,159 +206,164 @@ }) - - - {#await promise} -
- -
- {:then _} - - - - Back - - -
-
- -
- +
+
+ +
+
+ {#if licenseInfo?.licenseKey} + + {/if} +
@@ -152,4 +181,10 @@ grid-gap: var(--spacing-l); align-items: center; } + .action-button { + margin-right: 10px; + } + .button-container { + display: flex; + } diff --git a/packages/frontend-core/src/api/licensing.js b/packages/frontend-core/src/api/licensing.js index 16d65a20d7..c27d79d740 100644 --- a/packages/frontend-core/src/api/licensing.js +++ b/packages/frontend-core/src/api/licensing.js @@ -9,6 +9,15 @@ export const buildLicensingEndpoints = API => ({ }) }, + /** + * Delete a self hosted license key + */ + deleteLicenseKey: async () => { + return API.delete({ + url: `/api/global/license/info`, + }) + }, + /** * Get the license info - metadata about the license including the * obfuscated license key. diff --git a/packages/worker/src/api/controllers/global/license.ts b/packages/worker/src/api/controllers/global/license.ts index 1e5ca9beac..2bd173010f 100644 --- a/packages/worker/src/api/controllers/global/license.ts +++ b/packages/worker/src/api/controllers/global/license.ts @@ -24,6 +24,11 @@ export const getInfo = async (ctx: any) => { ctx.status = 200 } +export const deleteInfo = async (ctx: any) => { + await licensing.deleteLicenseInfo() + ctx.status = 200 +} + export const getQuotaUsage = async (ctx: any) => { ctx.body = await quotas.getQuotaUsage() } diff --git a/packages/worker/src/api/routes/global/license.ts b/packages/worker/src/api/routes/global/license.ts index b9f5aa3218..03908e052b 100644 --- a/packages/worker/src/api/routes/global/license.ts +++ b/packages/worker/src/api/routes/global/license.ts @@ -7,6 +7,7 @@ router .post("/api/global/license/activate", controller.activate) .post("/api/global/license/refresh", controller.refresh) .get("/api/global/license/info", controller.getInfo) + .delete("/api/global/license/info", controller.deleteInfo) .get("/api/global/license/usage", controller.getQuotaUsage) export = router From 9539b5fc355233cda2f5f9a0aa83e1975e81032b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Sep 2022 15:57:57 +0100 Subject: [PATCH 118/155] Update nord color overrides --- packages/frontend-core/src/themes/nord.css | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/frontend-core/src/themes/nord.css b/packages/frontend-core/src/themes/nord.css index c5a9b13640..11c7a3aea1 100644 --- a/packages/frontend-core/src/themes/nord.css +++ b/packages/frontend-core/src/themes/nord.css @@ -28,6 +28,7 @@ --spectrum-global-color-static-blue-600: #5680b4; --spectrum-global-color-static-blue-700: #4e79af; --spectrum-global-color-static-blue-800: #4a73a6; + --spectrum-global-color-static-blue: var(--spectrum-global-color-blue-600); --spectrum-global-color-gray-50: #2e3440; --spectrum-global-color-gray-75: #353b4a; From 39a3a478b7dd9f6ff7be9ef403220c3439244995 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Sep 2022 16:10:40 +0100 Subject: [PATCH 119/155] Make portal text consistent and hide upgrade prompts when you already have access --- .../builder/portal/manage/groups/index.svelte | 11 ++++++----- .../builder/portal/manage/plugins/index.svelte | 2 +- .../pages/builder/portal/manage/users/index.svelte | 3 +-- .../pages/builder/portal/settings/upgrade.svelte | 14 ++++++-------- .../src/pages/builder/portal/settings/usage.svelte | 8 ++++---- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte index 1eb4f63089..71149f6b76 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -99,10 +99,12 @@
{/if} - Easily assign and manage your users' access with user groups - {#if !$auth.accountPortalAccess} - Contact your account holder to upgrade - {/if} + + Easily assign and manage your users' access with user groups. + {#if !$auth.accountPortalAccess && !$licensing.groupsEnabled} + Contact your account holder to upgrade your plan. + {/if} +
@@ -147,7 +149,6 @@ data={filteredGroups} allowEditColumns={false} allowEditRows={false} - showHeaderBorder={false} {customRenderers} /> diff --git a/packages/builder/src/pages/builder/portal/manage/plugins/index.svelte b/packages/builder/src/pages/builder/portal/manage/plugins/index.svelte index c03232d091..b1f2480c28 100644 --- a/packages/builder/src/pages/builder/portal/manage/plugins/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/plugins/index.svelte @@ -45,7 +45,7 @@ Plugins - Add your own custom datasources and components + Add your own custom datasources and components. diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index 68bd44857c..24954e025a 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -213,7 +213,7 @@ Users - Add users and control who gets access to your published apps + Add users and control who gets access to your published apps.
@@ -254,7 +254,6 @@ allowEditColumns={false} allowEditRows={false} allowSelectRows={true} - showHeaderBorder={false} {customRenderers} />