Skip to content
Snippets Groups Projects
Commit a9125609 authored by Léopold Chappuis's avatar Léopold Chappuis Committed by Léopold Chappuis
Browse files

accounts-overview: simplify delete account logic and add upload cache deletion

The function is now streamlined with easier access to accountId, allowing for a more efficient implementation. Additionally, the logic includes the deletion of the upload cache.

Change-Id: I262980e770f0d6757a307e18850457a1df117b1b
parent d4e8aa81
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import envPaths from 'env-paths' ...@@ -20,6 +20,7 @@ import envPaths from 'env-paths'
import { Router } from 'express' import { Router } from 'express'
import asyncHandler from 'express-async-handler' import asyncHandler from 'express-async-handler'
import { ParamsDictionary, Request, Response } from 'express-serve-static-core' import { ParamsDictionary, Request, Response } from 'express-serve-static-core'
import fs from 'fs'
import { readdir, stat } from 'fs/promises' import { readdir, stat } from 'fs/promises'
import { import {
AccessToken, AccessToken,
...@@ -51,6 +52,11 @@ export const adminRouter = Router() ...@@ -51,6 +52,11 @@ export const adminRouter = Router()
const paths = envPaths('jami', { suffix: '' }) const paths = envPaths('jami', { suffix: '' })
const dataPath = paths.data const dataPath = paths.data
const multerPath = adminAccount.getUploadPath()
if (!fs.existsSync(multerPath)) {
fs.mkdirSync(multerPath)
}
adminRouter.get('/check', (_req, res) => { adminRouter.get('/check', (_req, res) => {
const isSetupComplete = adminAccount.getPasswordHash() !== undefined const isSetupComplete = adminAccount.getPasswordHash() !== undefined
res.send({ isSetupComplete }) res.send({ isSetupComplete })
...@@ -399,18 +405,13 @@ adminRouter.delete( ...@@ -399,18 +405,13 @@ adminRouter.delete(
asyncHandler(async (req, res) => { asyncHandler(async (req, res) => {
const users = req.body const users = req.body
for (const user of users) { for (const user of users) {
if (user.auth === 'local') { const accountId = user.accountId
const accountId = jamid.getAccountIdFromUsername(user.username)
if (accountId) {
jamid.removeAccount(accountId) jamid.removeAccount(accountId)
}
} else if (user.auth === 'jams') {
const account = accounts.get(user.username, user.auth)
if (typeof account === 'object') {
jamid.removeAccount(account.accountId)
}
}
accounts.remove(user.username, user.auth) accounts.remove(user.username, user.auth)
const userFilePath = multerPath + accountId + '/'
if (fs.existsSync(userFilePath)) {
fs.rmdirSync(userFilePath, { recursive: true })
}
} }
res.sendStatus(HttpStatusCode.Ok) res.sendStatus(HttpStatusCode.Ok)
}), }),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment