Skip to content

Commit

Permalink
Merge branch 'master' into chore/fix-oss-docker-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Jul 29, 2024
2 parents 1001691 + d29d37b commit fe74d57
Show file tree
Hide file tree
Showing 30 changed files with 752 additions and 673 deletions.
9 changes: 5 additions & 4 deletions packages/backend-core/src/db/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,18 @@ export const createPlatformUserView = async () => {

export const queryPlatformView = async <T extends Document>(
viewName: ViewName,
params: DatabaseQueryOpts,
opts?: QueryViewOptions
): Promise<T[] | T> => {
params: DatabaseQueryOpts
): Promise<T[]> => {
const CreateFuncByName: any = {
[ViewName.ACCOUNT_BY_EMAIL]: createPlatformAccountEmailView,
[ViewName.PLATFORM_USERS_LOWERCASE]: createPlatformUserView,
}

return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: Database) => {
const createFn = CreateFuncByName[viewName]
return queryView(viewName, params, db, createFn, opts)
return queryView(viewName, params, db, createFn, {
arrayResponse: true,
}) as Promise<T[]>
})
}

Expand Down
5 changes: 5 additions & 0 deletions packages/backend-core/src/platform/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export async function getUserDoc(emailOrId: string): Promise<PlatformUser> {
return db.get(emailOrId)
}

export async function updateUserDoc(platformUser: PlatformUserById) {
const db = getPlatformDB()
await db.put(platformUser)
}

// CREATE

function newUserIdDoc(id: string, tenantId: string): PlatformUserById {
Expand Down
32 changes: 31 additions & 1 deletion packages/backend-core/src/users/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ import {
User,
UserStatus,
UserGroup,
PlatformUserBySsoId,
PlatformUserById,
AnyDocument,
} from "@budibase/types"
import {
getAccountHolderFromUserIds,
isAdmin,
isCreator,
validateUniqueUser,
} from "./utils"
import { searchExistingEmails } from "./lookup"
import {
getFirstPlatformUser,
getPlatformUsers,
searchExistingEmails,
} from "./lookup"
import { hash } from "../utils"
import { validatePassword } from "../security"

Expand Down Expand Up @@ -446,9 +453,32 @@ export class UserDB {
creator => !!creator
).length

const ssoUsersToDelete: AnyDocument[] = []
for (let user of usersToDelete) {
const platformUser = (await getFirstPlatformUser(
user._id!
)) as PlatformUserById
const ssoId = platformUser.ssoId
if (ssoId) {
// Need to get the _rev of the SSO user doc to delete it. The view also returns docs that have the ssoId property, so we need to ignore those.
const ssoUsers = (await getPlatformUsers(
ssoId
)) as PlatformUserBySsoId[]
ssoUsers
.filter(user => user.ssoId == null)
.forEach(user => {
ssoUsersToDelete.push({
...user,
_deleted: true,
})
})
}
await bulkDeleteProcessing(user)
}

// Delete any associated SSO user docs
await platform.getPlatformDB().bulkDocs(ssoUsersToDelete)

await UserDB.quotas.removeUsers(toDelete.length, creatorsToDeleteCount)

// Build Response
Expand Down
37 changes: 15 additions & 22 deletions packages/backend-core/src/users/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ export async function searchExistingEmails(emails: string[]) {
}

// lookup, could be email or userId, either will return a doc
export async function getPlatformUser(
export async function getPlatformUsers(
identifier: string
): Promise<PlatformUser | null> {
): Promise<PlatformUser[]> {
// use the view here and allow to find anyone regardless of casing
// Use lowercase to ensure email login is case insensitive
return (await dbUtils.queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
return await dbUtils.queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
keys: [identifier.toLowerCase()],
include_docs: true,
})) as PlatformUser
})
}

export async function getFirstPlatformUser(
identifier: string
): Promise<PlatformUser | null> {
const platformUserDocs = await getPlatformUsers(identifier)
return platformUserDocs[0] ?? null
}

