1
0
Fork 0
mirror of synced 2024-10-02 01:56:57 +13:00

update groups doc to take a roles object

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

View file

@ -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")

View file

@ -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)) ||

View file

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

View file

@ -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)
]}
/>
</ListItem>
{/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)
]}
/>
</ListItem>

View file

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

View file

@ -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())