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 d2bb7a2a..a70bb76a 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 @@ -17,16 +17,10 @@ export class AdminDeleteUserController { async deleteUser( userId: string, deleteData: boolean, - username?: string, ): Promise<{ status: "failed" | "deleting" | "done"; userId?: string }> { try { - let pk: UserPrimaryKey = { id: userId }; - if (username) { - pk = { username_canonical: username }; - } - const data = await gr.services.users.anonymizeAndDelete( - pk, + { id: userId }, { user: { server_request: true }, } as unknown as ExecutionContext, @@ -68,8 +62,8 @@ export class AdminDeleteUserController { 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 }); + async getUserIdByEmail(email: string) { + const user = await gr.services.users.get({ email_canonical: email }); 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 f70fb232..956bf8c1 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 @@ -14,22 +14,21 @@ function authenticateAdminQuery(request: FastifyRequest, reply: FastifyReply) { return true; } -type TUserDeleteQueryBody = TQueryBody & { userId: string; deleteData: boolean; username?: string }; +type TUserDeleteQueryBody = TQueryBody & { userId: string; deleteData: boolean }; function getUserIfValidQuery(request: FastifyRequest, reply: FastifyReply) { if (!authenticateAdminQuery(request, reply)) return { userId: "", deleteData: false }; const body = request.body as TUserDeleteQueryBody; - if (!body.userId?.length && !body.username) { + if (!body.userId?.length) { reply.status(400).send(); - return { userId: "", username: "", deleteData: false }; + return { userId: "", deleteData: false }; } return { userId: body.userId || "", - username: body.username, deleteData: body.deleteData, }; } -type TUserGetIdByUsernameBody = TQueryBody & { username: string }; +type TUserGetIdByEmailBody = TQueryBody & { email: string }; const routes: FastifyPluginCallback = async (fastify: FastifyInstance, _opts, next) => { const urlRoot = "/api/user/delete"; @@ -37,13 +36,13 @@ const routes: FastifyPluginCallback = async (fastify: FastifyInstance, _opts, ne const controller = new AdminDeleteUserController(); if (config?.endpointSecret?.length) { fastify.post(urlRoot, async (request, reply) => { - const { userId, deleteData, username } = getUserIfValidQuery(request, reply); - if (!userId && !username) return false; + const { userId, deleteData } = getUserIfValidQuery(request, reply); + if (!userId) return false; if (userId == "e2e_simulate_timeout") return new Promise(() => { return; }); - return await controller.deleteUser(userId, deleteData, username); + return await controller.deleteUser(userId, deleteData); }); fastify.post(`${urlRoot}/pending`, async (request, reply) => { @@ -54,8 +53,8 @@ const routes: FastifyPluginCallback = async (fastify: FastifyInstance, _opts, ne 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); + const { email } = request.body as TUserGetIdByEmailBody; + const userId = await controller.getUserIdByEmail(email); if (!userId) { return reply.status(404).send({ message: "User not found" }); diff --git a/tdrive/backend/node/src/services/user/entities/user.ts b/tdrive/backend/node/src/services/user/entities/user.ts index d928ef95..73081359 100644 --- a/tdrive/backend/node/src/services/user/entities/user.ts +++ b/tdrive/backend/node/src/services/user/entities/user.ts @@ -151,7 +151,7 @@ export type UserNotificationPreferences = { export type UserPrimaryKey = { id?: uuid; - username_canonical?: string; + email_canonical?: string; }; export function getInstance(user: Partial): User {