prevent moving if the destination account has already moved

This commit is contained in:
Namekuji 2023-04-20 19:16:02 -04:00
parent 0d78cacffc
commit 2a0efffa3e
4 changed files with 37 additions and 22 deletions

View file

@ -78,7 +78,7 @@ export class AccountMoveService {
// add movedToUri to indicate that the user has moved
const update = {} as Partial<User>;
update.alsoKnownAs = src.alsoKnownAs?.concat([dstUri]) ?? [dstUri];
update.alsoKnownAs = src.alsoKnownAs?.includes(dstUri) ? src.alsoKnownAs : src.alsoKnownAs?.concat([dstUri]) ?? [dstUri];
update.movedToUri = dstUri;
await this.usersRepository.update(src.id, update);
src = Object.assign(src, update);
@ -226,7 +226,7 @@ export class AccountMoveService {
} while (newJoinings.has(id));
return id;
};
for (const joining of oldJoinings) {
for (const joining of oldJoinings) {
newJoinings.set(genId(), {
createdAt: new Date(),
userId: dst.id,

View file

@ -760,6 +760,9 @@ export class ApInboxService {
} else if (!newAccount.alsoKnownAs?.includes(this.accountMoveService.getUserUri(oldAccount))) {
isValidMove = false;
}
if (newAccount.movedToUri) {
isValidMove = false;
}
if (!isValidMove) {
return 'skip: destination account invalid';
}

View file

@ -28,7 +28,7 @@ export const meta = {
errors: {
destinationAccountForbids: {
message:
'Destination account doesn\'t have proper \'Known As\' alias. Did you remember to set it?',
'Destination account doesn\'t have proper \'Known As\' alias, or has already moved.',
code: 'REMOTE_ACCOUNT_FORBIDS',
id: 'b5c90186-4ab0-49c8-9bba-a1f766282ba4',
},
@ -125,7 +125,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
// abort if unintended
if (!allowed) throw new ApiError(meta.errors.destinationAccountForbids);
if (!allowed || moveTo.movedToUri) throw new ApiError(meta.errors.destinationAccountForbids);
return await this.accountMoveService.moveFromLocal(me, moveTo);
});