mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 06:00:21 +01:00
fix checking alsoKnownAs and uri
This commit is contained in:
parent
33851fbab6
commit
0e088cb2e4
2 changed files with 15 additions and 10 deletions
|
@ -74,12 +74,12 @@ export class AccountMoveService {
|
|||
*/
|
||||
@bindThis
|
||||
public async moveFromLocal(src: LocalUser, dst: User): Promise<unknown> {
|
||||
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<User>;
|
||||
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);
|
||||
|
|
|
@ -109,22 +109,27 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue