mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 15:43:18 +02:00
fetch person again (#10514)
This commit is contained in:
parent
0f328e8472
commit
e23cf77f86
2 changed files with 23 additions and 15 deletions
|
@ -736,13 +736,17 @@ export class ApInboxService {
|
||||||
// fetch the new and old accounts
|
// fetch the new and old accounts
|
||||||
const targetUri = getApHrefNullable(activity.target);
|
const targetUri = getApHrefNullable(activity.target);
|
||||||
if (!targetUri) return 'skip: invalid activity target';
|
if (!targetUri) return 'skip: invalid activity target';
|
||||||
const new_acc = await this.apPersonService.resolvePerson(targetUri);
|
let new_acc = await this.apPersonService.resolvePerson(targetUri);
|
||||||
const old_acc = await this.apPersonService.resolvePerson(actor.uri);
|
let old_acc = await this.apPersonService.resolvePerson(actor.uri);
|
||||||
|
|
||||||
// update them if they're remote
|
// update them if they're remote
|
||||||
if (new_acc.uri) await this.apPersonService.updatePerson(new_acc.uri);
|
if (new_acc.uri) await this.apPersonService.updatePerson(new_acc.uri);
|
||||||
if (old_acc.uri) await this.apPersonService.updatePerson(old_acc.uri);
|
if (old_acc.uri) await this.apPersonService.updatePerson(old_acc.uri);
|
||||||
|
|
||||||
|
// retrieve updated users
|
||||||
|
new_acc = await this.apPersonService.resolvePerson(targetUri);
|
||||||
|
old_acc = await this.apPersonService.resolvePerson(actor.uri);
|
||||||
|
|
||||||
// check if alsoKnownAs of the new account is valid
|
// check if alsoKnownAs of the new account is valid
|
||||||
let isValidMove = true;
|
let isValidMove = true;
|
||||||
if (old_acc.uri) {
|
if (old_acc.uri) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ export const meta = {
|
||||||
id: '4362f8dc-731f-4ad8-a694-be2a88922a24',
|
id: '4362f8dc-731f-4ad8-a694-be2a88922a24',
|
||||||
},
|
},
|
||||||
rootForbidden: {
|
rootForbidden: {
|
||||||
message: 'The root cant migrate.',
|
message: 'The root can\'t migrate.',
|
||||||
code: 'NOT_ROOT_FORBIDDEN',
|
code: 'NOT_ROOT_FORBIDDEN',
|
||||||
id: '4362e8dc-731f-4ad8-a694-be2a88922a24',
|
id: '4362e8dc-731f-4ad8-a694-be2a88922a24',
|
||||||
},
|
},
|
||||||
|
@ -92,42 +92,46 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private apPersonService: ApPersonService,
|
private apPersonService: ApPersonService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
// Check parameter
|
// check parameter
|
||||||
if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchMoveTarget);
|
if (!ps.moveToAccount) throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||||
// Abort if user is the root
|
// abort if user is the root
|
||||||
if (me.isRoot) throw new ApiError(meta.errors.rootForbidden);
|
if (me.isRoot) throw new ApiError(meta.errors.rootForbidden);
|
||||||
// Abort if user has already moved
|
// abort if user has already moved
|
||||||
if (me.movedToUri) throw new ApiError(meta.errors.alreadyMoved);
|
if (me.movedToUri) throw new ApiError(meta.errors.alreadyMoved);
|
||||||
|
|
||||||
let unfiltered = ps.moveToAccount;
|
let unfiltered = ps.moveToAccount;
|
||||||
if (!unfiltered) throw new ApiError(meta.errors.noSuchMoveTarget);
|
if (!unfiltered) throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||||
|
|
||||||
// Parse user's input into the destination account
|
// parse user's input into the destination account
|
||||||
if (unfiltered.startsWith('acct:')) unfiltered = unfiltered.substring(5);
|
if (unfiltered.startsWith('acct:')) unfiltered = unfiltered.substring(5);
|
||||||
if (unfiltered.startsWith('@')) unfiltered = unfiltered.substring(1);
|
if (unfiltered.startsWith('@')) unfiltered = unfiltered.substring(1);
|
||||||
if (!unfiltered.includes('@')) throw new ApiError(meta.errors.notRemote);
|
if (!unfiltered.includes('@')) throw new ApiError(meta.errors.notRemote);
|
||||||
|
|
||||||
const userAddress = unfiltered.split('@');
|
const userAddress = unfiltered.split('@');
|
||||||
// Retrieve the destination account
|
// retrieve the destination account
|
||||||
const remoteMoveTo = await this.remoteUserResolveService.resolveUser(userAddress[0], userAddress[1]).catch((e) => {
|
let moveTo = await this.remoteUserResolveService.resolveUser(userAddress[0], userAddress[1]).catch((e) => {
|
||||||
this.apiLoggerService.logger.warn(`failed to resolve remote user: ${e}`);
|
this.apiLoggerService.logger.warn(`failed to resolve remote user: ${e}`);
|
||||||
throw new ApiError(meta.errors.noSuchMoveTarget);
|
throw new ApiError(meta.errors.noSuchMoveTarget);
|
||||||
});
|
});
|
||||||
const moveTo = await this.getterService.getRemoteUser(remoteMoveTo.id);
|
const remoteMoveTo = await this.getterService.getRemoteUser(moveTo.id);
|
||||||
if (!moveTo.uri) throw new ApiError(meta.errors.uriNull);
|
if (!remoteMoveTo.uri) throw new ApiError(meta.errors.uriNull);
|
||||||
await this.apPersonService.updatePerson(moveTo.uri);
|
|
||||||
// Only allow moving to a remote account
|
// update local db
|
||||||
|
await this.apPersonService.updatePerson(remoteMoveTo.uri);
|
||||||
|
// retrieve updated user
|
||||||
|
moveTo = await this.apPersonService.resolvePerson(remoteMoveTo.uri);
|
||||||
|
// only allow moving to a remote account
|
||||||
if (this.userEntityService.isLocalUser(moveTo)) throw new ApiError(meta.errors.notRemote);
|
if (this.userEntityService.isLocalUser(moveTo)) throw new ApiError(meta.errors.notRemote);
|
||||||
|
|
||||||
let allowed = false;
|
let allowed = false;
|
||||||
|
|
||||||
const fromUrl = `${this.config.url}/users/${me.id}`;
|
const fromUrl = `${this.config.url}/users/${me.id}`;
|
||||||
// Make sure that the user has indicated the old account as an alias
|
// make sure that the user has indicated the old account as an alias
|
||||||
moveTo.alsoKnownAs?.forEach((elem) => {
|
moveTo.alsoKnownAs?.forEach((elem) => {
|
||||||
if (fromUrl.includes(elem)) allowed = true;
|
if (fromUrl.includes(elem)) allowed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Abort if unintended
|
// abort if unintended
|
||||||
if (!(allowed && moveTo.uri && fromUrl)) throw new ApiError(meta.errors.remoteAccountForbids);
|
if (!(allowed && moveTo.uri && fromUrl)) throw new ApiError(meta.errors.remoteAccountForbids);
|
||||||
|
|
||||||
return await this.accountMoveService.moveToRemote(me, moveTo);
|
return await this.accountMoveService.moveToRemote(me, moveTo);
|
||||||
|
|
Loading…
Reference in a new issue