From ee8bd9f599121b080738f0c24a1e5dcafa292628 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 4 Aug 2022 18:01:14 +0100 Subject: [PATCH] Show that admin and builder users have admin access to all apps --- .../portal/manage/users/[userId].svelte | 71 ++++++++----------- .../users/_components/ImportUsersModal.svelte | 1 - 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 8ce83d93ad..19e0321b5b 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -37,33 +37,15 @@ let popoverAnchor let searchTerm = "" let popover - let allAppList = [] let user let loaded = false $: fullName = user?.firstName ? user?.firstName + " " + user?.lastName : "" + $: privileged = user?.admin?.global || user?.builder?.global $: nameLabel = getNameLabel(user) $: initials = getInitials(nameLabel) $: filteredGroups = getFilteredGroups($groups, searchTerm) - $: allAppList = $apps - .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, - } - }) + $: availableApps = getAvailableApps($apps, privileged, user?.roles) $: userGroups = $groups.filter(x => { return x.users?.find(y => { return y._id === userId @@ -75,6 +57,25 @@ ? "developer" : "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) => { if (!search) { return groups @@ -116,18 +117,6 @@ 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) { try { await users.save({ ...user, firstName: evt.target.value }) @@ -320,10 +309,15 @@ {/if} - Apps +
+ Apps + {#if privileged} + This user's role grants admin access to all apps + {/if} +
- {#if allAppList.length} - {#each allAppList as app} + {#if availableApps.length} + {#each availableApps as app} $goto(`../../overview/${app.devId}`)} >
- - {getRoleLabel(getHighestRole(app.roles))} + + {getRoleLabel(app.role)}
diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte index 1e7c579346..954177f51e 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte @@ -72,7 +72,6 @@ size="M" title="Import users" confirmText="Done" - showCancelButton={false} cancelText="Cancel" showCloseIcon={false} onConfirm={() => createUsersFromCsv({ userEmails, usersRole, userGroups })}