adds updateRoles method to users store

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-17 13:01:16 +02:00
parent 8e3bd36cc5
commit d70e336574
3 changed files with 27 additions and 27 deletions

View File

@ -25,21 +25,17 @@
const roleSchema = {
name: { displayName: "App" },
roles: { type: "options" },
role: { type: "options" },
}
// Here we need to merge the Apps list and the roles response to get something that makes sense for the table
$: appList = $apps.map(app => ({ ...app, roles: ["READ"] }))
$: appList = $apps.map(app => ({
...app,
role: $request?.data?.roles?.[app._id],
}))
let selectedApp
const request = fetchData(`/api/admin/users/${userId}`)
const roles = fetchData(
`/api/admin/roles/app_5a72d9b923504765852338e614a72c85`
)
$: console.log($apps)
$: console.log($roles)
async function deleteUser() {
const res = await users.del(userId)
@ -71,7 +67,6 @@
ut nesciunt ipsam perspiciatis aliquam et hic minus alias beatae. Odit
veritatis quos quas laborum magnam tenetur perspiciatis ex hic.
</Body>
{JSON.stringify($roles.data, null, 2)}
<Body />
</Layout>
</div>

View File

@ -1,20 +1,23 @@
<script>
import {
Body,
Multiselect,
ModalContent,
notifications,
} from "@budibase/bbui"
import { Body, Select, ModalContent, notifications } from "@budibase/bbui"
import { fetchData } from "helpers"
import { users } from "stores/portal"
export let app
export let user
let roles = app.roles
const options = ["READ", "WRITE", "ADMIN", "PUBLIC"]
const roles = fetchData(`/api/admin/roles/${app._id}`)
$: options = $roles?.data?.roles?.map(role => role._id)
let selectedRole
function updateUserRoles() {
users.updateRoles({ ...user, roles: { ...user.roles, [app._id]: roles } })
users.updateRoles({
...user,
roles: {
...user.roles,
[app._id]: selectedRole,
},
})
notifications.success("Roles updated")
}
</script>
@ -30,9 +33,9 @@
<Body noPadding
>Update {user.email}'s roles for <strong>{app.name}</strong>.</Body
>
<Multiselect
<Select
placeholder={null}
bind:value={roles}
bind:value={selectedRole}
on:change
{options}
label="Select roles:"

View File

@ -1,5 +1,5 @@
import { writable } from "svelte/store"
import api from "builderStore/api"
import api, { get } from "builderStore/api"
import { update } from "lodash"
export function createUsersStore() {
@ -41,11 +41,13 @@ export function createUsersStore() {
}
async function updateRoles(data) {
console.log(data)
// const res = await api.post(`/api/admin/users`, data)
// console.log(await res.json())
// update(users => (users.filter(user => user._id !== id)))
// return await response.json()
try {
const res = await post(`/api/admin/users`, data)
const json = await res.json()
return json
} catch (error) {
return error
}
}
return {