Feat: 複数ノートの通報機能
This commit is contained in:
parent
4c135a5ca1
commit
6849d510ac
10 changed files with 197 additions and 69 deletions
11
packages/backend/migration/1702149469508-abusenoteselect.js
Normal file
11
packages/backend/migration/1702149469508-abusenoteselect.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export class Abusenoteselect1702149469508 {
|
||||
name = 'Abusenoteselect1702149469508'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "abuse_user_report" ADD "notes" jsonb NOT NULL DEFAULT '[]'`);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "abuse_user_report" DROP COLUMN "notes"`);
|
||||
}
|
||||
}
|
||||
|
|
@ -157,6 +157,7 @@ export interface AdminEventTypes {
|
|||
targetUserId: MiUser['id'],
|
||||
reporterId: MiUser['id'],
|
||||
comment: string;
|
||||
notes: any[];
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export class AbuseUserReportEntityService {
|
|||
id: report.id,
|
||||
createdAt: this.idService.parse(report.id).date.toISOString(),
|
||||
comment: report.comment,
|
||||
notes: report.notes,
|
||||
resolved: report.resolved,
|
||||
reporterId: report.reporterId,
|
||||
targetUserId: report.targetUserId,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ export class MiAbuseUserReport {
|
|||
})
|
||||
public comment: string;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: [],
|
||||
})
|
||||
public notes: any[];
|
||||
|
||||
//#region Denormalized fields
|
||||
@Index()
|
||||
@Column('varchar', {
|
||||
|
|
|
|||
|
|
@ -3,14 +3,17 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { setImmediate } from 'node:timers/promises';
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type { AbuseUserReportsRepository } from '@/models/_.js';
|
||||
import { In } from 'typeorm';
|
||||
import type { AbuseUserReportsRepository, NotesRepository } from '@/models/_.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
import { EmailService } from '@/core/EmailService.js';
|
||||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { GetterService } from '@/server/api/GetterService.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
|
|
@ -21,7 +24,7 @@ export const meta = {
|
|||
|
||||
requireCredential: true,
|
||||
|
||||
description: 'File a report.',
|
||||
description: 'User a report.',
|
||||
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
|
|
@ -49,6 +52,7 @@ export const paramDef = {
|
|||
properties: {
|
||||
userId: { type: 'string', format: 'misskey:id' },
|
||||
comment: { type: 'string', minLength: 1, maxLength: 2048 },
|
||||
noteIds: { type: 'array', items: { type: 'string', format: 'misskey:id' } },
|
||||
},
|
||||
required: ['userId', 'comment'],
|
||||
} as const;
|
||||
|
|
@ -59,11 +63,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
@Inject(DI.abuseUserReportsRepository)
|
||||
private abuseUserReportsRepository: AbuseUserReportsRepository,
|
||||
|
||||
@Inject(DI.notesRepository)
|
||||
private notesRepository: NotesRepository,
|
||||
|
||||
private idService: IdService,
|
||||
private metaService: MetaService,
|
||||
private emailService: EmailService,
|
||||
private getterService: GetterService,
|
||||
private roleService: RoleService,
|
||||
private noteEntityService: NoteEntityService,
|
||||
private globalEventService: GlobalEventService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
|
|
@ -81,6 +89,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.cannotReportAdmin);
|
||||
}
|
||||
|
||||
const notes = ps.noteIds ? await this.notesRepository.find({
|
||||
where: { id: In(ps.noteIds) },
|
||||
}) : [];
|
||||
const filteredNotes = notes.filter(note => note.userId === user.id);
|
||||
const report = await this.abuseUserReportsRepository.insert({
|
||||
id: this.idService.gen(),
|
||||
targetUserId: user.id,
|
||||
|
|
@ -88,6 +100,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
reporterId: me.id,
|
||||
reporterHost: null,
|
||||
comment: ps.comment,
|
||||
notes: ps.noteIds ? await this.noteEntityService.packMany(filteredNotes) : [],
|
||||
}).then(x => this.abuseUserReportsRepository.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
// Publish event to moderators
|
||||
|
|
@ -100,9 +113,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
targetUserId: report.targetUserId,
|
||||
reporterId: report.reporterId,
|
||||
comment: report.comment,
|
||||
notes: report.notes,
|
||||
});
|
||||
}
|
||||
|
||||
const meta = await this.metaService.fetch();
|
||||
if (meta.email) {
|
||||
this.emailService.sendEmail(meta.email, 'New abuse report',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue