diff --git a/packages/backend/src/server/api/EndpointsModule.ts b/packages/backend/src/server/api/EndpointsModule.ts index 287343c5ddc7..a7afcf7408f6 100644 --- a/packages/backend/src/server/api/EndpointsModule.ts +++ b/packages/backend/src/server/api/EndpointsModule.ts @@ -6,6 +6,7 @@ import { Module } from '@nestjs/common'; import { CoreModule } from '@/core/CoreModule.js'; +import * as ep___admin_nirilaDeleteUserLogAccess from './endpoints/admin/nirila-delete-user-log-access.js'; import * as ep___admin_meta from './endpoints/admin/meta.js'; import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-reports.js'; import * as ep___admin_accounts_create from './endpoints/admin/accounts/create.js'; @@ -368,6 +369,7 @@ import { GetterService } from './GetterService.js'; import { ApiLoggerService } from './ApiLoggerService.js'; import type { Provider } from '@nestjs/common'; +const $admin_nirilaDeleteUserLogAccess: Provider = { provide: 'ep:admin/nirila-delete-user-log-access', useClass: ep___admin_nirilaDeleteUserLogAccess.default }; const $admin_meta: Provider = { provide: 'ep:admin/meta', useClass: ep___admin_meta.default }; const $admin_abuseUserReports: Provider = { provide: 'ep:admin/abuse-user-reports', useClass: ep___admin_abuseUserReports.default }; const $admin_accounts_create: Provider = { provide: 'ep:admin/accounts/create', useClass: ep___admin_accounts_create.default }; @@ -734,6 +736,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention providers: [ GetterService, ApiLoggerService, + $admin_nirilaDeleteUserLogAccess, $admin_meta, $admin_abuseUserReports, $admin_accounts_create, @@ -1094,6 +1097,7 @@ const $retention: Provider = { provide: 'ep:retention', useClass: ep___retention $retention, ], exports: [ + $admin_nirilaDeleteUserLogAccess, $admin_meta, $admin_abuseUserReports, $admin_accounts_create, diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 9915b0e873d6..6289bdce72ce 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -7,6 +7,7 @@ import type { Schema } from '@/misc/json-schema.js'; import { permissions } from 'misskey-js'; import { RolePolicies } from '@/core/RoleService.js'; +import * as ep___admin_nirilaDeleteUserLogAccess from './endpoints/admin/nirila-delete-user-log-access.js'; import * as ep___admin_meta from './endpoints/admin/meta.js'; import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-reports.js'; import * as ep___admin_accounts_create from './endpoints/admin/accounts/create.js'; @@ -367,6 +368,7 @@ import * as ep___fetchExternalResources from './endpoints/fetch-external-resourc import * as ep___retention from './endpoints/retention.js'; const eps = [ + ['admin/nirila-delete-user-log-access', ep___admin_nirilaDeleteUserLogAccess], ['admin/meta', ep___admin_meta], ['admin/abuse-user-reports', ep___admin_abuseUserReports], ['admin/accounts/create', ep___admin_accounts_create], diff --git a/packages/backend/src/server/api/endpoints/admin/nirila-delete-user-log-access.ts b/packages/backend/src/server/api/endpoints/admin/nirila-delete-user-log-access.ts new file mode 100644 index 000000000000..9fc40dde5034 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/admin/nirila-delete-user-log-access.ts @@ -0,0 +1,84 @@ +/* + * SPDX-FileCopyrightText: anatawa12 + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Inject, Injectable } from '@nestjs/common'; +import type { NirilaDeleteUserLogRepository } from '@/models/_.js'; +import { Endpoint } from '@/server/api/endpoint-base.js'; +import { DI } from '@/di-symbols.js'; +import { ApiError } from '@/server/api/error.js'; +import { QueryService } from '@/core/QueryService.js'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + secure: true, + kind: 'read:admin:nirila-delete-user-log-access', + + errors: { + notFound: { + message: 'DeleteLog satisfies the request not found', + code: 'NOT_FOUND', + id: 'd29927d1-5b8c-4200-aa05-5537722ee7ab', + }, + }, + + res: { type: 'any' }, // no type data +} as const; + +export const paramDef = { + type: 'object', + properties: { + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + + // access single by id + email: { type: 'string' }, + username: { type: 'string' }, + userId: { type: 'string', format: 'misskey:id' }, + }, + required: [], +} as const; + +@Injectable() +export default class extends Endpoint { // eslint-disable-line import/no-default-export + constructor( + @Inject(DI.nirilaDeleteUserLogRepository) + private nirilaDeleteUserLogRepository: NirilaDeleteUserLogRepository, + + private queryService: QueryService, + ) { + super(meta, paramDef, async (ps, me) => { + // single query + if (ps.email) { + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ email: ps.email }); + if (!found) throw new ApiError(meta.errors.notFound); + return found.info; + } + + if (ps.username) { + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ username: ps.username }); + if (!found) throw new ApiError(meta.errors.notFound); + return found.info; + } + + if (ps.userId) { + const found = await this.nirilaDeleteUserLogRepository.findOneBy({ userId: ps.userId }); + if (!found) throw new ApiError(meta.errors.notFound); + return found.info; + } + + // list query + + const logs = await this.queryService.makePaginationQuery(this.nirilaDeleteUserLogRepository.createQueryBuilder('deleteLog'), ps.sinceId, ps.untilId) + .limit(ps.limit) + .getMany(); + + return logs.map(x => Object.assign(x.info, { id: x.id })); + }); + } +} diff --git a/packages/misskey-js/src/consts.ts b/packages/misskey-js/src/consts.ts index 82162e58ea0b..29de718019ee 100644 --- a/packages/misskey-js/src/consts.ts +++ b/packages/misskey-js/src/consts.ts @@ -9,6 +9,7 @@ export const followingVisibilities = ['public', 'followers', 'private'] as const export const followersVisibilities = ['public', 'followers', 'private'] as const; export const permissions = [ + 'read:admin:nirila-delete-user-log-access', 'read:account', 'write:account', 'read:blocks',