Skip to content

Commit

Permalink
Merge pull request #1066 from atsu1125/admindeleteaccout
Browse files Browse the repository at this point in the history
管理者がユーザーのアカウントを削除する機能
  • Loading branch information
fs5m8 authored Dec 30, 2022
2 parents 62b067f + 94b8b87 commit 025673e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
2 changes: 2 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,8 @@ admin/views/users.vue:
remote-user-updated: "The information regarding the remote user has been updated."
delete-all-files: "Delete all files"
delete-all-files-confirm: "Are you sure that you want to delete all files?"
delete-account: "Delete Account"
delete-account-confirm: "Are you sure that you want to delete this account?"
username: "Username"
host: "Host"
users:
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,8 @@ admin/views/users.vue:
remote-user-updated: "リモートユーザー情報を更新しました"
delete-all-files: "すべてのファイルを削除"
delete-all-files-confirm: "すべてのファイルを削除しますか?"
delete-account: "アカウントを削除"
delete-account-confirm: "このアカウントを削除しますか?"
username: "ユーザー名"
host: "ホスト"
users:
Expand Down
27 changes: 26 additions & 1 deletion src/client/app/admin/views/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
<ui-button @click="unsilenceUser">{{ $t('unmake-silence') }}</ui-button>
</ui-horizon-group>
<ui-horizon-group>
<ui-button @click="suspendUser" :disabled="suspending"><fa :icon="faSnowflake"/> {{ $t('suspend') }}</ui-button>
<ui-button @click="suspendUser" :disabled="suspending || user.isModerator || user.isAdmin"><fa :icon="faSnowflake"/> {{ $t('suspend') }}</ui-button>
<ui-button @click="unsuspendUser" :disabled="unsuspending">{{ $t('unsuspend') }}</ui-button>
</ui-horizon-group>
<ui-button @click="deleteAllFiles"><fa :icon="faTrashAlt"/> {{ $t('delete-all-files') }}</ui-button>
<ui-button @click="deleteAccount" :disabled="deleting || user.isModerator || user.isAdmin"><fa :icon="faTrashAlt"/> {{ $t('delete-account') }}</ui-button>
<ui-textarea v-if="user" :value="user | json5" readonly tall style="margin-top:16px;"></ui-textarea>
</div>
</div>
Expand Down Expand Up @@ -102,6 +103,7 @@ export default Vue.extend({
unverifying: false,
suspending: false,
unsuspending: false,
deleting: false,
sort: '+createdAt',
state: 'all',
origin: 'local',
Expand Down Expand Up @@ -409,6 +411,29 @@ export default Vue.extend({
});
},
async deleteAccount() {
if (!await this.getConfirmed(this.$t('delete-account-confirm'))) return;
this.deleting = true;
const process = async () => {
await this.$root.api('admin/delete-account', { userId: this.user.id });
this.$root.dialog({
type: 'success',
splash: true
});
};
await process().catch(e => {
this.$root.dialog({
type: 'error',
text: e.message
});
});
this.deleting = false;
},
async getConfirmed(text: string): Promise<Boolean> {
const confirm = await this.$root.dialog({
type: 'warning',
Expand Down
68 changes: 68 additions & 0 deletions src/server/api/endpoints/admin/delete-account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import $ from 'cafy';
import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { Users } from '../../../../models';
import { insertModerationLog } from '../../../../services/insert-moderation-log';
import { doPostSuspend } from '../../../../services/suspend-user';
import { publishTerminate } from '../../../../services/server-event';
import { createDeleteAccountJob } from '../../../../queue';

export const meta = {
desc: {
'ja-JP': '指定したユーザーを削除します。',
'en-US': 'Delete a user.'
},

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 suspend admin');
}

if (user.isModerator) {
throw new Error('cannot suspend 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,
});

if (Users.isLocalUser(user)) {
publishTerminate(user.id);
}

});

0 comments on commit 025673e

Please sign in to comment.