From 3f357561d0f42755845381d15d02e8e84058ba9a Mon Sep 17 00:00:00 2001 From: melohagan <101575380+melohagan@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:29:38 +0100 Subject: [PATCH] The UI should indicate who the account holder is (#14470) * Get tenantInfo in user fetch * Add account holder label in users table * Don't allow account holder to be selected in users table * Sort account holder to top of list * Only use account holder role in users table * lint * Remove joi validation from tenant-info endpoint * Remove dayPasses * Catch CouchDB 404 and return undefined * Don't allow account holder role to be changed UI * Don't offer delete option for tenant owner * Backend validation to ensure account holder role cannot be updated * Don't allow account holder role to be changed UI * Get tenantOwner in separate call * Pass data into SelectEditRenderer * Rename var to __selectable * setEnrichedUsers * Update pro reference * Only load tenantOwner once --- packages/backend-core/src/tenancy/db.ts | 14 +++++++--- .../bbui/src/Table/SelectEditRenderer.svelte | 3 ++- packages/bbui/src/Table/Table.svelte | 12 ++++++++- .../portal/users/users/[userId].svelte | 20 +++++++++----- .../_components/RoleTableRenderer.svelte | 2 +- .../builder/portal/users/users/index.svelte | 23 +++++++++++++--- .../builder/src/stores/portal/licensing.js | 2 +- packages/builder/src/stores/portal/users.js | 10 ++++++- packages/frontend-core/src/api/user.js | 6 +++++ packages/frontend-core/src/constants.js | 11 ++++++++ .../src/api/controllers/global/users.ts | 11 ++++++++ .../worker/src/api/routes/global/tenant.ts | 27 +------------------ .../src/api/routes/global/tests/users.spec.ts | 22 +++++++++++++++ 13 files changed, 119 insertions(+), 44 deletions(-) diff --git a/packages/backend-core/src/tenancy/db.ts b/packages/backend-core/src/tenancy/db.ts index d430296a5c..332ecbca48 100644 --- a/packages/backend-core/src/tenancy/db.ts +++ b/packages/backend-core/src/tenancy/db.ts @@ -15,7 +15,15 @@ export async function saveTenantInfo(tenantInfo: TenantInfo) { }) } -export async function getTenantInfo(tenantId: string): Promise { - const db = getTenantDB(tenantId) - return db.get("tenant_info") +export async function getTenantInfo( + tenantId: string +): Promise { + try { + const db = getTenantDB(tenantId) + const tenantInfo = (await db.get("tenant_info")) as TenantInfo + delete tenantInfo.owner.password + return tenantInfo + } catch { + return undefined + } } diff --git a/packages/bbui/src/Table/SelectEditRenderer.svelte b/packages/bbui/src/Table/SelectEditRenderer.svelte index c6eafa3ed0..0c88fa3167 100644 --- a/packages/bbui/src/Table/SelectEditRenderer.svelte +++ b/packages/bbui/src/Table/SelectEditRenderer.svelte @@ -6,10 +6,11 @@ export let onEdit export let allowSelectRows = false export let allowEditRows = false + export let data
- {#if allowSelectRows} + {#if allowSelectRows && data.__selectable !== false} {/if} {#if allowEditRows} diff --git a/packages/bbui/src/Table/Table.svelte b/packages/bbui/src/Table/Table.svelte index 868f7b3a0b..3916bec738 100644 --- a/packages/bbui/src/Table/Table.svelte +++ b/packages/bbui/src/Table/Table.svelte @@ -43,6 +43,8 @@ export let showHeaderBorder = true export let placeholderText = "No rows found" export let snippets = [] + export let defaultSortColumn + export let defaultSortOrder = "Ascending" const dispatch = createEventDispatcher() @@ -162,6 +164,8 @@ } const sortRows = (rows, sortColumn, sortOrder) => { + sortColumn = sortColumn ?? defaultSortColumn + sortOrder = sortOrder ?? defaultSortOrder if (!sortColumn || !sortOrder || disableSorting) { return rows } @@ -259,7 +263,10 @@ if (select) { // Add any rows which are not already in selected rows rows.forEach(row => { - if (selectedRows.findIndex(x => x._id === row._id) === -1) { + if ( + row.__selectable !== false && + selectedRows.findIndex(x => x._id === row._id) === -1 + ) { selectedRows.push(row) } }) @@ -396,6 +403,9 @@ class:noBorderCheckbox={!showHeaderBorder} class="spectrum-Table-cell spectrum-Table-cell--divider spectrum-Table-cell--edit" on:click={e => { + if (row.__selectable === false) { + return + } toggleSelectRow(row) e.stopPropagation() }} diff --git a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte index d4e765a4be..458c9a3f79 100644 --- a/packages/builder/src/pages/builder/portal/users/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/users/users/[userId].svelte @@ -85,7 +85,7 @@ let popoverAnchor let searchTerm = "" let popover - let user + let user, tenantOwner let loaded = false $: internalGroups = $groups?.filter(g => !g?.scimInfo?.isSync) @@ -104,6 +104,7 @@ }) }) $: globalRole = users.getUserRole(user) + $: isTenantOwner = tenantOwner?.email && tenantOwner.email === user?.email const getAvailableApps = (appList, privileged, roles) => { let availableApps = appList.slice() @@ -205,6 +206,7 @@ if (!user?._id) { $goto("./") } + tenantOwner = await users.tenantOwner($auth.tenantId) } async function toggleFlags(detail) { @@ -268,9 +270,11 @@ Force password reset {/if} - - Delete - + {#if !isTenantOwner} + + Delete + + {/if}
{/if} @@ -310,9 +314,11 @@