From e63c7fd56f4bc970cbd346d573ab334d0877da55 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 14 Jul 2022 16:58:32 +0100 Subject: [PATCH] update groups doc to take a roles object --- .../src/pages/builder/portal/_layout.svelte | 2 -- .../portal/manage/groups/[groupId].svelte | 9 ++++++ .../builder/portal/manage/groups/index.svelte | 1 + .../overview/_components/AccessTab.svelte | 32 +++++++++---------- packages/builder/src/stores/portal/groups.js | 1 + .../worker/src/api/routes/global/groups.js | 1 + 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/_layout.svelte b/packages/builder/src/pages/builder/portal/_layout.svelte index 2ee16337f6..5da8b34700 100644 --- a/packages/builder/src/pages/builder/portal/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/_layout.svelte @@ -14,7 +14,6 @@ } from "@budibase/bbui" import ConfigChecklist from "components/common/ConfigChecklist.svelte" import { organisation, auth } from "stores/portal" - import { roles } from "stores/backend" import { admin as adminStore } from "stores/portal" import { onMount } from "svelte" import UpdateUserInfoModal from "components/settings/UpdateUserInfoModal.svelte" @@ -126,7 +125,6 @@ $redirect("../") } else { try { - await roles.fetch() await organisation.init() } catch (error) { notifications.error("Error getting org config") 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 c03ab55b29..efade705eb 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -50,6 +50,15 @@ } await groups.actions.save(group) + + let user = await users.get(id) + + let userGroups = user.groups || [] + userGroups.push(groupId) + await users.save({ + ...user, + userGroups, + }) } $: filtered = $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._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 49c3140e00..2dd80506a8 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/index.svelte @@ -24,6 +24,7 @@ color: "var(--spectrum-global-color-blue-600)", users: [], apps: [], + roles: {}, } async function deleteGroup(group) { diff --git a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte index fd423354e9..ddb6703c25 100644 --- a/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte +++ b/packages/builder/src/pages/builder/portal/overview/_components/AccessTab.svelte @@ -17,9 +17,9 @@ import AssignmentModal from "./AssignmentModal.svelte" import { createPaginationStore } from "helpers/pagination" import { Constants } from "@budibase/frontend-core" + import { roles } from "stores/backend" export let app - let assignmentModal let appGroups = [] let appUsers = [] @@ -31,11 +31,11 @@ $: fetchUsers(page, search) $: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE - $: console.log(isProPlan) + $: console.log($users.data) $: appUsers = $users.data?.filter(x => { return Object.keys(x.roles).find(y => { - return extractAppId(y) === extractAppId(app.appId) + return y === app.prodId }) }) || [] @@ -45,20 +45,17 @@ }) }) - function extractAppId(id) { - const split = id?.split("_") || [] - return split.length ? split[split.length - 1] : null - } - async function addData(appData) { let gr_prefix = "gr" let us_prefix = "us" + console.log(appData) appData.forEach(async data => { if (data.id.startsWith(gr_prefix)) { let matchedGroup = $groups.find(group => { return group._id === data.id }) matchedGroup.apps.push(app) + matchedGroup.roles[app.prodId] = data.role groups.actions.save(matchedGroup) } else if (data.id.startsWith(us_prefix)) { @@ -68,23 +65,23 @@ let newUser = { ...matchedUser, - roles: { [app.appId]: data.role, ...matchedUser.roles }, + roles: { [app.prodId]: data.role, ...matchedUser.roles }, } await users.save(newUser) } }) await groups.actions.init() - await users.search({ page, appId: app.appId }) + await users.search({ page, appId: app.prodId }) } async function updateUserRole(role, user) { - user.roles[app.appId] = role + user.roles[app.prodId] = role users.save(user) } async function updateGroupRole(role, group) { - group.role = role + group.roles[app.prodId] = role groups.actions.save(group) } @@ -100,7 +97,7 @@ prevSearch = search try { pageInfo.loading() - await users.search({ page, appId: app.appId }) + await users.search({ page, appId: app.prodId }) pageInfo.fetched($users.hasNextPage, $users.nextPage) } catch (error) { notifications.error("Error getting user list") @@ -111,6 +108,7 @@ try { await groups.actions.init() await apps.load() + await roles.fetch() } catch (error) { notifications.error("Error") } @@ -143,7 +141,9 @@ on:change={e => updateGroupRole(e.detail, group)} autoWidth quiet - value={group.role} + value={group.roles[ + Object.keys(group.roles).find(x => x === app.prodId) + ]} /> {/each} @@ -158,9 +158,7 @@ autoWidth quiet value={user.roles[ - Object.keys(user.roles).find( - x => extractAppId(x) === extractAppId(app.appId) - ) + Object.keys(user.roles).find(x => x === app.prodId) ]} /> diff --git a/packages/builder/src/stores/portal/groups.js b/packages/builder/src/stores/portal/groups.js index aae647651d..d2189cbabc 100644 --- a/packages/builder/src/stores/portal/groups.js +++ b/packages/builder/src/stores/portal/groups.js @@ -8,6 +8,7 @@ export function createGroupsStore() { color: "", users: [], apps: [], + roles: {}, } const store = writable([DEFAULT_CONFIG]) diff --git a/packages/worker/src/api/routes/global/groups.js b/packages/worker/src/api/routes/global/groups.js index 7e1e30b79c..2bbf1e5049 100644 --- a/packages/worker/src/api/routes/global/groups.js +++ b/packages/worker/src/api/routes/global/groups.js @@ -17,6 +17,7 @@ function buildGroupSaveValidation() { role: Joi.string().optional(), users: Joi.array().optional(), apps: Joi.array().optional(), + roles: Joi.object().optional(), createdAt: Joi.string().optional(), updatedAt: Joi.string().optional(), }).required())