diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index 9e4462df00..d239155700 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -74,12 +74,12 @@ export class AccountMoveService { */ @bindThis public async moveFromLocal(src: LocalUser, dst: User): Promise { - if (!dst.uri) throw new Error('destination uri is empty'); + const dstUri = this.getUserUri(dst); // add movedToUri to indicate that the user has moved const update = {} as Partial; - update.alsoKnownAs = src.alsoKnownAs?.concat([dst.uri]) ?? [dst.uri]; - update.movedToUri = dst.uri; + update.alsoKnownAs = src.alsoKnownAs?.concat([dstUri]) ?? [dstUri]; + update.movedToUri = dstUri; await this.usersRepository.update(src.id, update); const srcPerson = await this.apRendererService.renderPerson(src); diff --git a/packages/backend/src/server/api/endpoints/i/move.ts b/packages/backend/src/server/api/endpoints/i/move.ts index c1aa0f4ccb..972dd6076d 100644 --- a/packages/backend/src/server/api/endpoints/i/move.ts +++ b/packages/backend/src/server/api/endpoints/i/move.ts @@ -109,22 +109,27 @@ export default class extends Endpoint { throw new ApiError(meta.errors.noSuchMoveTarget); }); const destination = await this.getterService.getUser(moveTo.id); - moveTo.uri = this.accountMoveService.getUserUri(destination); + const newUri = this.accountMoveService.getUserUri(destination); // update local db - await this.apPersonService.updatePerson(moveTo.uri); + await this.apPersonService.updatePerson(newUri); // retrieve updated user - moveTo = await this.apPersonService.resolvePerson(moveTo.uri); + moveTo = await this.apPersonService.resolvePerson(newUri); // make sure that the user has indicated the old account as an alias const fromUrl = `${this.config.url}/users/${me.id}`; let allowed = false; - moveTo.alsoKnownAs?.forEach((elem) => { - if (fromUrl.includes(elem)) allowed = true; - }); + if (moveTo.alsoKnownAs) { + for (const knownAs of moveTo.alsoKnownAs) { + if (knownAs.includes(fromUrl)) { + allowed = true; + break; + } + } + } // abort if unintended - if (!(allowed && moveTo.uri && fromUrl)) throw new ApiError(meta.errors.destinationAccountForbids); + if (!allowed) throw new ApiError(meta.errors.destinationAccountForbids); return await this.accountMoveService.moveFromLocal(me, moveTo); });