This commit is contained in:
tamaina 2023-05-29 14:09:13 +00:00
parent e1b4a0438e
commit 94f25d9cdd
3 changed files with 161 additions and 132 deletions

View file

@ -4,34 +4,17 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { DeleteAccountService } from '@/core/DeleteAccountService.js'; import { DeleteAccountService } from '@/core/DeleteAccountService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireAdmin: true,
res: {
},
} as const;
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/delete-account'> {
name = 'admin/delete-account' as const;
constructor( constructor(
@Inject(DI.usersRepository) @Inject(DI.usersRepository)
private usersRepository: UsersRepository, private usersRepository: UsersRepository,
private deleteAccountService: DeleteAccountService, private deleteAccountService: DeleteAccountService,
) { ) {
super(meta, paramDef, async (ps) => { super(async (ps) => {
const user = await this.usersRepository.findOneByOrFail({ id: ps.userId }); const user = await this.usersRepository.findOneByOrFail({ id: ps.userId });
if (user.isDeleted) { if (user.isDeleted) {
return; return;

View file

@ -4,31 +4,17 @@ import type { DriveFilesRepository } from '@/models/index.js';
import { DriveService } from '@/core/DriveService.js'; import { DriveService } from '@/core/DriveService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireAdmin: true,
} as const;
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/delete-all-files-of-a-user'> {
name = 'admin/delete-all-files-of-a-user' as const;
constructor( constructor(
@Inject(DI.driveFilesRepository) @Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository, private driveFilesRepository: DriveFilesRepository,
private driveService: DriveService, private driveService: DriveService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const files = await this.driveFilesRepository.findBy({ const files = await this.driveFilesRepository.findBy({
userId: ps.userId, userId: ps.userId,
}); });

View file

@ -30,7 +30,7 @@ export const endpoints = {
}, },
'admin/accounts/delete': { 'admin/accounts/delete': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireAdmin: true, requireAdmin: true,
defines: [{ defines: [{
@ -95,7 +95,7 @@ export const endpoints = {
}, },
'admin/ad/list': { 'admin/ad/list': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -227,10 +227,10 @@ export const endpoints = {
}, },
'admin/announcements/update': { 'admin/announcements/update': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchAnnouncement: { noSuchAnnouncement: {
message: 'No such announcement.', message: 'No such announcement.',
@ -260,7 +260,7 @@ export const endpoints = {
}, },
'admin/drive/clean-remote-files': { 'admin/drive/clean-remote-files': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -282,7 +282,7 @@ export const endpoints = {
}, },
'admin/drive/files': { 'admin/drive/files': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -329,10 +329,10 @@ export const endpoints = {
}, },
'admin/drive/show-file': { 'admin/drive/show-file': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchFile: { noSuchFile: {
message: 'No such file.', message: 'No such file.',
@ -358,7 +358,7 @@ export const endpoints = {
properties: { properties: {
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
createdAt: { type: 'string', format: 'date-time' }, createdAt: { type: 'string', format: 'date-time' },
userId: { userId: {
oneOf: [ oneOf: [
{ $ref: 'https://misskey-hub.net/api/schemas/Id' }, { $ref: 'https://misskey-hub.net/api/schemas/Id' },
{ type: 'null' }, { type: 'null' },
@ -455,12 +455,16 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
aliases: { type: 'array', items: { }
type: 'string', },
} }, aliases: {
type: 'array', items: {
type: 'string',
}
},
}, },
required: ['ids', 'aliases'], required: ['ids', 'aliases'],
}, },
@ -491,15 +495,19 @@ export const endpoints = {
type: ['string', 'null'], type: ['string', 'null'],
description: 'Use `null` to reset the category.', description: 'Use `null` to reset the category.',
}, },
aliases: { type: 'array', items: { aliases: {
type: 'string', type: 'array', items: {
} }, type: 'string',
}
},
license: { type: ['string', 'null'] }, license: { type: ['string', 'null'] },
isSensitive: { type: 'boolean' }, isSensitive: { type: 'boolean' },
localOnly: { type: 'boolean' }, localOnly: { type: 'boolean' },
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: { roleIdsThatCanBeUsedThisEmojiAsReaction: {
type: 'string', type: 'array', items: {
} }, type: 'string',
}
},
}, },
required: ['name', 'fileId'], required: ['name', 'fileId'],
}, },
@ -553,9 +561,11 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
}
},
}, },
required: ['ids'], required: ['ids'],
}, },
@ -564,10 +574,10 @@ export const endpoints = {
}, },
'admin/emoji/delete': { 'admin/emoji/delete': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireRolePolicy: 'canManageCustomEmojis', requireRolePolicy: 'canManageCustomEmojis',
errors: { errors: {
noSuchEmoji: { noSuchEmoji: {
message: 'No such emoji.', message: 'No such emoji.',
@ -668,12 +678,16 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
aliases: { type: 'array', items: { }
type: 'string', },
} }, aliases: {
type: 'array', items: {
type: 'string',
}
},
}, },
required: ['ids', 'aliases'], required: ['ids', 'aliases'],
}, },
@ -682,7 +696,7 @@ export const endpoints = {
}, },
'admin/emoji/set-aliases-bulk': { 'admin/emoji/set-aliases-bulk': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireRolePolicy: 'canManageCustomEmojis', requireRolePolicy: 'canManageCustomEmojis',
@ -690,12 +704,16 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
aliases: { type: 'array', items: { }
type: 'string', },
} }, aliases: {
type: 'array', items: {
type: 'string',
}
},
}, },
required: ['ids', 'aliases'], required: ['ids', 'aliases'],
}, },
@ -704,7 +722,7 @@ export const endpoints = {
}, },
'admin/emoji/set-category-bulk': { 'admin/emoji/set-category-bulk': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireRolePolicy: 'canManageCustomEmojis', requireRolePolicy: 'canManageCustomEmojis',
@ -712,9 +730,11 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
}
},
category: { category: {
type: ['string', 'null'], type: ['string', 'null'],
description: 'Use `null` to reset the category.', description: 'Use `null` to reset the category.',
@ -727,7 +747,7 @@ export const endpoints = {
}, },
'admin/emoji/set-license-bulk': { 'admin/emoji/set-license-bulk': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireRolePolicy: 'canManageCustomEmojis', requireRolePolicy: 'canManageCustomEmojis',
@ -735,9 +755,11 @@ export const endpoints = {
req: { req: {
type: 'object', type: 'object',
properties: { properties: {
ids: { type: 'array', items: { ids: {
type: 'string', format: 'misskey:id', type: 'array', items: {
} }, type: 'string', format: 'misskey:id',
}
},
license: { license: {
type: ['string', 'null'], type: ['string', 'null'],
description: 'Use `null` to reset the license.', description: 'Use `null` to reset the license.',
@ -750,10 +772,10 @@ export const endpoints = {
}, },
'admin/emoji/update': { 'admin/emoji/update': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireRolePolicy: 'canManageCustomEmojis', requireRolePolicy: 'canManageCustomEmojis',
errors: { errors: {
noSuchFile: { noSuchFile: {
message: 'No such file.', message: 'No such file.',
@ -773,15 +795,19 @@ export const endpoints = {
type: ['string', 'null'], type: ['string', 'null'],
description: 'Use `null` to reset the category.', description: 'Use `null` to reset the category.',
}, },
aliases: { type: 'array', items: { aliases: {
type: 'string', type: 'array', items: {
} }, type: 'string',
}
},
license: { type: ['string', 'null'] }, license: { type: ['string', 'null'] },
isSensitive: { type: 'boolean' }, isSensitive: { type: 'boolean' },
localOnly: { type: 'boolean' }, localOnly: { type: 'boolean' },
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: { roleIdsThatCanBeUsedThisEmojiAsReaction: {
type: 'string', type: 'array', items: {
} }, type: 'string',
}
},
}, },
required: ['id', 'name', 'aliases'], required: ['id', 'name', 'aliases'],
}, },
@ -790,7 +816,7 @@ export const endpoints = {
}, },
'admin/federation/delete-all-files': { 'admin/federation/delete-all-files': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -807,7 +833,7 @@ export const endpoints = {
}, },
'admin/federation/refresh-remote-instance-metadata': { 'admin/federation/refresh-remote-instance-metadata': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -824,7 +850,7 @@ export const endpoints = {
}, },
'admin/federation/remove-all-following': { 'admin/federation/remove-all-following': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -841,7 +867,7 @@ export const endpoints = {
}, },
'admin/federation/update-instance': { 'admin/federation/update-instance': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -859,17 +885,17 @@ export const endpoints = {
}, },
'admin/promo/create': { 'admin/promo/create': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchNote: { noSuchNote: {
message: 'No such note.', message: 'No such note.',
code: 'NO_SUCH_NOTE', code: 'NO_SUCH_NOTE',
id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc', id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc',
}, },
alreadyPromoted: { alreadyPromoted: {
message: 'The note has already promoted.', message: 'The note has already promoted.',
code: 'ALREADY_PROMOTED', code: 'ALREADY_PROMOTED',
@ -891,7 +917,7 @@ export const endpoints = {
}, },
'admin/queue/clear': { 'admin/queue/clear': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -902,7 +928,7 @@ export const endpoints = {
}, },
'admin/queue/deliver-delayed': { 'admin/queue/deliver-delayed': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -932,7 +958,7 @@ export const endpoints = {
}, },
'admin/queue/inbox-delayed': { 'admin/queue/inbox-delayed': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -962,7 +988,7 @@ export const endpoints = {
}, },
'admin/queue/promote': { 'admin/queue/promote': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -979,10 +1005,10 @@ export const endpoints = {
}, },
'admin/queue/stats': { 'admin/queue/stats': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
defines: [{ defines: [{
req: undefined, req: undefined,
res: { res: {
@ -999,10 +1025,10 @@ export const endpoints = {
}, },
'admin/relays/add': { 'admin/relays/add': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
invalidUrl: { invalidUrl: {
message: 'Invalid URL', message: 'Invalid URL',
@ -1010,7 +1036,7 @@ export const endpoints = {
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c', id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
}, },
}, },
defines: [{ defines: [{
req: { req: {
type: 'object', type: 'object',
@ -1026,7 +1052,7 @@ export const endpoints = {
}, },
'admin/relays/list': { 'admin/relays/list': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -1042,7 +1068,7 @@ export const endpoints = {
}, },
'admin/relays/remove': { 'admin/relays/remove': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -1059,23 +1085,23 @@ export const endpoints = {
}, },
'admin/roles/assign': { 'admin/roles/assign': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
code: 'NO_SUCH_ROLE', code: 'NO_SUCH_ROLE',
id: '6503c040-6af4-4ed9-bf07-f2dd16678eab', id: '6503c040-6af4-4ed9-bf07-f2dd16678eab',
}, },
noSuchUser: { noSuchUser: {
message: 'No such user.', message: 'No such user.',
code: 'NO_SUCH_USER', code: 'NO_SUCH_USER',
id: '558ea170-f653-4700-94d0-5a818371d0df', id: '558ea170-f653-4700-94d0-5a818371d0df',
}, },
accessDenied: { accessDenied: {
message: 'Only administrators can edit members of the role.', message: 'Only administrators can edit members of the role.',
code: 'ACCESS_DENIED', code: 'ACCESS_DENIED',
@ -1103,7 +1129,7 @@ export const endpoints = {
}, },
'admin/roles/create': { 'admin/roles/create': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireAdmin: true, requireAdmin: true,
@ -1151,10 +1177,10 @@ export const endpoints = {
}, },
'admin/roles/delete': { 'admin/roles/delete': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireAdmin: true, requireAdmin: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
@ -1178,7 +1204,7 @@ export const endpoints = {
}, },
'admin/roles/list': { 'admin/roles/list': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
@ -1194,10 +1220,10 @@ export const endpoints = {
}, },
'admin/roles/show': { 'admin/roles/show': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
@ -1223,29 +1249,29 @@ export const endpoints = {
}, },
'admin/roles/unassign': { 'admin/roles/unassign': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
code: 'NO_SUCH_ROLE', code: 'NO_SUCH_ROLE',
id: '6e519036-a70d-4c76-b679-bc8fb18194e2', id: '6e519036-a70d-4c76-b679-bc8fb18194e2',
}, },
noSuchUser: { noSuchUser: {
message: 'No such user.', message: 'No such user.',
code: 'NO_SUCH_USER', code: 'NO_SUCH_USER',
id: '2b730f78-1179-461b-88ad-d24c9af1a5ce', id: '2b730f78-1179-461b-88ad-d24c9af1a5ce',
}, },
notAssigned: { notAssigned: {
message: 'Not assigned.', message: 'Not assigned.',
code: 'NOT_ASSIGNED', code: 'NOT_ASSIGNED',
id: 'b9060ac7-5c94-4da4-9f55-2047c953df44', id: 'b9060ac7-5c94-4da4-9f55-2047c953df44',
}, },
accessDenied: { accessDenied: {
message: 'Only administrators can edit members of the role.', message: 'Only administrators can edit members of the role.',
code: 'ACCESS_DENIED', code: 'ACCESS_DENIED',
@ -1270,7 +1296,7 @@ export const endpoints = {
}, },
'admin/roles/update-default-policies': { 'admin/roles/update-default-policies': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireAdmin: true, requireAdmin: true,
@ -1291,10 +1317,10 @@ export const endpoints = {
}, },
'admin/roles/update': { 'admin/roles/update': {
tags: ['admin', 'role'], tags: ['admin', 'role'],
requireCredential: true, requireCredential: true,
requireAdmin: true, requireAdmin: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
@ -1347,10 +1373,10 @@ export const endpoints = {
}, },
'admin/roles/users': { 'admin/roles/users': {
tags: ['admin', 'role', 'users'], tags: ['admin', 'role', 'users'],
requireCredential: false, requireCredential: false,
requireAdmin: true, requireAdmin: true,
errors: { errors: {
noSuchRole: { noSuchRole: {
message: 'No such role.', message: 'No such role.',
@ -1380,10 +1406,10 @@ export const endpoints = {
}, },
'admin/abuse-user-reports': { 'admin/abuse-user-reports': {
tags: ['admin'], tags: ['admin'],
requireCredential: true, requireCredential: true,
requireModerator: true, requireModerator: true,
defines: [{ defines: [{
req: { req: {
type: 'object', type: 'object',
@ -1406,6 +1432,40 @@ export const endpoints = {
}, },
}], }],
}, },
'admin/delete-account': {
tags: ['admin'],
requireCredential: true,
requireAdmin: true,
defines: [{
req: {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
},
res: undefined,
}],
},
'admin/delete-all-files-of-a-user': {
tags: ['admin'],
requireCredential: true,
requireAdmin: true,
defines: [{
req: {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
},
res: undefined,
}],
}
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };
/** /**