diff --git a/tdrive/backend/node/src/core/platform/services/admin/controller/delete-user-controller.ts b/tdrive/backend/node/src/core/platform/services/admin/controller/delete-user-controller.ts index 7de45fd6..d2bb7a2a 100644 --- a/tdrive/backend/node/src/core/platform/services/admin/controller/delete-user-controller.ts +++ b/tdrive/backend/node/src/core/platform/services/admin/controller/delete-user-controller.ts @@ -48,7 +48,7 @@ export class AdminDeleteUserController { } } } catch (err) { - adminLogger.error("[DELETE USER] ", JSON.stringify({ err, userId }), "User deletion error"); + adminLogger.error({ err, userId }, "[DELETE USER] User deletion error"); return { status: "failed", userId, @@ -67,4 +67,10 @@ export class AdminDeleteUserController { ).getEntities(); return users.map(({ id, delete_process_started_epoch }) => [id, delete_process_started_epoch]); } + + async getUserIdByUsername(username: string) { + const user = await gr.services.users.get({ username_canonical: username }); + + return user?.id; + } } diff --git a/tdrive/backend/node/src/core/platform/services/admin/web/delete-user-routes.ts b/tdrive/backend/node/src/core/platform/services/admin/web/delete-user-routes.ts index c5c451de..f70fb232 100644 --- a/tdrive/backend/node/src/core/platform/services/admin/web/delete-user-routes.ts +++ b/tdrive/backend/node/src/core/platform/services/admin/web/delete-user-routes.ts @@ -29,6 +29,8 @@ function getUserIfValidQuery(request: FastifyRequest, reply: FastifyReply) { }; } +type TUserGetIdByUsernameBody = TQueryBody & { username: string }; + const routes: FastifyPluginCallback = async (fastify: FastifyInstance, _opts, next) => { const urlRoot = "/api/user/delete"; const config = getConfig(); @@ -48,6 +50,19 @@ const routes: FastifyPluginCallback = async (fastify: FastifyInstance, _opts, ne if (!authenticateAdminQuery(request, reply)) return false; return await controller.listUsersPendingDeletion(); }); + + fastify.post("/api/user-id", async (request, reply) => { + if (!authenticateAdminQuery(request, reply)) return false; + + const { username } = request.body as TUserGetIdByUsernameBody; + const userId = await controller.getUserIdByUsername(username); + + if (!userId) { + return reply.status(404).send({ message: "User not found" }); + } + + return { id: userId }; + }); } next(); };