Update some other portal components to use new role metadata
This commit is contained in:
parent
8a7af78c48
commit
f6852d5331
|
@ -1,17 +1,17 @@
|
|||
<script>
|
||||
import { StatusLight } from "@budibase/bbui"
|
||||
import { RoleUtils, Constants } from "@budibase/frontend-core"
|
||||
import { Constants } from "@budibase/frontend-core"
|
||||
import { roles } from "stores/builder"
|
||||
import { capitalise } from "helpers"
|
||||
|
||||
export let value
|
||||
|
||||
$: role = $roles.find(x => x._id === roleId)
|
||||
$: role = $roles.find(x => x._id === value)
|
||||
|
||||
const getRoleLabel = roleId => {
|
||||
return roleId === Constants.Roles.CREATOR
|
||||
? capitalise(Constants.Roles.CREATOR.toLowerCase())
|
||||
: role?.name || "Custom role"
|
||||
: role?.displayName || role?.name || "Custom role"
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<script>
|
||||
import TagsTableRenderer from "./TagsTableRenderer.svelte"
|
||||
|
||||
export let value
|
||||
|
||||
$: roles = value?.filter(role => role != null).map(role => role.name) ?? []
|
||||
</script>
|
||||
|
||||
<TagsTableRenderer value={roles} />
|
|
@ -1,35 +0,0 @@
|
|||
<script>
|
||||
import { Tag, Tags } from "@budibase/bbui"
|
||||
|
||||
export let value
|
||||
|
||||
const displayLimit = 5
|
||||
|
||||
$: values = value?.filter(value => value != null) ?? []
|
||||
$: tags = values.slice(0, displayLimit)
|
||||
$: leftover = values.length - tags.length
|
||||
</script>
|
||||
|
||||
<div class="tag-renderer">
|
||||
<Tags>
|
||||
{#each tags as tag}
|
||||
<Tag>
|
||||
{tag}
|
||||
</Tag>
|
||||
{/each}
|
||||
{#if leftover}
|
||||
<Tag>+{leftover} more</Tag>
|
||||
{/if}
|
||||
</Tags>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tag-renderer :global(.spectrum-Tags-item:hover) {
|
||||
color: var(--spectrum-alias-label-text-color);
|
||||
border-color: var(--spectrum-alias-border-color-darker-default);
|
||||
cursor: pointer;
|
||||
}
|
||||
.tag-renderer :global(.spectrum-Tags-itemLabel) {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
|
@ -1,74 +0,0 @@
|
|||
<script>
|
||||
import { createEventDispatcher } from "svelte"
|
||||
import { Body, Select, ModalContent, notifications } from "@budibase/bbui"
|
||||
import { users } from "stores/portal"
|
||||
import { sdk } from "@budibase/shared-core"
|
||||
|
||||
export let app
|
||||
export let user
|
||||
|
||||
const NO_ACCESS = "NO_ACCESS"
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
const roles = app.roles
|
||||
let options = roles
|
||||
.filter(role => role._id !== "PUBLIC")
|
||||
.map(role => ({ value: role._id, label: role.name }))
|
||||
|
||||
if (!sdk.users.isBuilder(user, app?.appId)) {
|
||||
options.push({ value: NO_ACCESS, label: "No Access" })
|
||||
}
|
||||
let selectedRole = user?.roles?.[app?._id]
|
||||
|
||||
async function updateUserRoles() {
|
||||
try {
|
||||
if (selectedRole === NO_ACCESS) {
|
||||
// Remove the user role
|
||||
const filteredRoles = { ...user.roles }
|
||||
delete filteredRoles[app?._id]
|
||||
await users.save({
|
||||
...user,
|
||||
roles: {
|
||||
...filteredRoles,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// Add the user role
|
||||
await users.save({
|
||||
...user,
|
||||
roles: {
|
||||
...user.roles,
|
||||
[app._id]: selectedRole,
|
||||
},
|
||||
})
|
||||
}
|
||||
notifications.success("Role updated")
|
||||
dispatch("update")
|
||||
} catch (error) {
|
||||
notifications.error("Failed to update role")
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<ModalContent
|
||||
onConfirm={updateUserRoles}
|
||||
title="Update App Role"
|
||||
confirmText="Update role"
|
||||
cancelText="Cancel"
|
||||
size="M"
|
||||
showCloseIcon={false}
|
||||
>
|
||||
<Body>
|
||||
Update {user.email}'s role for <strong>{app.name}</strong>.
|
||||
</Body>
|
||||
<Select
|
||||
placeholder={null}
|
||||
bind:value={selectedRole}
|
||||
on:change
|
||||
{options}
|
||||
label="Role"
|
||||
getOptionLabel={role => role.label}
|
||||
getOptionValue={role => role.value}
|
||||
/>
|
||||
</ModalContent>
|
Loading…
Reference in New Issue