Merge pull request #7019 from Budibase/cheeks-fixes

User groups fixes
This commit is contained in:
Andrew Kingston 2022-08-01 15:52:51 +01:00 committed by GitHub
commit cefd36f928
11 changed files with 365 additions and 294 deletions

View File

@ -233,7 +233,10 @@
</div> </div>
{:else if getPrimaryOptionColour(option, idx)} {:else if getPrimaryOptionColour(option, idx)}
<span class="option-left"> <span class="option-left">
<StatusLight color={getPrimaryOptionColour(option, idx)} /> <StatusLight
square
color={getPrimaryOptionColour(option, idx)}
/>
</span> </span>
{/if} {/if}
<span class="spectrum-Menu-itemLabel"> <span class="spectrum-Menu-itemLabel">
@ -253,6 +256,7 @@
{#if getPrimaryOptionIcon(option, idx) && getPrimaryOptionColour(option, idx)} {#if getPrimaryOptionIcon(option, idx) && getPrimaryOptionColour(option, idx)}
<span class="option-right"> <span class="option-right">
<StatusLight <StatusLight
square
color={getPrimaryOptionColour(option, idx)} color={getPrimaryOptionColour(option, idx)}
/> />
</span> </span>
@ -281,7 +285,7 @@
</span> </span>
{:else if secondaryFieldColour} {:else if secondaryFieldColour}
<span class="option-left"> <span class="option-left">
<StatusLight color={secondaryFieldColour} /> <StatusLight square color={secondaryFieldColour} />
</span> </span>
{/if} {/if}
@ -319,6 +323,7 @@
{#if getSecondaryOptionColour(option, idx)} {#if getSecondaryOptionColour(option, idx)}
<span class="option-left"> <span class="option-left">
<StatusLight <StatusLight
square
color={getSecondaryOptionColour(option, idx)} color={getSecondaryOptionColour(option, idx)}
/> />
</span> </span>
@ -351,6 +356,13 @@
min-width: 0; min-width: 0;
width: 100%; width: 100%;
} }
.spectrum-InputGroup :global(.spectrum-Search-input) {
border: none;
border-bottom: 1px solid var(--spectrum-global-color-gray-300);
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.override-borders { .override-borders {
border-top-left-radius: 0px; border-top-left-radius: 0px;
border-bottom-left-radius: 0px; border-bottom-left-radius: 0px;

View File

@ -72,7 +72,7 @@
href: "/builder/portal/manage/groups", href: "/builder/portal/manage/groups",
} }
menu.splice(1, 0, item) menu.splice(2, 0, item)
} }
if (!$adminStore.cloud) { if (!$adminStore.cloud) {

View File

@ -18,23 +18,44 @@
import { users, apps, groups } from "stores/portal" import { users, apps, groups } from "stores/portal"
import { onMount } from "svelte" import { onMount } from "svelte"
import { RoleUtils } from "@budibase/frontend-core" import { RoleUtils } from "@budibase/frontend-core"
import { roles } from "stores/backend"
export let groupId export let groupId
let popoverAnchor let popoverAnchor
let popover let popover
let searchTerm = "" let searchTerm = ""
let selectedUsers = [] let selectedUsers = []
let prevSearch = undefined, let prevSearch = undefined
search = undefined
let pageInfo = createPaginationStore() let pageInfo = createPaginationStore()
let loaded = false
$: page = $pageInfo.page $: page = $pageInfo.page
$: fetchUsers(page, search) $: fetchUsers(page, searchTerm)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
async function addAll() { async function addAll() {
group.users = selectedUsers selectedUsers = [...selectedUsers, ...filtered.map(u => u._id)]
let reducedUserObjects = filtered.map(u => {
return {
_id: u._id,
email: u.email,
}
})
group.users = [...reducedUserObjects, ...group.users]
await groups.actions.save(group) await groups.actions.save(group)
$users.data.forEach(async user => {
let userToEdit = await users.get(user._id)
let userGroups = userToEdit.userGroups || []
userGroups.push(groupId)
await users.save({
...userToEdit,
userGroups,
})
})
} }
async function selectUser(id) { async function selectUser(id) {
@ -97,26 +118,37 @@
prevSearch = search prevSearch = search
try { try {
pageInfo.loading() pageInfo.loading()
await users.search({ page, search }) await users.search({ page, email: search })
pageInfo.fetched($users.hasNextPage, $users.nextPage) pageInfo.fetched($users.hasNextPage, $users.nextPage)
} catch (error) { } catch (error) {
notifications.error("Error getting user list") notifications.error("Error getting user list")
} }
} }
const getRoleLabel = appId => {
const roleId = group?.roles?.[`app_${appId}`]
const role = $roles.find(x => x._id === roleId)
return role?.name || "Custom role"
}
onMount(async () => { onMount(async () => {
try { try {
await groups.actions.init() await Promise.all([groups.actions.init(), apps.load(), roles.fetch()])
await apps.load() loaded = true
} catch (error) { } catch (error) {
notifications.error("Error fetching User Group data") notifications.error("Error fetching user group data")
} }
}) })
</script> </script>
{#if loaded}
<Layout noPadding> <Layout noPadding>
<div> <div>
<ActionButton on:click={() => $goto("../groups")} size="S" icon="ArrowLeft"> <ActionButton
on:click={() => $goto("../groups")}
size="S"
icon="ArrowLeft"
>
Back Back
</ActionButton> </ActionButton>
</div> </div>
@ -132,7 +164,7 @@
</div> </div>
</div> </div>
<div bind:this={popoverAnchor}> <div bind:this={popoverAnchor}>
<Button on:click={popover.show()} icon="UserAdd" cta>Add User</Button> <Button on:click={popover.show()} icon="UserAdd" cta>Add user</Button>
</div> </div>
<Popover align="right" bind:this={popover} anchor={popoverAnchor}> <Popover align="right" bind:this={popover} anchor={popoverAnchor}>
<UserGroupPicker <UserGroupPicker
@ -169,7 +201,8 @@
> >
<Heading weight="light" size="XS">Apps</Heading> <Heading weight="light" size="XS">Apps</Heading>
<div style="margin-top: var(--spacing-xs)"> <div style="margin-top: var(--spacing-xs)">
<Body size="S">Manage apps that this User group has been assigned to</Body <Body size="S"
>Manage apps that this User group has been assigned to</Body
> >
</div> </div>
</div> </div>
@ -184,11 +217,11 @@
> >
<div class="title "> <div class="title ">
<StatusLight <StatusLight
color={RoleUtils.getRoleColour(group.roles[app.appId])} square
/> color={RoleUtils.getRoleColour(group.roles[`app_${app.appId}`])}
<div style="margin-left: var(--spacing-s);"> >
<Body size="XS">{group.roles[app.appId]}</Body> {getRoleLabel(app.appId)}
</div> </StatusLight>
</div> </div>
</ListItem> </ListItem>
{/each} {/each}
@ -197,6 +230,7 @@
{/if} {/if}
</List> </List>
</Layout> </Layout>
{/if}
<style> <style>
.text-padding { .text-padding {

View File

@ -14,13 +14,9 @@
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte"
import UserGroupsRow from "./_components/UserGroupsRow.svelte" import UserGroupsRow from "./_components/UserGroupsRow.svelte"
import { cloneDeep } from "lodash/fp"
$: hasGroupsLicense = $auth.user?.license.features.includes( const DefaultGroup = {
Constants.Features.USER_GROUPS
)
let modal
let group = {
name: "", name: "",
icon: "UserGroup", icon: "UserGroup",
color: "var(--spectrum-global-color-blue-600)", color: "var(--spectrum-global-color-blue-600)",
@ -28,6 +24,12 @@
apps: [], apps: [],
roles: {}, roles: {},
} }
let modal
let group = cloneDeep(DefaultGroup)
$: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS
)
async function deleteGroup(group) { async function deleteGroup(group) {
try { try {
@ -45,6 +47,11 @@
} }
} }
const showCreateGroupModal = () => {
group = cloneDeep(DefaultGroup)
modal?.show()
}
onMount(async () => { onMount(async () => {
try { try {
if (hasGroupsLicense) { if (hasGroupsLicense) {
@ -78,10 +85,11 @@
icon={hasGroupsLicense ? "UserGroup" : ""} icon={hasGroupsLicense ? "UserGroup" : ""}
cta={hasGroupsLicense} cta={hasGroupsLicense}
on:click={hasGroupsLicense on:click={hasGroupsLicense
? () => modal.show() ? showCreateGroupModal
: window.open("https://budibase.com/pricing/", "_blank")} : window.open("https://budibase.com/pricing/", "_blank")}
>{hasGroupsLicense ? "Create user group" : "Upgrade Account"}</Button
> >
{hasGroupsLicense ? "Create user group" : "Upgrade Account"}
</Button>
{#if !hasGroupsLicense} {#if !hasGroupsLicense}
<Button <Button
newStyles newStyles
@ -130,7 +138,7 @@
.groupTable :global(> div) { .groupTable :global(> div) {
background: var(--bg-color); background: var(--bg-color);
height: 70px; height: 55px;
display: grid; display: grid;
align-items: center; align-items: center;
grid-gap: var(--spacing-xl); grid-gap: var(--spacing-xl);

View File

@ -21,9 +21,9 @@
StatusLight, StatusLight,
} from "@budibase/bbui" } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import { fetchData } from "helpers" import { fetchData } from "helpers"
import { users, auth, groups, apps } from "stores/portal" import { users, auth, groups, apps } from "stores/portal"
import { roles } from "stores/backend"
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import ForceResetPasswordModal from "./_components/ForceResetPasswordModal.svelte" import ForceResetPasswordModal from "./_components/ForceResetPasswordModal.svelte"
import { RoleUtils } from "@budibase/frontend-core" import { RoleUtils } from "@budibase/frontend-core"
@ -40,6 +40,7 @@
let selectedGroups = [] let selectedGroups = []
let allAppList = [] let allAppList = []
let user let user
let loaded = false
$: fetchUser(userId) $: fetchUser(userId)
$: fullName = $userFetch?.data?.firstName $: fullName = $userFetch?.data?.firstName
@ -49,6 +50,8 @@
$: hasGroupsLicense = $auth.user?.license.features.includes( $: hasGroupsLicense = $auth.user?.license.features.includes(
Constants.Features.USER_GROUPS Constants.Features.USER_GROUPS
) )
$: nameLabel = getNameLabel($userFetch)
$: initials = getInitials(nameLabel)
$: allAppList = $apps $: allAppList = $apps
.filter(x => { .filter(x => {
@ -91,6 +94,39 @@
const userFetch = fetchData(`/api/global/users/${userId}`) const userFetch = fetchData(`/api/global/users/${userId}`)
const getNameLabel = userFetch => {
const { firstName, lastName, email } = userFetch?.data || {}
if (!firstName && !lastName) {
return email || ""
}
let label
if (firstName) {
label = firstName
if (lastName) {
label += ` ${lastName}`
}
} else {
label = lastName
}
return label
}
const getInitials = nameLabel => {
if (!nameLabel) {
return "?"
}
return nameLabel
.split(" ")
.slice(0, 2)
.map(x => x[0])
.join("")
}
const getRoleLabel = roleId => {
const role = $roles.find(x => x._id === roleId)
return role?.name || "Custom role"
}
function getHighestRole(roles) { function getHighestRole(roles) {
let highestRole let highestRole
let highestRoleNumber = 0 let highestRoleNumber = 0
@ -171,14 +207,15 @@
function addAll() {} function addAll() {}
onMount(async () => { onMount(async () => {
try { try {
await groups.actions.init() await Promise.all([groups.actions.init(), apps.load(), roles.fetch()])
await apps.load() loaded = true
} catch (error) { } catch (error) {
notifications.error("Error getting User groups") notifications.error("Error getting user groups")
} }
}) })
</script> </script>
{#if loaded}
<Layout gap="L" noPadding> <Layout gap="L" noPadding>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<div> <div>
@ -191,27 +228,15 @@
<div class="title"> <div class="title">
<div> <div>
<div style="display: flex;"> <div style="display: flex;">
<Avatar <Avatar size="XXL" {initials} />
size="XXL"
initials={user?.email
.split(" ")
.map(x => x[0])
.join("")}
/>
{#if fullName}
<div class="subtitle"> <div class="subtitle">
<Heading size="S">{fullName}</Heading> <Heading size="S">{nameLabel}</Heading>
{#if nameLabel !== $userFetch?.data?.email}
<Body size="XS">{$userFetch?.data?.email}</Body> <Body size="XS">{$userFetch?.data?.email}</Body>
</div>
{:else}
<div class="alignEmail">
<Heading size="S">{$userFetch?.data?.email}</Heading>
</div>
{/if} {/if}
</div> </div>
</div> </div>
</div>
<div> <div>
<ActionMenu align="right"> <ActionMenu align="right">
<span slot="control"> <span slot="control">
@ -220,7 +245,8 @@
<MenuItem on:click={resetPasswordModal.show} icon="Refresh" <MenuItem on:click={resetPasswordModal.show} icon="Refresh"
>Force Password Reset</MenuItem >Force Password Reset</MenuItem
> >
<MenuItem on:click={deleteModal.show} icon="Delete">Delete</MenuItem> <MenuItem on:click={deleteModal.show} icon="Delete">Delete</MenuItem
>
</ActionMenu> </ActionMenu>
</div> </div>
</div> </div>
@ -266,9 +292,9 @@
<Body size="S">Add or remove this user from user groups</Body> <Body size="S">Add or remove this user from user groups</Body>
</div> </div>
<div bind:this={popoverAnchor}> <div bind:this={popoverAnchor}>
<Button on:click={popover.show()} icon="UserGroup" cta <Button on:click={popover.show()} icon="UserGroup" cta>
>Add User Group</Button Add user group
> </Button>
</div> </div>
<Popover align="right" bind:this={popover} anchor={popoverAnchor}> <Popover align="right" bind:this={popover} anchor={popoverAnchor}>
<UserGroupPicker <UserGroupPicker
@ -316,7 +342,10 @@
<List> <List>
{#if allAppList.length} {#if allAppList.length}
{#each allAppList as app} {#each allAppList as app}
<div class="pointer" on:click={$goto(`../../overview/${app.devId}`)}> <div
class="pointer"
on:click={$goto(`../../overview/${app.devId}`)}
>
<ListItem <ListItem
title={app.name} title={app.name}
iconBackground={app?.icon?.color || ""} iconBackground={app?.icon?.color || ""}
@ -324,13 +353,11 @@
> >
<div class="title "> <div class="title ">
<StatusLight <StatusLight
square
color={RoleUtils.getRoleColour(getHighestRole(app.roles))} color={RoleUtils.getRoleColour(getHighestRole(app.roles))}
/>
<div style="margin-left: var(--spacing-s);">
<Body size="XS"
>{Constants.Roles[getHighestRole(app.roles)]}</Body
> >
</div> {getRoleLabel(getHighestRole(app.roles))}
</StatusLight>
</div> </div>
</ListItem> </ListItem>
</div> </div>
@ -341,6 +368,7 @@
</List> </List>
</Layout> </Layout>
</Layout> </Layout>
{/if}
<Modal bind:this={deleteModal}> <Modal bind:this={deleteModal}>
<DeleteUserModal user={$userFetch.data} /> <DeleteUserModal user={$userFetch.data} />
@ -380,17 +408,14 @@
.subtitle { .subtitle {
padding: 0 0 0 var(--spacing-m); padding: 0 0 0 var(--spacing-m);
display: inline-block; display: flex;
flex-direction: column;
justify-content: center;
align-items: stretch;
} }
.appsTitle { .appsTitle {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.alignEmail {
display: flex;
align-items: center;
margin-left: var(--spacing-m);
}
</style> </style>

View File

@ -123,12 +123,7 @@
.fix-height { .fix-height {
margin-bottom: 5%; margin-bottom: 5%;
} }
.normal-height { .normal-height {
margin-bottom: 0%; margin-bottom: 0%;
} }
:global(.spectrum-Picker) {
border-top-left-radius: 0px;
}
</style> </style>

View File

@ -108,10 +108,6 @@
</ModalContent> </ModalContent>
<style> <style>
:global(.spectrum-Picker) {
border-top-left-radius: 0px;
}
.dropzone { .dropzone {
text-align: center; text-align: center;
display: flex; display: flex;

View File

@ -79,10 +79,6 @@
display: flex; display: flex;
} }
:global(.spectrum-Picker) {
border-top-left-radius: 0px;
}
.container { .container {
width: 100%; width: 100%;
height: var(--spectrum-alias-item-height-l); height: var(--spectrum-alias-item-height-l);

View File

@ -249,10 +249,10 @@
dataCy="add-user" dataCy="add-user"
on:click={createUserModal.show} on:click={createUserModal.show}
icon="UserAdd" icon="UserAdd"
cta>Add Users</Button cta>Add users</Button
> >
<Button on:click={importUsersModal.show} icon="Import" primary <Button on:click={importUsersModal.show} icon="Import" primary
>Import Users</Button >Import users</Button
> >
<div class="field"> <div class="field">

View File

@ -3,6 +3,7 @@
ModalContent, ModalContent,
PickerDropdown, PickerDropdown,
ActionButton, ActionButton,
Layout,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { roles } from "stores/backend" import { roles } from "stores/backend"
@ -38,9 +39,9 @@
} }
} }
$: filteredGroups = $groups.filter(element => { $: filteredGroups = $groups.filter(group => {
return !element.apps.find(y => { return !group.apps.find(appId => {
return y.appId === app.appId return appId === app.appId
}) })
}) })
@ -78,11 +79,13 @@
onConfirm={() => addData(appData)} onConfirm={() => addData(appData)}
showCloseIcon={false} showCloseIcon={false}
> >
<Layout noPadding gap="XS">
{#each appData as input, index} {#each appData as input, index}
<PickerDropdown <PickerDropdown
autocomplete autocomplete
primaryOptions={optionSections} primaryOptions={optionSections}
secondaryOptions={$roles} secondaryOptions={$roles}
secondaryPlaceholder="Access"
bind:primaryValue={input.id} bind:primaryValue={input.id}
bind:secondaryValue={input.role} bind:secondaryValue={input.role}
bind:searchTerm={search} bind:searchTerm={search}
@ -95,7 +98,7 @@
getSecondaryOptionColour={role => RoleUtils.getRoleColour(role._id)} getSecondaryOptionColour={role => RoleUtils.getRoleColour(role._id)}
/> />
{/each} {/each}
</Layout>
<div> <div>
<ActionButton on:click={addNewInput} icon="Add">Add email</ActionButton> <ActionButton on:click={addNewInput} icon="Add">Add email</ActionButton>
</div> </div>

View File

@ -5,7 +5,7 @@
import { store } from "builderStore" import { store } from "builderStore"
import clientPackage from "@budibase/client/package.json" import clientPackage from "@budibase/client/package.json"
import { processStringSync } from "@budibase/string-templates" import { processStringSync } from "@budibase/string-templates"
import { users, auth } from "stores/portal" import { users, auth, apps } from "stores/portal"
import { createEventDispatcher, onMount } from "svelte" import { createEventDispatcher, onMount } from "svelte"
export let app export let app
@ -40,9 +40,11 @@
} }
onMount(async () => { onMount(async () => {
let resp = await users.getUserCountByApp({ appId: "app_" + app.appId }) let resp = await users.getUserCountByApp({
appId: apps.getProdAppID(app.devId),
})
userCount = resp.userCount userCount = resp.userCount
await users.search({ appId: "app_" + app.appId, limit: 4 }) await users.search({ appId: apps.getProdAppID(app.devId), limit: 4 })
}) })
</script> </script>