2022-02-27 02:07:39 +00:00
|
|
|
import { Users } from '@/models/index.js';
|
2022-12-25 14:33:46 +00:00
|
|
|
import { ApiError } from '@/server/api/error.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { doPostSuspend } from '@/services/suspend-user.js';
|
|
|
|
import { publishUserEvent } from '@/services/stream.js';
|
|
|
|
import { createDeleteAccountJob } from '@/queue/index.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import define from '../../../define.js';
|
2021-09-22 08:34:48 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2021-09-22 08:34:48 +00:00
|
|
|
requireModerator: true,
|
2022-12-25 14:33:46 +00:00
|
|
|
|
|
|
|
errors: ['NO_SUCH_USER', 'IS_ADMIN', 'IS_MODERATOR'],
|
2022-02-19 05:05:32 +00:00
|
|
|
} as const;
|
2021-09-22 08:34:48 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
required: ['userId'],
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2021-09-22 08:34:48 +00:00
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2022-03-26 06:34:00 +00:00
|
|
|
const user = await Users.findOneBy({ id: ps.userId });
|
2021-09-22 08:34:48 +00:00
|
|
|
|
|
|
|
if (user == null) {
|
2022-12-25 14:33:46 +00:00
|
|
|
throw new ApiError('NO_SUCH_USER');
|
|
|
|
} else if (user.isAdmin) {
|
|
|
|
throw new ApiError('IS_ADMIN');
|
|
|
|
} else if(user.isModerator) {
|
|
|
|
throw new ApiError('IS_MODERATOR');
|
2021-09-22 08:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Users.isLocalUser(user)) {
|
|
|
|
// 物理削除する前にDelete activityを送信する
|
|
|
|
await doPostSuspend(user).catch(e => {});
|
|
|
|
|
|
|
|
createDeleteAccountJob(user, {
|
2021-12-09 14:58:30 +00:00
|
|
|
soft: false,
|
2021-09-22 08:34:48 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
createDeleteAccountJob(user, {
|
2021-12-09 14:58:30 +00:00
|
|
|
soft: true, // リモートユーザーの削除は、完全にDBから物理削除してしまうと再度連合してきてアカウントが復活する可能性があるため、soft指定する
|
2021-09-22 08:34:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await Users.update(user.id, {
|
|
|
|
isDeleted: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Users.isLocalUser(user)) {
|
|
|
|
// Terminate streaming
|
|
|
|
publishUserEvent(user.id, 'terminate', {});
|
|
|
|
}
|
|
|
|
});
|