cacf275a99
* Prevent SSO users from setting / resetting a password * Add support for ENABLE_SSO_MAINTENANCE_MODE * Add typing to self api and build out user update sdk * Integrate sso checks with user sdk. Integrate user sdk with self api * Test fixes * Move self update into SDK * Lock down maintenance mode to admin user * Fix typo * Add health status response and return type signature to accounts.getStatus * Remove some unnecessary comments * Make sso save user function non optional * Remove redundant check on sso auth details provider * Update syncProfilePicture function name to getProfilePictureUrl * Update packages/worker/src/sdk/users/events.ts Co-authored-by: Adria Navarro <adria@revityapp.com> * Add ENABLE_EMAIL_TEST_MODE flag * Fix for logging in as sso user when existing user has password already * Hide password update and force reset from ui for sso users * Always disable sso maintenance mode in cloud --------- Co-authored-by: Adria Navarro <adria@revityapp.com>
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { AccountMetadata } from "@budibase/types"
|
|
import {
|
|
db,
|
|
StaticDatabases,
|
|
DocumentType,
|
|
SEPARATOR,
|
|
} from "@budibase/backend-core"
|
|
|
|
export const formatAccountMetadataId = (accountId: string) => {
|
|
return `${DocumentType.ACCOUNT_METADATA}${SEPARATOR}${accountId}`
|
|
}
|
|
|
|
export const saveMetadata = async (
|
|
metadata: AccountMetadata
|
|
): Promise<AccountMetadata> => {
|
|
return db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
|
const existing = await getMetadata(metadata._id!)
|
|
if (existing) {
|
|
metadata._rev = existing._rev
|
|
}
|
|
const res = await db.put(metadata)
|
|
metadata._rev = res.rev
|
|
return metadata
|
|
})
|
|
}
|
|
|
|
export const getMetadata = async (
|
|
accountId: string
|
|
): Promise<AccountMetadata | undefined> => {
|
|
return db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
|
try {
|
|
return await db.get(accountId)
|
|
} catch (e: any) {
|
|
if (e.status === 404) {
|
|
// do nothing
|
|
return
|
|
} else {
|
|
throw e
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
export const destroyMetadata = async (accountId: string) => {
|
|
await db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
|
const metadata = await getMetadata(accountId)
|
|
if (!metadata) {
|
|
return
|
|
}
|
|
try {
|
|
await db.remove(accountId, metadata._rev)
|
|
} catch (e: any) {
|
|
if (e.status !== 404) {
|
|
throw e
|
|
}
|
|
}
|
|
})
|
|
}
|