Show that admin and builder users have admin access to all apps
This commit is contained in:
parent
136bb5742f
commit
8cd07023ce
|
@ -37,33 +37,15 @@
|
||||||
let popoverAnchor
|
let popoverAnchor
|
||||||
let searchTerm = ""
|
let searchTerm = ""
|
||||||
let popover
|
let popover
|
||||||
let allAppList = []
|
|
||||||
let user
|
let user
|
||||||
let loaded = false
|
let loaded = false
|
||||||
|
|
||||||
$: fullName = user?.firstName ? user?.firstName + " " + user?.lastName : ""
|
$: fullName = user?.firstName ? user?.firstName + " " + user?.lastName : ""
|
||||||
|
$: privileged = user?.admin?.global || user?.builder?.global
|
||||||
$: nameLabel = getNameLabel(user)
|
$: nameLabel = getNameLabel(user)
|
||||||
$: initials = getInitials(nameLabel)
|
$: initials = getInitials(nameLabel)
|
||||||
$: filteredGroups = getFilteredGroups($groups, searchTerm)
|
$: filteredGroups = getFilteredGroups($groups, searchTerm)
|
||||||
$: allAppList = $apps
|
$: availableApps = getAvailableApps($apps, privileged, user?.roles)
|
||||||
.filter(x => {
|
|
||||||
return Object.keys(user?.roles || {}).find(y => {
|
|
||||||
return x.appId === apps.extractAppId(y)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.map(app => {
|
|
||||||
let roles = Object.fromEntries(
|
|
||||||
Object.entries(user?.roles).filter(([key]) => {
|
|
||||||
return apps.extractAppId(key) === app.appId
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
name: app.name,
|
|
||||||
devId: app.devId,
|
|
||||||
icon: app.icon,
|
|
||||||
roles,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
$: userGroups = $groups.filter(x => {
|
$: userGroups = $groups.filter(x => {
|
||||||
return x.users?.find(y => {
|
return x.users?.find(y => {
|
||||||
return y._id === userId
|
return y._id === userId
|
||||||
|
@ -75,6 +57,25 @@
|
||||||
? "developer"
|
? "developer"
|
||||||
: "appUser"
|
: "appUser"
|
||||||
|
|
||||||
|
const getAvailableApps = (appList, privileged, roles) => {
|
||||||
|
let availableApps = appList.slice()
|
||||||
|
if (!privileged) {
|
||||||
|
availableApps = availableApps.filter(x => {
|
||||||
|
return Object.keys(roles || {}).find(y => {
|
||||||
|
return x.appId === apps.extractAppId(y)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return availableApps.map(app => {
|
||||||
|
return {
|
||||||
|
name: app.name,
|
||||||
|
devId: app.devId,
|
||||||
|
icon: app.icon,
|
||||||
|
role: privileged ? Constants.Roles.ADMIN : roles[app.appId],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const getFilteredGroups = (groups, search) => {
|
const getFilteredGroups = (groups, search) => {
|
||||||
if (!search) {
|
if (!search) {
|
||||||
return groups
|
return groups
|
||||||
|
@ -116,18 +117,6 @@
|
||||||
return role?.name || "Custom role"
|
return role?.name || "Custom role"
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHighestRole(roles) {
|
|
||||||
let highestRole
|
|
||||||
let highestRoleNumber = 0
|
|
||||||
Object.keys(roles).forEach(role => {
|
|
||||||
let roleNumber = RoleUtils.getRolePriority(roles[role])
|
|
||||||
if (roleNumber > highestRoleNumber) {
|
|
||||||
highestRoleNumber = roleNumber
|
|
||||||
highestRole = roles[role]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return highestRole
|
|
||||||
}
|
|
||||||
async function updateUserFirstName(evt) {
|
async function updateUserFirstName(evt) {
|
||||||
try {
|
try {
|
||||||
await users.save({ ...user, firstName: evt.target.value })
|
await users.save({ ...user, firstName: evt.target.value })
|
||||||
|
@ -320,10 +309,15 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Layout gap="S" noPadding>
|
<Layout gap="S" noPadding>
|
||||||
<Heading size="S">Apps</Heading>
|
<div>
|
||||||
|
<Heading size="S">Apps</Heading>
|
||||||
|
{#if privileged}
|
||||||
|
<Body size="S">This user's role grants admin access to all apps</Body>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<List>
|
<List>
|
||||||
{#if allAppList.length}
|
{#if availableApps.length}
|
||||||
{#each allAppList as app}
|
{#each availableApps as app}
|
||||||
<ListItem
|
<ListItem
|
||||||
title={app.name}
|
title={app.name}
|
||||||
iconBackground={app?.icon?.color || ""}
|
iconBackground={app?.icon?.color || ""}
|
||||||
|
@ -332,11 +326,8 @@
|
||||||
on:click={() => $goto(`../../overview/${app.devId}`)}
|
on:click={() => $goto(`../../overview/${app.devId}`)}
|
||||||
>
|
>
|
||||||
<div class="title ">
|
<div class="title ">
|
||||||
<StatusLight
|
<StatusLight square color={RoleUtils.getRoleColour(app.role)}>
|
||||||
square
|
{getRoleLabel(app.role)}
|
||||||
color={RoleUtils.getRoleColour(getHighestRole(app.roles))}
|
|
||||||
>
|
|
||||||
{getRoleLabel(getHighestRole(app.roles))}
|
|
||||||
</StatusLight>
|
</StatusLight>
|
||||||
</div>
|
</div>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
|
@ -72,7 +72,6 @@
|
||||||
size="M"
|
size="M"
|
||||||
title="Import users"
|
title="Import users"
|
||||||
confirmText="Done"
|
confirmText="Done"
|
||||||
showCancelButton={false}
|
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
showCloseIcon={false}
|
showCloseIcon={false}
|
||||||
onConfirm={() => createUsersFromCsv({ userEmails, usersRole, userGroups })}
|
onConfirm={() => createUsersFromCsv({ userEmails, usersRole, userGroups })}
|
||||||
|
|
Loading…
Reference in New Issue