This commit is contained in:
tamaina 2023-05-29 13:28:31 +00:00
parent 9ce6f99cad
commit 93ea327660
6 changed files with 92 additions and 86 deletions

View File

@ -5,6 +5,8 @@ import { awaitAll } from '@/misc/prelude/await-all.js';
import type { AbuseUserReport } from '@/models/entities/AbuseUserReport.js'; import type { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
import { UserEntityService } from './UserEntityService.js'; import { UserEntityService } from './UserEntityService.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { Packed } from 'misskey-js';
import { Serialized } from 'schema-type';
@Injectable() @Injectable()
export class AbuseUserReportEntityService { export class AbuseUserReportEntityService {
@ -19,7 +21,7 @@ export class AbuseUserReportEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: AbuseUserReport['id'] | AbuseUserReport, src: AbuseUserReport['id'] | AbuseUserReport,
) { ): Promise<Serialized<Packed<'AbuseUserReport'>>> {
const report = typeof src === 'object' ? src : await this.abuseUserReportsRepository.findOneByOrFail({ id: src }); const report = typeof src === 'object' ? src : await this.abuseUserReportsRepository.findOneByOrFail({ id: src });
return await awaitAll({ return await awaitAll({
@ -46,7 +48,7 @@ export class AbuseUserReportEntityService {
@bindThis @bindThis
public packMany( public packMany(
reports: any[], reports: any[],
) { ): Promise<Serialized<Packed<'AbuseUserReport'>>[]> {
return Promise.all(reports.map(x => this.pack(x))); return Promise.all(reports.map(x => this.pack(x)));
} }
} }

View File

@ -5,91 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { AbuseUserReportEntityService } from '@/core/entities/AbuseUserReportEntityService.js'; import { AbuseUserReportEntityService } from '@/core/entities/AbuseUserReportEntityService.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
properties: {
id: {
type: 'string',
nullable: false, optional: false,
format: 'id',
example: 'xxxxxxxxxx',
},
createdAt: {
type: 'string',
nullable: false, optional: false,
format: 'date-time',
},
comment: {
type: 'string',
nullable: false, optional: false,
},
resolved: {
type: 'boolean',
nullable: false, optional: false,
example: false,
},
reporterId: {
type: 'string',
nullable: false, optional: false,
format: 'id',
},
targetUserId: {
type: 'string',
nullable: false, optional: false,
format: 'id',
},
assigneeId: {
type: 'string',
nullable: true, optional: false,
format: 'id',
},
reporter: {
type: 'object',
nullable: false, optional: false,
ref: 'User',
},
targetUser: {
type: 'object',
nullable: false, optional: false,
ref: 'User',
},
assignee: {
type: 'object',
nullable: true, optional: true,
ref: 'User',
},
},
},
},
} 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' },
state: { type: 'string', nullable: true, default: null },
reporterOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
targetUserOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
forwarded: { type: 'boolean', default: false },
},
required: [],
} 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/abuse-user-reports'> {
name = 'admin/abuse-user-reports' as const;
constructor( constructor(
@Inject(DI.abuseUserReportsRepository) @Inject(DI.abuseUserReportsRepository)
private abuseUserReportsRepository: AbuseUserReportsRepository, private abuseUserReportsRepository: AbuseUserReportsRepository,
@ -97,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private abuseUserReportEntityService: AbuseUserReportEntityService, private abuseUserReportEntityService: AbuseUserReportEntityService,
private queryService: QueryService, private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.abuseUserReportsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId); const query = this.queryService.makePaginationQuery(this.abuseUserReportsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId);
switch (ps.state) { switch (ps.state) {

View File

@ -1378,6 +1378,34 @@ export const endpoints = {
} }
}], }],
}, },
'admin/abuse-user-reports': {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
defines: [{
req: {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
state: { type: ['string', 'null'], default: null },
reporterOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
targetUserOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
forwarded: { type: 'boolean', default: false },
},
required: [],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/AbuseUserReport',
},
},
}],
},
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };
/** /**

View File

@ -36,6 +36,7 @@ import { packedFlashSchema } from './schemas/flash.js';
import { packedAdSchema } from './schemas/ad.js'; import { packedAdSchema } from './schemas/ad.js';
import { packedAnnouncementSchema } from './schemas/announcement.js'; import { packedAnnouncementSchema } from './schemas/announcement.js';
import { packedRelaySchema } from './schemas/relay.js'; import { packedRelaySchema } from './schemas/relay.js';
import { packedAbuseUserReportSchema } from './schemas/abuse-user-report.js';
import { import {
packedRoleSchema, packedRoleSchema,
packedRoleAssignSchema, packedRoleAssignSchema,
@ -87,6 +88,7 @@ export const refs = {
RoleAssign: packedRoleAssignSchema, RoleAssign: packedRoleAssignSchema,
RolePolicy: packedRolePolicySchema, RolePolicy: packedRolePolicySchema,
RoleCondFormula: packedRoleCondFormulaSchema, RoleCondFormula: packedRoleCondFormulaSchema,
AbuseUserReport: packedAbuseUserReportSchema,
Error: Error, Error: Error,
ApiError: ApiError, ApiError: ApiError,

View File

@ -0,0 +1,52 @@
import type { JSONSchema7Definition } from 'schema-type';
export const packedAbuseUserReportSchema = {
$id: 'https://misskey-hub.net/api/schemas/AbuseUserReport',
type: 'object',
properties: {
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
createdAt: {
type: 'string',
format: 'date-time',
},
comment: {
type: 'string',
},
resolved: {
type: 'boolean',
examples: [false],
},
reporterId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
reporter: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
targetUserId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
targetUser: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
assigneeId: {
oneOf: [
{ $ref: 'https://misskey-hub.net/api/schemas/Id' },
{ type: 'null' },
]
},
assignee: {
oneOf: [
{ $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
{ type: 'null' },
]
},
forwarded: {
type: 'boolean',
},
},
required: [
'id',
'createdAt',
'comment',
'resolved',
'reporterId',
'reporter',
'targetUserId',
'targetUser',
'assigneeId',
'forwarded',
],
} as const satisfies JSONSchema7Definition;

View File

@ -107,6 +107,9 @@ describe('schemas', () => {
type RolePolicy = Packed<'RolePolicy'>; type RolePolicy = Packed<'RolePolicy'>;
type RoleCondFormula = Packed<'RoleCondFormula'>; type RoleCondFormula = Packed<'RoleCondFormula'>;
}); });
test('abuse user report', () => {
type AbuseUserReport = Packed<'AbuseUserReport'>;
});
test('error', () => { test('error', () => {
type Error = Packed<'Error'>; type Error = Packed<'Error'>;
type ApiError = Packed<'ApiError'>; type ApiError = Packed<'ApiError'>;