export async function getExistingTenantUsers(
Expand Down Expand Up @@ -74,15 +81,10 @@ export async function getExistingPlatformUsers(
keys: lcEmails,
include_docs: true,
}

const opts = {
arrayResponse: true,
}
return (await dbUtils.queryPlatformView(
return await dbUtils.queryPlatformView(
ViewName.PLATFORM_USERS_LOWERCASE,
params,
opts
)) as PlatformUserByEmail[]
params
)
}

export async function getExistingAccounts(
Expand All @@ -93,14 +95,5 @@ export async function getExistingAccounts(
keys: lcEmails,
include_docs: true,
}

const opts = {
arrayResponse: true,
}

return (await dbUtils.queryPlatformView(
ViewName.ACCOUNT_BY_EMAIL,
params,
opts
)) as AccountMetadata[]
return await dbUtils.queryPlatformView(ViewName.ACCOUNT_BY_EMAIL, params)
}
4 changes: 2 additions & 2 deletions packages/backend-core/src/users/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CloudAccount, ContextUser, User, UserGroup } from "@budibase/types"
import * as accountSdk from "../accounts"
import env from "../environment"
import { getPlatformUser } from "./lookup"
import { getFirstPlatformUser } from "./lookup"
import { EmailUnavailableError } from "../errors"
import { getTenantId } from "../context"
import { sdk } from "@budibase/shared-core"
Expand Down Expand Up @@ -51,7 +51,7 @@ async function isCreatorByGroupMembership(user?: User | ContextUser) {
export async function validateUniqueUser(email: string, tenantId: string) {
// check budibase users in other tenants
if (env.MULTI_TENANCY) {
const tenantUser = await getPlatformUser(email)
const tenantUser = await getFirstPlatformUser(email)
if (tenantUser != null && tenantUser.tenantId !== tenantId) {
throw new EmailUnavailableError(email)
}
Expand Down
8 changes: 5 additions & 3 deletions packages/bbui/src/InlineAlert/InlineAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
<use xlink:href="#spectrum-icon-18-{icon}" />
</svg>
<div class="spectrum-InLineAlert-header">{header}</div>
{#each split as splitMsg}
<div class="spectrum-InLineAlert-content">{splitMsg}</div>
{/each}
<slot>
{#each split as splitMsg}
<div class="spectrum-InLineAlert-content">{splitMsg}</div>
{/each}
</slot>
{#if onConfirm}
<div class="spectrum-InLineAlert-footer button">
<Button {cta} secondary={cta ? false : true} on:click={onConfirm}
Expand Down
20 changes: 17 additions & 3 deletions packages/bbui/src/StatusLight/StatusLight.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class:custom={!!color}
class:square
class:hoverable
style={`--color: ${color};`}
style={`--color: ${color ?? "var(--spectrum-global-color-gray-400)"};`}
class:spectrum-StatusLight--celery={celery}
class:spectrum-StatusLight--yellow={yellow}
class:spectrum-StatusLight--fuchsia={fuchsia}
Expand Down Expand Up @@ -61,13 +61,17 @@
min-height: 0;
padding-top: 0;
padding-bottom: 0;
transition: color ease-out 130ms;
}
.spectrum-StatusLight.withText::before {
margin-right: 10px;
}
.spectrum-StatusLight::before {
transition: background-color ease-out 160ms;
}
.custom::before {
background: var(--color) !important;
background-color: var(--color) !important;
}
.square::before {
width: 14px;
Expand All @@ -79,4 +83,14 @@
cursor: pointer;
color: var(--spectrum-global-color-gray-900);
}
.spectrum-StatusLight--sizeXS::before {
width: 10px;
height: 10px;
border-radius: 2px;
}
.spectrum-StatusLight--disabled::before {
background-color: var(--spectrum-global-color-gray-400) !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
title="Confirm Deletion"
>
Are you sure you wish to delete the datasource
<i>{datasource.name}?</i>
This action cannot be undone.
<i>{datasource.name}</i>? This action cannot be undone.
</ConfirmDialog>
Loading

0 comments on commit fe74d57

Please sign in to comment.