forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/backend/src/server/api/endpoints/admin/delete-account.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Users } from '@/models/index'; | ||
import $ from 'cafy'; | ||
import define from '../../define'; | ||
import { createDeleteAccountJob } from '@/queue'; | ||
import { ID } from '@/misc/cafy-id'; | ||
import { doPostSuspend } from '@/services/suspend-user'; | ||
import { publishUserEvent } from '@/services/stream'; | ||
import { insertModerationLog } from '@/services/insert-moderation-log'; | ||
|
||
export const meta = { | ||
tags: ['admin'], | ||
|
||
requireCredential: true, | ||
requireModerator: true, | ||
|
||
params: { | ||
userId: { | ||
validator: $.type(ID), | ||
desc: { | ||
'ja-JP': '対象のユーザーID', | ||
'en-US': 'The user ID which you want to delete' | ||
} | ||
}, | ||
} | ||
}; | ||
|
||
export default define(meta, async (ps, me) => { | ||
const user = await Users.findOne(ps.userId as string); | ||
|
||
if (user == null) { | ||
throw new Error('user not found'); | ||
} | ||
|
||
if (user.isAdmin) { | ||
throw new Error('cannot delete admin'); | ||
} | ||
|
||
if (user.isModerator) { | ||
throw new Error('cannot delete moderator'); | ||
} | ||
|
||
if (user.isDeleted) { | ||
return; | ||
} | ||
|
||
// 物理削除する前にDelete activityを送信する | ||
await doPostSuspend(user).catch(e => {}); | ||
|
||
createDeleteAccountJob(user); | ||
|
||
await Users.update(user.id, { | ||
isDeleted: true, | ||
}); | ||
|
||
insertModerationLog(me, 'delete', { | ||
targetId: user.id, | ||
}); | ||
|
||
// Terminate streaming | ||
publishUserEvent(user.id, 'terminate', {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters