implement admin/restart-migration endpoint
This commit is contained in:
parent
8310c128a8
commit
b3e41b74a1
5 changed files with 83 additions and 0 deletions
|
|
@ -87,6 +87,7 @@ export * as 'admin/relays/add' from './endpoints/admin/relays/add.js';
|
||||||
export * as 'admin/relays/list' from './endpoints/admin/relays/list.js';
|
export * as 'admin/relays/list' from './endpoints/admin/relays/list.js';
|
||||||
export * as 'admin/relays/remove' from './endpoints/admin/relays/remove.js';
|
export * as 'admin/relays/remove' from './endpoints/admin/relays/remove.js';
|
||||||
export * as 'admin/reset-password' from './endpoints/admin/reset-password.js';
|
export * as 'admin/reset-password' from './endpoints/admin/reset-password.js';
|
||||||
|
export * as 'admin/restart-migration' from './endpoints/admin/restart-migration.js';
|
||||||
export * as 'admin/resolve-abuse-user-report' from './endpoints/admin/resolve-abuse-user-report.js';
|
export * as 'admin/resolve-abuse-user-report' from './endpoints/admin/resolve-abuse-user-report.js';
|
||||||
export * as 'admin/roles/annotate-condition' from './endpoints/admin/roles/annotate-condition.js';
|
export * as 'admin/roles/annotate-condition' from './endpoints/admin/roles/annotate-condition.js';
|
||||||
export * as 'admin/roles/assign' from './endpoints/admin/roles/assign.js';
|
export * as 'admin/roles/assign' from './endpoints/admin/roles/assign.js';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
|
import { CacheService } from '@/core/CacheService.js';
|
||||||
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||||
|
import { AccountMoveService } from '@/core/AccountMoveService.js';
|
||||||
|
import { ApiError } from '@/server/api/error.js';
|
||||||
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
tags: ['admin'],
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
requireAdmin: true,
|
||||||
|
kind: 'write:admin:restart-migration',
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
accountHasNotMigrated: {
|
||||||
|
message: 'Account has not migrated anywhere.',
|
||||||
|
code: 'ACCOUNT_HAS_NOT_MIGRATED',
|
||||||
|
id: 'ddcf173a-00f2-4aa4-ba12-cddd131bacf4',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
res: {},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const paramDef = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
userId: { type: 'string', format: 'misskey:id' },
|
||||||
|
},
|
||||||
|
required: ['userId'],
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||||
|
constructor(
|
||||||
|
private readonly cacheService: CacheService,
|
||||||
|
private readonly moderationLogService: ModerationLogService,
|
||||||
|
private readonly accountMoveService: AccountMoveService,
|
||||||
|
) {
|
||||||
|
super(meta, paramDef, async (ps, me) => {
|
||||||
|
try {
|
||||||
|
const user = await this.cacheService.findUserById(ps.userId);
|
||||||
|
await this.accountMoveService.restartMigration(user);
|
||||||
|
|
||||||
|
await this.moderationLogService.log(me, 'restartMigration', {
|
||||||
|
userId: user.id,
|
||||||
|
userUsername: user.username,
|
||||||
|
userHost: user.host,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
// TODO allow this mapping stuff to be defined in the meta
|
||||||
|
if (err instanceof IdentifiableError && err.id === 'ddcf173a-00f2-4aa4-ba12-cddd131bacf4') {
|
||||||
|
throw new ApiError(meta.errors.accountHasNotMigrated);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -108,6 +108,7 @@ export const moderationLogTypes = [
|
||||||
'deleteGlobalAnnouncement',
|
'deleteGlobalAnnouncement',
|
||||||
'deleteUserAnnouncement',
|
'deleteUserAnnouncement',
|
||||||
'resetPassword',
|
'resetPassword',
|
||||||
|
'restartMigration',
|
||||||
'setMandatoryCW',
|
'setMandatoryCW',
|
||||||
'setMandatoryCWForNote',
|
'setMandatoryCWForNote',
|
||||||
'setMandatoryCWForInstance',
|
'setMandatoryCWForInstance',
|
||||||
|
|
@ -290,6 +291,11 @@ export type ModerationLogPayloads = {
|
||||||
userUsername: string;
|
userUsername: string;
|
||||||
userHost: string | null;
|
userHost: string | null;
|
||||||
};
|
};
|
||||||
|
restartMigration: {
|
||||||
|
userId: string;
|
||||||
|
userUsername: string;
|
||||||
|
userHost: string | null;
|
||||||
|
};
|
||||||
setMandatoryCW: {
|
setMandatoryCW: {
|
||||||
newCW: string | null;
|
newCW: string | null;
|
||||||
oldCW: string | null;
|
oldCW: string | null;
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ export const permissions = [
|
||||||
'write:admin:unset-user-banner',
|
'write:admin:unset-user-banner',
|
||||||
'write:admin:unsuspend-user',
|
'write:admin:unsuspend-user',
|
||||||
'write:admin:reject-quotes',
|
'write:admin:reject-quotes',
|
||||||
|
'write:admin:restart-migration',
|
||||||
'write:admin:meta',
|
'write:admin:meta',
|
||||||
'write:admin:user-note',
|
'write:admin:user-note',
|
||||||
'write:admin:roles',
|
'write:admin:roles',
|
||||||
|
|
@ -339,6 +340,11 @@ export type ModerationLogPayloads = {
|
||||||
userUsername: string;
|
userUsername: string;
|
||||||
userHost: string | null;
|
userHost: string | null;
|
||||||
};
|
};
|
||||||
|
restartMigration: {
|
||||||
|
userId: string;
|
||||||
|
userUsername: string;
|
||||||
|
userHost: string | null;
|
||||||
|
};
|
||||||
setMandatoryCW: {
|
setMandatoryCW: {
|
||||||
newCW: string | null;
|
newCW: string | null;
|
||||||
oldCW: string | null;
|
oldCW: string | null;
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,9 @@ export type ModerationLog = {
|
||||||
} | {
|
} | {
|
||||||
type: 'setMandatoryCWForInstance';
|
type: 'setMandatoryCWForInstance';
|
||||||
info: ModerationLogPayloads['setMandatoryCWForInstance'];
|
info: ModerationLogPayloads['setMandatoryCWForInstance'];
|
||||||
|
} | {
|
||||||
|
type: 'restartMigration';
|
||||||
|
info: ModerationLogPayloads['restartMigration'];
|
||||||
} | {
|
} | {
|
||||||
type: 'resetPassword';
|
type: 'resetPassword';
|
||||||
info: ModerationLogPayloads['resetPassword'];
|
info: ModerationLogPayloads['resetPassword'];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue