1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

Use ctx.identity instead of passing it as param

This commit is contained in:
adrinr 2023-03-14 15:46:50 +01:00
parent f8959aacb0
commit 4f2696ed32
3 changed files with 5 additions and 4 deletions

View file

@ -177,7 +177,7 @@ export const destroy = async (ctx: any) => {
ctx.throw(400, "Unable to delete self.")
}
await userSdk.destroy(id, ctx.user)
await userSdk.destroy(id)
ctx.body = {
message: `User ${id} deleted.`,

View file

@ -6,7 +6,7 @@ export const initPro = async () => {
scimUserServiceConfig: {
functions: {
saveUser: userSdk.save,
removeUser: (id: string) => userSdk.destroy(id, undefined),
removeUser: (id: string) => userSdk.destroy(id),
},
},
})

View file

@ -15,6 +15,7 @@ import {
utils,
ViewName,
env as coreEnv,
context,
} from "@budibase/backend-core"
import {
AccountMetadata,
@ -537,7 +538,7 @@ export const bulkDelete = async (
return response
}
export const destroy = async (id: string, currentUser: any) => {
export const destroy = async (id: string) => {
const db = tenancy.getGlobalDB()
const dbUser = (await db.get(id)) as User
const userId = dbUser._id as string
@ -547,7 +548,7 @@ export const destroy = async (id: string, currentUser: any) => {
const email = dbUser.email
const account = await accounts.getAccount(email)
if (account) {
if (email === currentUser.email) {
if (dbUser.userId === context.getIdentity()!._id) {
throw new HTTPError('Please visit "Account" to delete this user', 400)
} else {
throw new HTTPError("Account holder cannot be deleted", 400)