From 23c9f6a6ca1ba938a6a2a7c9f5e1007d47fd28c5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 15 May 2019 20:41:01 +0900 Subject: [PATCH] Resolve #4833 --- locales/ja-JP.yml | 2 ++ src/client/app/admin/views/users.vue | 28 +++++++++++++--- .../admin/delete-all-files-of-a-user.ts | 32 +++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/server/api/endpoints/admin/delete-all-files-of-a-user.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 91edb82e0d..76c1ab8269 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1365,6 +1365,8 @@ admin/views/users.vue: unsilence-confirm: "サイレンスを解除しますか?" update-remote-user: "リモートユーザー情報の更新" remote-user-updated: "リモートユーザー情報を更新しました" + delete-all-files: "すべてのファイルを削除" + delete-all-files-confirm: "すべてのファイルを削除しますか?" users: title: "ユーザー" sort: diff --git a/src/client/app/admin/views/users.vue b/src/client/app/admin/views/users.vue index cc38108532..fd9f0dd8b2 100644 --- a/src/client/app/admin/views/users.vue +++ b/src/client/app/admin/views/users.vue @@ -9,8 +9,9 @@ {{ $t('lookup') }}
- +
+ {{ $t('update-remote-user') }} {{ $t('reset-password') }} {{ $t('make-silence') }} @@ -20,7 +21,7 @@ {{ $t('suspend') }} {{ $t('unsuspend') }} - {{ $t('update-remote-user') }} + {{ $t('delete-all-files') }}
@@ -67,7 +68,7 @@ import Vue from 'vue'; import i18n from '../../i18n'; import parseAcct from "../../../../misc/acct/parse"; import { faUsers, faTerminal, faSearch, faKey, faSync, faMicrophoneSlash } from '@fortawesome/free-solid-svg-icons'; -import { faSnowflake } from '@fortawesome/free-regular-svg-icons'; +import { faSnowflake, faTrashAlt } from '@fortawesome/free-regular-svg-icons'; import XUser from './users.user.vue'; export default Vue.extend({ @@ -88,7 +89,7 @@ export default Vue.extend({ offset: 0, users: [], existMore: false, - faTerminal, faUsers, faSnowflake, faSearch, faKey, faSync, faMicrophoneSlash + faTerminal, faUsers, faSnowflake, faSearch, faKey, faSync, faMicrophoneSlash, faTrashAlt }; }, @@ -277,6 +278,25 @@ export default Vue.extend({ this.refreshUser(); }, + async deleteAllFiles() { + if (!await this.getConfirmed(this.$t('delete-all-files-confirm'))) return; + + const process = async () => { + await this.$root.api('admin/delete-all-files-of-a-user', { userId: this.user.id }); + this.$root.dialog({ + type: 'success', + splash: true + }); + }; + + await process().catch(e => { + this.$root.dialog({ + type: 'error', + text: e.toString() + }); + }); + }, + async getConfirmed(text: string): Promise { const confirm = await this.$root.dialog({ type: 'warning', diff --git a/src/server/api/endpoints/admin/delete-all-files-of-a-user.ts b/src/server/api/endpoints/admin/delete-all-files-of-a-user.ts new file mode 100644 index 0000000000..84e9c363e1 --- /dev/null +++ b/src/server/api/endpoints/admin/delete-all-files-of-a-user.ts @@ -0,0 +1,32 @@ +import $ from 'cafy'; +import define from '../../define'; +import del from '../../../../services/drive/delete-file'; +import { DriveFiles } from '../../../../models'; +import { ID } from '../../../../misc/cafy-id'; + +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 suspend' + } + }, + } +}; + +export default define(meta, async (ps, me) => { + const files = await DriveFiles.find({ + userId: ps.userId + }); + + for (const file of files) { + del(file); + } +});