Clone user (#10974)
This commit is contained in:
parent
b0debf17ef
commit
9e9cece59e
|
@ -9,7 +9,7 @@ import {
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { groups } from "@budibase/pro"
|
import { groups } from "@budibase/pro"
|
||||||
import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
|
import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
|
||||||
import { global } from "yargs"
|
import { cloneDeep } from "lodash"
|
||||||
|
|
||||||
export function updateAppRole(
|
export function updateAppRole(
|
||||||
user: ContextUser,
|
user: ContextUser,
|
||||||
|
@ -65,16 +65,20 @@ export async function processUser(
|
||||||
user: ContextUser,
|
user: ContextUser,
|
||||||
opts: { appId?: string; groups?: UserGroup[] } = {}
|
opts: { appId?: string; groups?: UserGroup[] } = {}
|
||||||
) {
|
) {
|
||||||
if (user) {
|
let clonedUser = cloneDeep(user)
|
||||||
delete user.password
|
if (clonedUser) {
|
||||||
|
delete clonedUser.password
|
||||||
}
|
}
|
||||||
const appId = opts.appId || context.getAppId()
|
const appId = opts.appId || context.getAppId()
|
||||||
user = updateAppRole(user, { appId })
|
clonedUser = updateAppRole(clonedUser, { appId })
|
||||||
if (!user.roleId && user?.userGroups?.length) {
|
if (!clonedUser.roleId && clonedUser?.userGroups?.length) {
|
||||||
user = await checkGroupRoles(user, { appId, groups: opts?.groups })
|
clonedUser = await checkGroupRoles(clonedUser, {
|
||||||
|
appId,
|
||||||
|
groups: opts?.groups,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return user
|
return clonedUser
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCachedSelf(ctx: UserCtx, appId: string) {
|
export async function getCachedSelf(ctx: UserCtx, appId: string) {
|
||||||
|
|
Loading…
Reference in New Issue