user screen update
This commit is contained in:
parent
3de2123dc4
commit
15f725b4d2
|
@ -27,11 +27,9 @@
|
||||||
import { users, auth, groups, apps } from "stores/portal"
|
import { users, auth, groups, apps } from "stores/portal"
|
||||||
import { roles } from "stores/backend"
|
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"
|
||||||
import UserGroupPicker from "components/settings/UserGroupPicker.svelte"
|
import UserGroupPicker from "components/settings/UserGroupPicker.svelte"
|
||||||
|
|
||||||
export let userId
|
export let userId
|
||||||
let deleteUserModal
|
let deleteUserModal
|
||||||
let resetPasswordModal
|
let resetPasswordModal
|
||||||
|
@ -40,9 +38,7 @@
|
||||||
let popover
|
let popover
|
||||||
let selectedGroups = []
|
let selectedGroups = []
|
||||||
let allAppList = []
|
let allAppList = []
|
||||||
$: console.log($apps)
|
let toggleDisabled = false
|
||||||
$: console.log($userFetch.data)
|
|
||||||
|
|
||||||
$: allAppList = $apps
|
$: allAppList = $apps
|
||||||
.filter(x => {
|
.filter(x => {
|
||||||
if ($userFetch.data?.roles) {
|
if ($userFetch.data?.roles) {
|
||||||
|
@ -52,15 +48,18 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(app => {
|
.map(app => {
|
||||||
let roles = Object.keys($userFetch.data.roles).filter(id => {
|
let roles = Object.fromEntries(
|
||||||
return id === app.appId
|
Object.entries($userFetch.data.roles).filter(
|
||||||
})
|
([key]) => key === app.appId
|
||||||
|
)
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
...app,
|
name: app.name,
|
||||||
|
devId: app.devId,
|
||||||
|
icon: app.icon,
|
||||||
roles,
|
roles,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$: console.log(allAppList)
|
|
||||||
// Used for searching through groups in the add group popover
|
// Used for searching through groups in the add group popover
|
||||||
$: filteredGroups = $groups.filter(
|
$: filteredGroups = $groups.filter(
|
||||||
group =>
|
group =>
|
||||||
|
@ -74,6 +73,12 @@
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$: globalRole = $userFetch?.data?.admin?.global
|
||||||
|
? "admin"
|
||||||
|
: $userFetch?.data?.builder?.global
|
||||||
|
? "developer"
|
||||||
|
: "appUser"
|
||||||
|
|
||||||
const userFetch = fetchData(`/api/global/users/${userId}`)
|
const userFetch = fetchData(`/api/global/users/${userId}`)
|
||||||
async function deleteUser() {
|
async function deleteUser() {
|
||||||
try {
|
try {
|
||||||
|
@ -88,10 +93,10 @@
|
||||||
function getHighestRole(roles) {
|
function getHighestRole(roles) {
|
||||||
let highestRole
|
let highestRole
|
||||||
let highestRoleNumber = 0
|
let highestRoleNumber = 0
|
||||||
roles.forEach(role => {
|
Object.keys(roles).forEach(role => {
|
||||||
let roleNumber = RoleUtils.getRolePriority(role._id)
|
let roleNumber = RoleUtils.getRolePriority(roles[role])
|
||||||
if (roleNumber > highestRoleNumber) {
|
if (roleNumber > highestRoleNumber) {
|
||||||
highestRole = role
|
highestRole = roles[role]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return highestRole
|
return highestRole
|
||||||
|
@ -121,8 +126,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateUserRole() {
|
async function updateUserRole({ detail }) {
|
||||||
return
|
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 addGroup(groupId) {
|
async function addGroup(groupId) {
|
||||||
|
@ -142,21 +153,14 @@
|
||||||
await groups.actions.save(group)
|
await groups.actions.save(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAll() {}
|
async function toggleFlags(detail) {
|
||||||
|
|
||||||
/*
|
|
||||||
async function toggleFlag(flagName, detail) {
|
|
||||||
toggleDisabled = true
|
|
||||||
try {
|
try {
|
||||||
await users.save({ ...$userFetch?.data, [flagName]: { global: detail } })
|
await users.save({ ...$userFetch?.data, ...detail })
|
||||||
await userFetch.refresh()
|
await userFetch.refresh()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error("Error updating user")
|
notifications.error("Error updating user")
|
||||||
}
|
}
|
||||||
toggleDisabled = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function toggleBuilderAccess({ detail }) {
|
async function toggleBuilderAccess({ detail }) {
|
||||||
return toggleFlag("builder", detail)
|
return toggleFlag("builder", detail)
|
||||||
}
|
}
|
||||||
|
@ -169,7 +173,8 @@
|
||||||
selectedApp = detail
|
selectedApp = detail
|
||||||
editRolesModal.show()
|
editRolesModal.show()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
function addAll() {}
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
try {
|
try {
|
||||||
await groups.actions.init()
|
await groups.actions.init()
|
||||||
|
@ -240,7 +245,11 @@
|
||||||
{#if userId !== $auth.user._id}
|
{#if userId !== $auth.user._id}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Role</Label>
|
<Label size="L">Role</Label>
|
||||||
<Select options={Constants.BbRoles} on:blur={updateUserRole} />
|
<Select
|
||||||
|
value={globalRole}
|
||||||
|
options={Constants.BbRoles}
|
||||||
|
on:change={updateUserRole}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -304,16 +313,20 @@
|
||||||
<List>
|
<List>
|
||||||
{#if allAppList.length}
|
{#if allAppList.length}
|
||||||
{#each allAppList as app}
|
{#each allAppList as app}
|
||||||
<div 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 || ""}
|
||||||
icon={app?.icon?.name || "Apps"}
|
icon={app?.icon?.name || "Apps"}
|
||||||
>
|
>
|
||||||
<div class="title ">
|
<div class="title ">
|
||||||
<StatusLight />
|
<StatusLight
|
||||||
|
color={RoleUtils.getRoleColour(getHighestRole(app.roles))}
|
||||||
|
/>
|
||||||
<div style="margin-left: var(--spacing-s);">
|
<div style="margin-left: var(--spacing-s);">
|
||||||
<Body size="XS">d</Body>
|
<Body size="XS"
|
||||||
|
>{Constants.Roles[getHighestRole(app.roles)]}</Body
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
@ -348,6 +361,9 @@
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.pointer {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
.fields {
|
.fields {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: var(--spacing-m);
|
grid-gap: var(--spacing-m);
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
<script>
|
<script>
|
||||||
import { Icon } from "@budibase/bbui"
|
import { Icon } from "@budibase/bbui"
|
||||||
export let value
|
export let value
|
||||||
|
$: console.log(value)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="align">
|
<div class="align">
|
||||||
<div class="spacing">
|
<div class="spacing">
|
||||||
<Icon name="Apps" />
|
<Icon name="WebPage" />
|
||||||
</div>
|
</div>
|
||||||
{#if value?.apps?.length === 0}
|
{parseInt(value?.length) || 0}
|
||||||
<div>
|
|
||||||
<div>No groups</div>
|
|
||||||
</div>
|
|
||||||
{:else if value?.apps?.length === 1}
|
|
||||||
{value?.groups[0]?.name}
|
|
||||||
{:else}
|
|
||||||
{parseInt(value?.apps?.length) || 0}
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -5,16 +5,18 @@
|
||||||
|
|
||||||
<div class="align">
|
<div class="align">
|
||||||
<div class="spacing">
|
<div class="spacing">
|
||||||
<Icon name="User" />
|
<Icon name="UserGroup" />
|
||||||
</div>
|
</div>
|
||||||
{#if value.length === 0}
|
{#if value.length === 0}
|
||||||
<div>0</div>
|
<div class="opacity">0</div>
|
||||||
{:else if value.length === 1}
|
{:else if value.length === 1}
|
||||||
<div class="opacity">
|
<div class="opacity">
|
||||||
<Body size="S">{value[0].name}</Body>
|
<Body size="S">{value[0].name}</Body>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{parseInt(value.length) || 0} groups
|
<div class="opacity">
|
||||||
|
{parseInt(value.length) || 0} groups
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -25,7 +27,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.opacity {
|
.opacity {
|
||||||
opacity: 0.7;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.spacing {
|
.spacing {
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
import PasswordModal from "./_components/PasswordModal.svelte"
|
import PasswordModal from "./_components/PasswordModal.svelte"
|
||||||
import ImportUsersModal from "./_components/ImportUsersModal.svelte"
|
import ImportUsersModal from "./_components/ImportUsersModal.svelte"
|
||||||
import analytics, { Events } from "analytics"
|
import analytics, { Events } from "analytics"
|
||||||
import TriggerAutomation from "../../../../../components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/TriggerAutomation.svelte"
|
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
name: {},
|
name: {},
|
||||||
|
@ -35,10 +34,10 @@
|
||||||
sortable: false,
|
sortable: false,
|
||||||
},
|
},
|
||||||
userGroups: { sortable: false, displayName: "User groups" },
|
userGroups: { sortable: false, displayName: "User groups" },
|
||||||
apps: {},
|
apps: { width: "120px" },
|
||||||
settings: {
|
settings: {
|
||||||
sortable: false,
|
sortable: false,
|
||||||
width: "50px",
|
width: "60px",
|
||||||
displayName: "",
|
displayName: "",
|
||||||
align: "Right",
|
align: "Right",
|
||||||
},
|
},
|
||||||
|
@ -81,11 +80,13 @@
|
||||||
|
|
||||||
$: enrichedUsers = $users.map(user => {
|
$: enrichedUsers = $users.map(user => {
|
||||||
let userGroups = []
|
let userGroups = []
|
||||||
|
let userApps = []
|
||||||
$groups.forEach(group => {
|
$groups.forEach(group => {
|
||||||
if (group.users) {
|
if (group.users) {
|
||||||
group.users?.forEach(y => {
|
group.users?.forEach(y => {
|
||||||
if (y._id === user._id) {
|
if (y._id === user._id) {
|
||||||
userGroups.push(group)
|
userGroups.push(group)
|
||||||
|
userApps = group.apps
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -94,6 +95,7 @@
|
||||||
...user,
|
...user,
|
||||||
name: user.firstName ? user.firstName + " " + user.lastName : "",
|
name: user.firstName ? user.firstName + " " + user.lastName : "",
|
||||||
userGroups,
|
userGroups,
|
||||||
|
apps: [...new Set(Object.keys(user.roles))],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
let appUsers = []
|
let appUsers = []
|
||||||
|
|
||||||
$: appUsers = $users.filter(x => {
|
$: appUsers = $users.filter(x => {
|
||||||
return Object.keys(x.roles).some(y => {
|
return Object.keys(x.roles).find(y => {
|
||||||
return extractAppId(y) === extractAppId(app.appId)
|
return extractAppId(y) === extractAppId(app.appId)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
|
|
||||||
let newUser = {
|
let newUser = {
|
||||||
...matchedUser,
|
...matchedUser,
|
||||||
roles: { [app.appId]: data.role },
|
roles: { [app.appId]: data.role, ...matchedUser.roles },
|
||||||
}
|
}
|
||||||
|
|
||||||
await users.save(newUser)
|
await users.save(newUser)
|
||||||
|
|
Loading…
Reference in New Issue