From 5a30581c7386ee8f26e43b75f0eeb98389604643 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 8 Apr 2024 20:39:41 +0200 Subject: [PATCH] [backend] Fix autofollowedAccount being set to random (possibly non-local) users on update-meta --- .../server/api/endpoints/admin/update-meta.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 32276783a..90f089c78 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -4,6 +4,7 @@ import { db } from "@/db/postgre.js"; import define from "../../define.js"; import { Metas } from "@/models/index.js"; import { Users } from "@/models/index.js"; +import { IsNull } from "typeorm"; export const meta = { @@ -537,10 +538,18 @@ export default define(meta, paramDef, async (ps, me) => { } if (ps.autofollowedAccount !== undefined) { - // Verify account exists and is a local account - const user = await Users.findOneBy({ username: ps.autofollowedAccount, host: null }); - if (user) { - set.autofollowedAccount = user.username; + if (ps.autofollowedAccount === null) { + set.autofollowedAccount = null; + } + else { + // Verify account exists and is a local account + const user = await Users.findOneBy({ username: ps.autofollowedAccount, host: IsNull() }); + if (user !== null) { + set.autofollowedAccount = user.username; + } + else { + set.autofollowedAccount = null; + } } }