feat(backend): 通報および通報解決時に送出されるSystemWebhookにユーザ情報を含めるようにする
This commit is contained in:
parent
650e22c90d
commit
91144d4398
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
- Enhance: セキュリティ向上のため、ログイン時にメール通知を行うように
|
- Enhance: セキュリティ向上のため、ログイン時にメール通知を行うように
|
||||||
|
- Enhance: 通報および通報解決時に送出されるSystemWebhookにユーザ情報を含めるように ( #14697 )
|
||||||
|
|
||||||
## 2024.9.0
|
## 2024.9.0
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { RoleService } from '@/core/RoleService.js';
|
||||||
import { RecipientMethod } from '@/models/AbuseReportNotificationRecipient.js';
|
import { RecipientMethod } from '@/models/AbuseReportNotificationRecipient.js';
|
||||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||||
import { SystemWebhookService } from '@/core/SystemWebhookService.js';
|
import { SystemWebhookService } from '@/core/SystemWebhookService.js';
|
||||||
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||||
import { IdService } from './IdService.js';
|
import { IdService } from './IdService.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -29,19 +30,17 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.meta)
|
@Inject(DI.meta)
|
||||||
private meta: MiMeta,
|
private meta: MiMeta,
|
||||||
|
|
||||||
@Inject(DI.abuseReportNotificationRecipientRepository)
|
@Inject(DI.abuseReportNotificationRecipientRepository)
|
||||||
private abuseReportNotificationRecipientRepository: AbuseReportNotificationRecipientRepository,
|
private abuseReportNotificationRecipientRepository: AbuseReportNotificationRecipientRepository,
|
||||||
|
|
||||||
@Inject(DI.redisForSub)
|
@Inject(DI.redisForSub)
|
||||||
private redisForSub: Redis.Redis,
|
private redisForSub: Redis.Redis,
|
||||||
|
|
||||||
private idService: IdService,
|
private idService: IdService,
|
||||||
private roleService: RoleService,
|
private roleService: RoleService,
|
||||||
private systemWebhookService: SystemWebhookService,
|
private systemWebhookService: SystemWebhookService,
|
||||||
private emailService: EmailService,
|
private emailService: EmailService,
|
||||||
private moderationLogService: ModerationLogService,
|
private moderationLogService: ModerationLogService,
|
||||||
private globalEventService: GlobalEventService,
|
private globalEventService: GlobalEventService,
|
||||||
|
private userEntityService: UserEntityService,
|
||||||
) {
|
) {
|
||||||
this.redisForSub.on('message', this.onMessage);
|
this.redisForSub.on('message', this.onMessage);
|
||||||
}
|
}
|
||||||
|
@ -135,6 +134,26 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
return;
|
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()
|
const recipientWebhookIds = await this.fetchWebhookRecipients()
|
||||||
.then(it => it
|
.then(it => it
|
||||||
.filter(it => it.isActive && it.systemWebhookId && it.method === 'webhook')
|
.filter(it => it.isActive && it.systemWebhookId && it.method === 'webhook')
|
||||||
|
@ -142,7 +161,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
.filter(x => x != null));
|
.filter(x => x != null));
|
||||||
for (const webhookId of recipientWebhookIds) {
|
for (const webhookId of recipientWebhookIds) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
abuseReports.map(it => {
|
convertedReports.map(it => {
|
||||||
return this.systemWebhookService.enqueueSystemWebhook(
|
return this.systemWebhookService.enqueueSystemWebhook(
|
||||||
webhookId,
|
webhookId,
|
||||||
type,
|
type,
|
||||||
|
|
Loading…
Reference in New Issue