Skip to content

Commit

Permalink
Merge pull request #1124 from atsu1125/modpatch3
Browse files Browse the repository at this point in the history
モデレータ権限変更(ファイル全削除)
  • Loading branch information
fs5m8 authored Feb 10, 2023
2 parents 76da3b7 + 49051f8 commit 827cf4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client/app/admin/views/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<x-user :user="user"/>
<div class="actions">
<ui-button v-if="user.host != null" @click="updateRemoteUser"><fa :icon="faSync"/> {{ $t('update-remote-user') }}</ui-button>
<ui-button @click="resetPassword"><fa :icon="faKey"/> {{ $t('reset-password') }}</ui-button>
<ui-button @click="resetPassword" :disabled="user.isAdmin"><fa :icon="faKey"/> {{ $t('reset-password') }}</ui-button>
<ui-horizon-group>
<ui-button @click="setPremium" :disabled="changing"><fa :icon="faCrown"/> {{ $t('premium') }}</ui-button>
<ui-button @click="unsetPremium" :disabled="changing">{{ $t('unpremium') }}</ui-button>
Expand All @@ -29,7 +29,7 @@
<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="deleteAllFiles" :disabled="(user.isModerator && !$store.getters.isAdmin) || user.isAdmin"><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>
Expand Down
12 changes: 11 additions & 1 deletion src/server/api/endpoints/admin/delete-all-files-of-a-user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $ from 'cafy';
import define from '../../define';
import { deleteFile } from '../../../../services/drive/delete-file';
import { DriveFiles } from '../../../../models';
import { DriveFiles, Users } from '../../../../models';
import { ID } from '../../../../misc/cafy-id';

export const meta = {
Expand All @@ -26,6 +26,16 @@ export default define(meta, async (ps, me) => {
userId: ps.userId
});

const user = await Users.findOne(ps.userId as string);

if (user.isAdmin) {
throw new Error('cannot delete files of admin');
}

if (me.isModerator && user.isModerator) {
throw new Error('cannot delete files of moderator');
}

for (const file of files) {
deleteFile(file);
}
Expand Down

0 comments on commit 827cf4b

Please sign in to comment.