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