Add endpoint to deactivate user from app on delete
This commit is contained in:
parent
24f8f3a7cb
commit
09b4533cc8
|
@ -173,3 +173,35 @@ export async function getFlags(ctx: BBContext) {
|
|||
}
|
||||
ctx.body = doc
|
||||
}
|
||||
|
||||
export async function removeUserFromApp(ctx: BBContext) {
|
||||
const { id: userId, prodAppId } = ctx.params
|
||||
|
||||
const devAppId = dbCore.getDevelopmentAppID(prodAppId)
|
||||
for (let appId of [prodAppId, devAppId]) {
|
||||
if (!(await dbCore.dbExists(appId))) {
|
||||
continue
|
||||
}
|
||||
await context.doInAppContext(appId, async () => {
|
||||
const db = context.getAppDB()
|
||||
const metadataId = generateUserMetadataID(userId)
|
||||
let metadata
|
||||
try {
|
||||
metadata = await db.get(metadataId)
|
||||
} catch (err) {
|
||||
return
|
||||
}
|
||||
|
||||
let combined = {
|
||||
...metadata,
|
||||
status: constants.UserStatus.INACTIVE,
|
||||
metadata: rolesCore.BUILTIN_ROLE_IDS.PUBLIC,
|
||||
}
|
||||
|
||||
await db.put(combined)
|
||||
})
|
||||
}
|
||||
ctx.body = {
|
||||
message: `User ${userId} deleted from ${prodAppId} and ${"devapp"}.`,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,5 +47,10 @@ router
|
|||
authorized(PermissionType.USER, PermissionLevel.READ),
|
||||
controller.getFlags
|
||||
)
|
||||
.delete(
|
||||
"/api/users/metadata/:id/app/:prodAppId",
|
||||
authorized(PermissionType.USER, PermissionLevel.WRITE),
|
||||
controller.removeUserFromApp
|
||||
)
|
||||
|
||||
export default router
|
||||
|
|
Loading…
Reference in New Issue