update groups doc to take a roles object

This commit is contained in:
Peter Clement 2022-07-14 16:58:32 +01:00
parent f253803dc2
commit e63c7fd56f
6 changed files with 27 additions and 19 deletions

View File

@ -14,7 +14,6 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import ConfigChecklist from "components/common/ConfigChecklist.svelte" import ConfigChecklist from "components/common/ConfigChecklist.svelte"
import { organisation, auth } from "stores/portal" import { organisation, auth } from "stores/portal"
import { roles } from "stores/backend"
import { admin as adminStore } from "stores/portal" import { admin as adminStore } from "stores/portal"
import { onMount } from "svelte" import { onMount } from "svelte"
import UpdateUserInfoModal from "components/settings/UpdateUserInfoModal.svelte" import UpdateUserInfoModal from "components/settings/UpdateUserInfoModal.svelte"
@ -126,7 +125,6 @@
$redirect("../") $redirect("../")
} else { } else {
try { try {
await roles.fetch()
await organisation.init() await organisation.init()
} catch (error) { } catch (error) {
notifications.error("Error getting org config") notifications.error("Error getting org config")

View File

@ -50,6 +50,15 @@
} }
await groups.actions.save(group) await groups.actions.save(group)
let user = await users.get(id)
let userGroups = user.groups || []
userGroups.push(groupId)
await users.save({
...user,
userGroups,
})
} }
$: filtered = $: filtered =
$users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) || $users.data?.filter(x => !group?.users.map(y => y._id).includes(x._id)) ||

View File

@ -24,6 +24,7 @@
color: "var(--spectrum-global-color-blue-600)", color: "var(--spectrum-global-color-blue-600)",
users: [], users: [],
apps: [], apps: [],
roles: {},
} }
async function deleteGroup(group) { async function deleteGroup(group) {

View File

@ -17,9 +17,9 @@
import AssignmentModal from "./AssignmentModal.svelte" import AssignmentModal from "./AssignmentModal.svelte"
import { createPaginationStore } from "helpers/pagination" import { createPaginationStore } from "helpers/pagination"
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import { roles } from "stores/backend"
export let app export let app
let assignmentModal let assignmentModal
let appGroups = [] let appGroups = []
let appUsers = [] let appUsers = []
@ -31,11 +31,11 @@
$: fetchUsers(page, search) $: fetchUsers(page, search)
$: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE $: isProPlan = $auth.user?.license.plan.type !== Constants.PlanType.FREE
$: console.log(isProPlan) $: console.log($users.data)
$: appUsers = $: appUsers =
$users.data?.filter(x => { $users.data?.filter(x => {
return Object.keys(x.roles).find(y => { 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) { async function addData(appData) {
let gr_prefix = "gr" let gr_prefix = "gr"
let us_prefix = "us" let us_prefix = "us"
console.log(appData)
appData.forEach(async data => { appData.forEach(async data => {
if (data.id.startsWith(gr_prefix)) { if (data.id.startsWith(gr_prefix)) {
let matchedGroup = $groups.find(group => { let matchedGroup = $groups.find(group => {
return group._id === data.id return group._id === data.id
}) })
matchedGroup.apps.push(app) matchedGroup.apps.push(app)
matchedGroup.roles[app.prodId] = data.role
groups.actions.save(matchedGroup) groups.actions.save(matchedGroup)
} else if (data.id.startsWith(us_prefix)) { } else if (data.id.startsWith(us_prefix)) {
@ -68,23 +65,23 @@
let newUser = { let newUser = {
...matchedUser, ...matchedUser,
roles: { [app.appId]: data.role, ...matchedUser.roles }, roles: { [app.prodId]: data.role, ...matchedUser.roles },
} }
await users.save(newUser) await users.save(newUser)
} }
}) })
await groups.actions.init() await groups.actions.init()
await users.search({ page, appId: app.appId }) await users.search({ page, appId: app.prodId })
} }
async function updateUserRole(role, user) { async function updateUserRole(role, user) {
user.roles[app.appId] = role user.roles[app.prodId] = role
users.save(user) users.save(user)
} }
async function updateGroupRole(role, group) { async function updateGroupRole(role, group) {
group.role = role group.roles[app.prodId] = role
groups.actions.save(group) groups.actions.save(group)
} }
@ -100,7 +97,7 @@
prevSearch = search prevSearch = search
try { try {
pageInfo.loading() pageInfo.loading()
await users.search({ page, appId: app.appId }) await users.search({ page, appId: app.prodId })
pageInfo.fetched($users.hasNextPage, $users.nextPage) pageInfo.fetched($users.hasNextPage, $users.nextPage)
} catch (error) { } catch (error) {
notifications.error("Error getting user list") notifications.error("Error getting user list")
@ -111,6 +108,7 @@
try { try {
await groups.actions.init() await groups.actions.init()
await apps.load() await apps.load()
await roles.fetch()
} catch (error) { } catch (error) {
notifications.error("Error") notifications.error("Error")
} }
@ -143,7 +141,9 @@
on:change={e => updateGroupRole(e.detail, group)} on:change={e => updateGroupRole(e.detail, group)}
autoWidth autoWidth
quiet quiet
value={group.role} value={group.roles[
Object.keys(group.roles).find(x => x === app.prodId)
]}
/> />
</ListItem> </ListItem>
{/each} {/each}
@ -158,9 +158,7 @@
autoWidth autoWidth
quiet quiet
value={user.roles[ value={user.roles[
Object.keys(user.roles).find( Object.keys(user.roles).find(x => x === app.prodId)
x => extractAppId(x) === extractAppId(app.appId)
)
]} ]}
/> />
</ListItem> </ListItem>

View File

@ -8,6 +8,7 @@ export function createGroupsStore() {
color: "", color: "",
users: [], users: [],
apps: [], apps: [],
roles: {},
} }
const store = writable([DEFAULT_CONFIG]) const store = writable([DEFAULT_CONFIG])

View File

@ -17,6 +17,7 @@ function buildGroupSaveValidation() {
role: Joi.string().optional(), role: Joi.string().optional(),
users: Joi.array().optional(), users: Joi.array().optional(),
apps: Joi.array().optional(), apps: Joi.array().optional(),
roles: Joi.object().optional(),
createdAt: Joi.string().optional(), createdAt: Joi.string().optional(),
updatedAt: Joi.string().optional(), updatedAt: Joi.string().optional(),
}).required()) }).required())