adds updateRoles method to users store

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

View File

@ -25,21 +25,17 @@
const roleSchema = { const roleSchema = {
name: { displayName: "App" }, 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 // 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 let selectedApp
const request = fetchData(`/api/admin/users/${userId}`) const request = fetchData(`/api/admin/users/${userId}`)
const roles = fetchData(
`/api/admin/roles/app_5a72d9b923504765852338e614a72c85`
)
$: console.log($apps)
$: console.log($roles)
async function deleteUser() { async function deleteUser() {
const res = await users.del(userId) const res = await users.del(userId)
@ -71,7 +67,6 @@
ut nesciunt ipsam perspiciatis aliquam et hic minus alias beatae. Odit ut nesciunt ipsam perspiciatis aliquam et hic minus alias beatae. Odit
veritatis quos quas laborum magnam tenetur perspiciatis ex hic. veritatis quos quas laborum magnam tenetur perspiciatis ex hic.
</Body> </Body>
{JSON.stringify($roles.data, null, 2)}
<Body /> <Body />
</Layout> </Layout>
</div> </div>

View File

@ -1,20 +1,23 @@
<script> <script>
import { import { Body, Select, ModalContent, notifications } from "@budibase/bbui"
Body, import { fetchData } from "helpers"
Multiselect,
ModalContent,
notifications,
} from "@budibase/bbui"
import { users } from "stores/portal" import { users } from "stores/portal"
export let app export let app
export let user 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() { function updateUserRoles() {
users.updateRoles({ ...user, roles: { ...user.roles, [app._id]: roles } }) users.updateRoles({
...user,
roles: {
...user.roles,
[app._id]: selectedRole,
},
})
notifications.success("Roles updated") notifications.success("Roles updated")
} }
</script> </script>
@ -30,9 +33,9 @@
<Body noPadding <Body noPadding
>Update {user.email}'s roles for <strong>{app.name}</strong>.</Body >Update {user.email}'s roles for <strong>{app.name}</strong>.</Body
> >
<Multiselect <Select
placeholder={null} placeholder={null}
bind:value={roles} bind:value={selectedRole}
on:change on:change
{options} {options}
label="Select roles:" label="Select roles:"

View File

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