2021-09-22 08:34:48 +00:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../../define';
|
|
|
|
import { Users } from '@/models/index';
|
|
|
|
import { doPostSuspend } from '@/services/suspend-user';
|
|
|
|
import { publishUserEvent } from '@/services/stream';
|
|
|
|
import { createDeleteAccountJob } from '@/queue';
|
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
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
|
2021-09-22 08:34:48 +00:00
|
|
|
export default define(meta, async (ps, me) => {
|
|
|
|
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 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', {});
|
|
|
|
}
|
|
|
|
});
|