Skip to content

Commit

Permalink
Feat: Admin delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 30, 2022
1 parent 41bd7fb commit 9131844
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ disablePagesScript: "Disable AiScript on Pages"
updateRemoteUser: "Update remote user information"
deleteAllFiles: "Delete All Files"
deleteAllFilesConfirm: "Are you sure that you want to delete all files?"
deleteAccount: "Delete Account"
removeAllFollowing: "Unfollow all followed users"
removeAllFollowingDescription: "Executing this unfollows all accounts from {host}. Please run this if the instance e.g. no longer exists."
userSuspended: "This user has been suspended."
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ disablePagesScript: "Pagesのスクリプトを無効にする"
updateRemoteUser: "リモートユーザー情報の更新"
deleteAllFiles: "すべてのファイルを削除"
deleteAllFilesConfirm: "すべてのファイルを削除しますか?"
deleteAccount: "アカウントを削除"
removeAllFollowing: "フォローを全解除"
removeAllFollowingDescription: "{host}からのフォローをすべて解除します。そのインスタンスがもう存在しなくなった場合などに実行してください。"
userSuspended: "このユーザーは凍結されています。"
Expand Down
61 changes: 61 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/delete-account.ts
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', {});
});
20 changes: 20 additions & 0 deletions packages/client/src/pages/user-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<FormSwitch v-model="suspended" class="_formBlock" @update:modelValue="toggleSuspend">{{ $ts.suspend }}</FormSwitch>
<FormButton v-if="user.host == null && iAmModerator" class="_formBlock" @click="resetPassword"><i class="fas fa-key"></i> {{ $ts.resetPassword }}</FormButton>
<FormButton v-if="iAmModerator" class="_formBlock" @click="deleteAllFiles"><i class="fas fa-trash-alt"></i> {{ $ts.deleteAllFiles }}</FormButton>
<FormButton v-if="iAmModerator && (!user.isModerator && !user.isAdmin)" class="_formBlock" @click="deleteAccount"><i class="fas fa-trash-alt"></i> {{ $ts.deleteAccount }}</FormButton>
</FormSection>

<FormSection>
Expand Down Expand Up @@ -240,6 +241,25 @@ export default defineComponent({
});
await this.refreshUser();
},
async deleteAccount() {
const confirm = await os.confirm({
type: 'warning',
text: this.$ts.deleteAccountConfirm,
});
if (confirm.canceled) return;
const process = async () => {
await os.api('admin/delete-account', { userId: this.user.id });
os.success();
};
await process().catch(e => {
os.alert({
type: 'error',
text: e.toString()
});
});
await this.refreshUser();
},
}
});
</script>
Expand Down

0 comments on commit 9131844

Please sign in to comment.