summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorおさむのひと <46447427+samunohito@users.noreply.github.com>2024-10-05 12:51:46 +0900
committerGitHub <noreply@github.com>2024-10-05 12:51:46 +0900
commit88698462a91e0fe15501a44f923a812d169bb030 (patch)
tree43e9cbb5e67e1f0cb03df3e81681b9575922fdfc /packages/backend/src/core
parentfix: signin の資格情報が足りないだけの場合はエラーにせ... (diff)
downloadmisskey-88698462a91e0fe15501a44f923a812d169bb030.tar.gz
misskey-88698462a91e0fe15501a44f923a812d169bb030.tar.bz2
misskey-88698462a91e0fe15501a44f923a812d169bb030.zip
feat(backend): 通報および通報解決時に送出されるSystemWebhookにユーザ情報を含めるようにする (#14698)
* feat(backend): 通報および通報解決時に送出されるSystemWebhookにユーザ情報を含めるようにする * テスト送信もペイロード形式を合わせる * add spaces * fix test
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/AbuseReportNotificationService.ts24
-rw-r--r--packages/backend/src/core/WebhookTestService.ts20
2 files changed, 40 insertions, 4 deletions
diff --git a/packages/backend/src/core/AbuseReportNotificationService.ts b/packages/backend/src/core/AbuseReportNotificationService.ts
index fe2c63e7d6..fb7c7bd2c3 100644
--- a/packages/backend/src/core/AbuseReportNotificationService.ts
+++ b/packages/backend/src/core/AbuseReportNotificationService.ts
@@ -22,6 +22,7 @@ import { RoleService } from '@/core/RoleService.js';
import { RecipientMethod } from '@/models/AbuseReportNotificationRecipient.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { SystemWebhookService } from '@/core/SystemWebhookService.js';
+import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { IdService } from './IdService.js';
@Injectable()
@@ -42,6 +43,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
private emailService: EmailService,
private moderationLogService: ModerationLogService,
private globalEventService: GlobalEventService,
+ private userEntityService: UserEntityService,
) {
this.redisForSub.on('message', this.onMessage);
}
@@ -135,6 +137,26 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
return;
}
+ const usersMap = await this.userEntityService.packMany(
+ [
+ ...new Set([
+ ...abuseReports.map(it => it.reporter ?? it.reporterId),
+ ...abuseReports.map(it => it.targetUser ?? it.targetUserId),
+ ...abuseReports.map(it => it.assignee ?? it.assigneeId),
+ ].filter(x => x != null)),
+ ],
+ null,
+ { schema: 'UserLite' },
+ ).then(it => new Map(it.map(it => [it.id, it])));
+ const convertedReports = abuseReports.map(it => {
+ return {
+ ...it,
+ reporter: usersMap.get(it.reporterId),
+ targetUser: usersMap.get(it.targetUserId),
+ assignee: it.assigneeId ? usersMap.get(it.assigneeId) : null,
+ };
+ });
+
const recipientWebhookIds = await this.fetchWebhookRecipients()
.then(it => it
.filter(it => it.isActive && it.systemWebhookId && it.method === 'webhook')
@@ -142,7 +164,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
.filter(x => x != null));
for (const webhookId of recipientWebhookIds) {
await Promise.all(
- abuseReports.map(it => {
+ convertedReports.map(it => {
return this.systemWebhookService.enqueueSystemWebhook(
webhookId,
type,
diff --git a/packages/backend/src/core/WebhookTestService.ts b/packages/backend/src/core/WebhookTestService.ts
index c2764f30e8..149c753d4c 100644
--- a/packages/backend/src/core/WebhookTestService.ts
+++ b/packages/backend/src/core/WebhookTestService.ts
@@ -15,8 +15,14 @@ import { QueueService } from '@/core/QueueService.js';
const oneDayMillis = 24 * 60 * 60 * 1000;
-function generateAbuseReport(override?: Partial<MiAbuseUserReport>): MiAbuseUserReport {
- return {
+type AbuseUserReportDto = Omit<MiAbuseUserReport, 'targetUser' | 'reporter' | 'assignee'> & {
+ targetUser: Packed<'UserLite'> | null,
+ reporter: Packed<'UserLite'> | null,
+ assignee: Packed<'UserLite'> | null,
+};
+
+function generateAbuseReport(override?: Partial<MiAbuseUserReport>): AbuseUserReportDto {
+ const result: MiAbuseUserReport = {
id: 'dummy-abuse-report1',
targetUserId: 'dummy-target-user',
targetUser: null,
@@ -31,6 +37,13 @@ function generateAbuseReport(override?: Partial<MiAbuseUserReport>): MiAbuseUser
reporterHost: null,
...override,
};
+
+ return {
+ ...result,
+ targetUser: result.targetUser ? toPackedUserLite(result.targetUser) : null,
+ reporter: result.reporter ? toPackedUserLite(result.reporter) : null,
+ assignee: result.assignee ? toPackedUserLite(result.assignee) : null,
+ };
}
function generateDummyUser(override?: Partial<MiUser>): MiUser {
@@ -268,7 +281,8 @@ const dummyUser3 = generateDummyUser({
@Injectable()
export class WebhookTestService {
- public static NoSuchWebhookError = class extends Error {};
+ public static NoSuchWebhookError = class extends Error {
+ };
constructor(
private userWebhookService: UserWebhookService,