Review feedback
This commit is contained in:
parent
ab45e06edb
commit
f622c84ebc
|
@ -1,11 +1,3 @@
|
||||||
export interface UpdateSelf {
|
|
||||||
firstName?: string
|
|
||||||
lastName?: string
|
|
||||||
password?: string
|
|
||||||
forceResetPassword?: boolean
|
|
||||||
onboardedAt?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SaveUserOpts {
|
export interface SaveUserOpts {
|
||||||
hashPassword?: boolean
|
hashPassword?: boolean
|
||||||
requirePassword?: boolean
|
requirePassword?: boolean
|
||||||
|
|
|
@ -10,12 +10,7 @@ import {
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { groups } from "@budibase/pro"
|
import { groups } from "@budibase/pro"
|
||||||
import {
|
import { UpdateSelfRequest, UpdateSelfResponse, UserCtx } from "@budibase/types"
|
||||||
UpdateSelfRequest,
|
|
||||||
UpdateSelfResponse,
|
|
||||||
UpdateSelf,
|
|
||||||
UserCtx,
|
|
||||||
} from "@budibase/types"
|
|
||||||
const { getCookie, clearCookie, newid } = utils
|
const { getCookie, clearCookie, newid } = utils
|
||||||
|
|
||||||
function newTestApiKey() {
|
function newTestApiKey() {
|
||||||
|
@ -122,13 +117,14 @@ export async function getSelf(ctx: any) {
|
||||||
export async function updateSelf(
|
export async function updateSelf(
|
||||||
ctx: UserCtx<UpdateSelfRequest, UpdateSelfResponse>
|
ctx: UserCtx<UpdateSelfRequest, UpdateSelfResponse>
|
||||||
) {
|
) {
|
||||||
const body = ctx.request.body
|
const update = ctx.request.body
|
||||||
|
|
||||||
const update: UpdateSelf = {
|
let user = await userSdk.getUser(ctx.user._id!)
|
||||||
...body,
|
user = {
|
||||||
|
...user,
|
||||||
|
...update,
|
||||||
}
|
}
|
||||||
|
user = await userSdk.save(user, { requirePassword: false })
|
||||||
const user = await userSdk.updateSelf(ctx.user._id!, update)
|
|
||||||
|
|
||||||
if (update.password) {
|
if (update.password) {
|
||||||
// Log all other sessions out apart from the current one
|
// Log all other sessions out apart from the current one
|
||||||
|
|
|
@ -29,7 +29,6 @@ import {
|
||||||
PlatformUserByEmail,
|
PlatformUserByEmail,
|
||||||
RowResponse,
|
RowResponse,
|
||||||
SearchUsersRequest,
|
SearchUsersRequest,
|
||||||
UpdateSelf,
|
|
||||||
User,
|
User,
|
||||||
SaveUserOpts,
|
SaveUserOpts,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -227,15 +226,6 @@ export async function isPreventPasswordActions(user: User) {
|
||||||
return !!(account && isSSOAccount(account))
|
return !!(account && isSSOAccount(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateSelf(id: string, data: UpdateSelf) {
|
|
||||||
let user = await getUser(id)
|
|
||||||
user = {
|
|
||||||
...user,
|
|
||||||
...data,
|
|
||||||
}
|
|
||||||
return save(user, { requirePassword: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
export const save = async (
|
export const save = async (
|
||||||
user: User,
|
user: User,
|
||||||
opts: SaveUserOpts = {}
|
opts: SaveUserOpts = {}
|
||||||
|
|
Loading…
Reference in New Issue