changing user roles from users table

This commit is contained in:
NEOLPAR 2022-07-14 16:55:19 +01:00
parent 0fc78fdbf6
commit c8512e3de6
2 changed files with 33 additions and 7 deletions

View File

@ -1,15 +1,37 @@
<script> <script>
import { Select } from "@budibase/bbui" import { notifications, Select } from "@budibase/bbui"
import { users } from "stores/portal"
import { Constants } from "@budibase/frontend-core"
const options = [ export let row
{ label: "App User", value: "appUser" }, $: value = users.getUserRole(row)
{ label: "Developer", value: "developer" },
{ label: "Admin", value: "admin" }, async function updateUserRole({ detail }) {
] if (detail === "developer") {
toggleFlags({ admin: { global: false }, builder: { global: true } })
} else if (detail === "admin") {
toggleFlags({ admin: { global: true }, builder: { global: false } })
} else if (detail === "appUser") {
toggleFlags({ admin: { global: false }, builder: { global: false } })
}
}
async function toggleFlags(roleFlags) {
try {
await users.save({ ...(await users.get(row._id)), ...roleFlags })
} catch (error) {
notifications.error("Error updating user")
}
}
</script> </script>
<div on:click|stopPropagation> <div on:click|stopPropagation>
<Select value={"appUser"} {options} placeholder="Admin" autoWidth quiet /> <Select
{value}
options={Constants.BbRoles}
autoWidth
quiet
on:change={updateUserRole}
/>
</div> </div>
<style> <style>

View File

@ -86,10 +86,14 @@ export function createUsersStore() {
return await API.saveUser(user) return await API.saveUser(user)
} }
const getUserRole = ({ admin, builder }) =>
admin?.global ? "admin" : builder?.global ? "developer" : "appUser"
return { return {
subscribe, subscribe,
search, search,
get, get,
getUserRole,
fetch, fetch,
invite, invite,
acceptInvite, acceptInvite,