Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 通報の即時解決機能を追加 #113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f1889d3
feat: 通報の即時解決機能を追加
chocolate-pie Jun 17, 2023
9b00b35
fix: 条件変更時に有効期限を変更していないのに勝手に更新される問題を修正
chocolate-pie Jun 19, 2023
3796d61
fix: 条件のパターンの削除ができない問題を修正
chocolate-pie Jun 19, 2023
7a138ae
fix: リソルバーの通報を解決する判定基準が間違っていたのを修正
chocolate-pie Jun 19, 2023
5f879f0
fix: 変更する変数が間違っていたのを修正
chocolate-pie Jun 19, 2023
66e9240
fix: getUTCMonthはゼロ始まりかも
chocolate-pie Jun 19, 2023
3b19cc7
enhance: Storybookのストーリーを作成
chocolate-pie Jun 21, 2023
4ab8f14
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jun 25, 2023
f7e45ff
fix: 色々修正
chocolate-pie Jun 26, 2023
2bf908c
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jun 26, 2023
762ef6b
fix: 型エラーを修正
chocolate-pie Jun 26, 2023
cf0b6ff
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jun 29, 2023
e443170
[ci skip] Update CHANGELOG.md
chocolate-pie Jun 30, 2023
4db3fd0
[ci skip] Update CHANGELOG.md
chocolate-pie Jun 30, 2023
3f6f9ce
Merge branch 'develop' into abuse-report-resolver
chocolate-pie Jul 3, 2023
7cbf72b
Update CHANGELOG.md
chocolate-pie Jul 3, 2023
adba699
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jul 4, 2023
3aa6aa0
リファクタリング
chocolate-pie Jul 4, 2023
5d35a37
refactor: 型定義をよりよくした
chocolate-pie Jul 4, 2023
0ee451a
refactor: beforeExpiresAtの初期値はundefinedの方がいい
chocolate-pie Jul 4, 2023
5466f47
refactor: 変数の名前を変更
chocolate-pie Jul 4, 2023
36b8412
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jul 18, 2023
fd3353b
Fix: リモートサーバーから転送された通報も対象に追加
chocolate-pie Jul 18, 2023
4b86cb2
Merge remote-tracking branch 'upstream/develop' into abuse-report-res…
chocolate-pie Jul 22, 2023
3b1d9e0
Update CHANGELOG.md
chocolate-pie Jul 22, 2023
0cc7559
take review
u1-liquid Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,25 @@ export interface Locale {
"mention": string;
};
};
"_abuse": {
"_resolver": {
"1hour": string;
"12hours": string;
"1day": string;
"1week": string;
"1month": string;
"3months": string;
"6months": string;
"1year": string;
"indefinitely": string;
"expiresAt": string;
"targetUserPattern": string;
"reporterPattern": string;
"reportContentPattern": string;
};
"list": string;
"resolver": string;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
18 changes: 18 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2093,3 +2093,21 @@ _webhookSettings:
renote: "Renoteされたとき"
reaction: "リアクションがあったとき"
mention: "メンションされたとき"

_abuse:
_resolver:
1hour: "一時間"
12hours: "半日"
1day: "一日"
1week: "一週間"
1month: "一ヶ月"
3months: "三ヶ月"
6months: "六ヶ月"
1year: "一年"
indefinitely: "無期限"
expiresAt: "この条件の有効期限"
targetUserPattern: "通報先のパターン"
reporterPattern: "通報元のパターン"
reportContentPattern: "通報内容のパターン"
list: "一覧"
resolver: "リソルバー"
19 changes: 19 additions & 0 deletions packages/backend/migration/1686908762393-AbuseReportResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class AbuseReportResolver1686908762393 {
name = 'AbuseReportResolver1686908762393'

async up(queryRunner) {
await queryRunner.query(`CREATE TYPE "public"."abuse_report_resolver_expiresat_enum" AS ENUM('1hour', '12hours', '1day', '1week', '1month', '3months', '6months', '1year', 'indefinitely')`);
await queryRunner.query(`CREATE TABLE "abuse_report_resolver" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, "name" character varying(256) NOT NULL, "targetUserPattern" character varying(1024), "reporterPattern" character varying(1024), "reportContentPattern" character varying(1024), "expirationDate" TIMESTAMP WITH TIME ZONE, "expiresAt" "public"."abuse_report_resolver_expiresat_enum" NOT NULL, "forward" boolean NOT NULL, CONSTRAINT "PK_093500bf1bb38880d38b1bb41dc" PRIMARY KEY ("id")); COMMENT ON COLUMN "abuse_report_resolver"."createdAt" IS 'The created date of AbuseReportResolver'; COMMENT ON COLUMN "abuse_report_resolver"."updatedAt" IS 'The updated date of AbuseReportResolver'; COMMENT ON COLUMN "abuse_report_resolver"."expirationDate" IS 'The expiration date of AbuseReportResolver'`);
await queryRunner.query(`CREATE INDEX "IDX_fdd74ab625ed0f6a30c47b00e0" ON "abuse_report_resolver" ("createdAt") `);
await queryRunner.query(`CREATE INDEX "IDX_d90c2c0e555b1eb2e4f19c9ad4" ON "abuse_report_resolver" ("updatedAt") `);
await queryRunner.query(`CREATE INDEX "IDX_e83a32a146021c72ba9bde6675" ON "abuse_report_resolver" ("expirationDate") `);
}

async down(queryRunner) {
await queryRunner.query(`DROP INDEX "public"."IDX_e83a32a146021c72ba9bde6675"`);
await queryRunner.query(`DROP INDEX "public"."IDX_d90c2c0e555b1eb2e4f19c9ad4"`);
await queryRunner.query(`DROP INDEX "public"."IDX_fdd74ab625ed0f6a30c47b00e0"`);
await queryRunner.query(`DROP TABLE "abuse_report_resolver"`);
await queryRunner.query(`DROP TYPE "public"."abuse_report_resolver_expiresat_enum"`);
}
}
6 changes: 6 additions & 0 deletions packages/backend/src/core/QueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
import { Inject, Injectable } from '@nestjs/common';
import type { IActivity } from '@/core/activitypub/type.js';
import type { DriveFile } from '@/models/entities/DriveFile.js';
import type { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
import type { Webhook, webhookEventTypes } from '@/models/entities/Webhook.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
Expand Down Expand Up @@ -336,6 +337,11 @@ export class QueueService {
});
}

@bindThis
public createReportAbuseJob(report: AbuseUserReport) {
return this.dbQueue.add('reportAbuse', report);
}

@bindThis
public createFollowJob(followings: { from: ThinUser, to: ThinUser, requestId?: string, silent?: boolean }[]) {
const jobs = followings.map(rel => this.generateRelationshipJobData('follow', rel));
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,17 @@ export class ApInboxService {
});
if (users.length < 1) return 'skip';

await this.abuseUserReportsRepository.insert({
const report = await this.abuseUserReportsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
targetUserId: users[0].id,
targetUserHost: users[0].host,
reporterId: actor.id,
reporterHost: actor.host,
comment: `${activity.content}\n${JSON.stringify(uris, null, 2)}`,
});
}).then(x => this.abuseUserReportsRepository.findOneByOrFail(x.identifiers[0]));

this.queueService.createReportAbuseJob(report);

return 'ok';
}
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/di-symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DI = {
//#region Repositories
usersRepository: Symbol('usersRepository'),
notesRepository: Symbol('notesRepository'),
abuseReportResolversRepository: Symbol('abuseReportResolversRepository'),
announcementsRepository: Symbol('announcementsRepository'),
announcementReadsRepository: Symbol('announcementReadsRepository'),
appsRepository: Symbol('appsRepository'),
Expand Down
10 changes: 9 additions & 1 deletion packages/backend/src/models/RepositoryModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelFavorite, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite, UserMemo, UserListFavorite } from './index.js';
import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelFavorite, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite, UserMemo, UserListFavorite, AbuseReportResolver } from './index.js';
import type { DataSource } from 'typeorm';
import type { Provider } from '@nestjs/common';

Expand Down Expand Up @@ -400,6 +400,12 @@ const $userMemosRepository: Provider = {
inject: [DI.db],
};

const $abuseReportResolversRepository: Provider = {
provide: DI.abuseReportResolversRepository,
useFactory: (db: DataSource) => db.getRepository(AbuseReportResolver),
inject: [DI.db],
};

@Module({
imports: [
],
Expand Down Expand Up @@ -470,6 +476,7 @@ const $userMemosRepository: Provider = {
$flashsRepository,
$flashLikesRepository,
$userMemosRepository,
$abuseReportResolversRepository,
],
exports: [
$usersRepository,
Expand Down Expand Up @@ -538,6 +545,7 @@ const $userMemosRepository: Provider = {
$flashsRepository,
$flashLikesRepository,
$userMemosRepository,
$abuseReportResolversRepository,
],
})
export class RepositoryModule {}
58 changes: 58 additions & 0 deletions packages/backend/src/models/entities/AbuseReportResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Column, Entity, PrimaryColumn, Index } from 'typeorm';
import { id } from '../id.js';

@Entity()
export class AbuseReportResolver {
@PrimaryColumn(id())
public id: string;

@Index()
@Column('timestamp with time zone', {
comment: 'The created date of AbuseReportResolver',
})
public createdAt: Date;

@Index()
@Column('timestamp with time zone', {
comment: 'The updated date of AbuseReportResolver',
})
public updatedAt: Date;

@Column('varchar', {
length: 256,
})
public name: string;

@Column('varchar', {
length: 1024,
nullable: true,
})
public targetUserPattern: string | null;

@Column('varchar', {
length: 1024,
nullable: true,
})
public reporterPattern: string | null;

@Column('varchar', {
length: 1024,
nullable: true,
})
public reportContentPattern: string | null;

@Index()
@Column('timestamp with time zone', {
comment: 'The expiration date of AbuseReportResolver',
nullable: true,
})
public expirationDate: Date | null;

@Column('enum', {
enum: ['1hour', '12hours', '1day', '1week', '1month', '3months', '6months', '1year', 'indefinitely']
})
public expiresAt: string;

@Column('boolean')
public forward: boolean;
}
3 changes: 3 additions & 0 deletions packages/backend/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbuseReportResolver } from '@/models/entities/AbuseReportResolver.js';
import { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
import { AccessToken } from '@/models/entities/AccessToken.js';
import { Ad } from '@/models/entities/Ad.js';
Expand Down Expand Up @@ -67,6 +68,7 @@ import { UserListFavorite } from './entities/UserListFavorite.js';
import type { Repository } from 'typeorm';

export {
AbuseReportResolver,
AbuseUserReport,
AccessToken,
Ad,
Expand Down Expand Up @@ -135,6 +137,7 @@ export {
UserMemo,
};

export type AbuseReportResolversRepository = Repository<AbuseReportResolver>;
export type AbuseUserReportsRepository = Repository<AbuseUserReport>;
export type AccessTokensRepository = Repository<AccessToken>;
export type AdsRepository = Repository<Ad>;
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DataSource, Logger } from 'typeorm';
import * as highlight from 'cli-highlight';
import { entities as charts } from '@/core/chart/entities.js';

import { AbuseReportResolver } from '@/models/entities/AbuseReportResolver.js';
import { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
import { AccessToken } from '@/models/entities/AccessToken.js';
import { Ad } from '@/models/entities/Ad.js';
Expand Down Expand Up @@ -121,6 +122,7 @@ class MyCustomLogger implements Logger {
}

export const entities = [
AbuseReportResolver,
Announcement,
AnnouncementRead,
Meta,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/queue/QueueProcessorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ImportMutingProcessorService } from './processors/ImportMutingProcessor
import { ImportUserListsProcessorService } from './processors/ImportUserListsProcessorService.js';
import { ImportAntennasProcessorService } from './processors/ImportAntennasProcessorService.js';
import { ResyncChartsProcessorService } from './processors/ResyncChartsProcessorService.js';
import { ReportAbuseProcessorService } from './processors/ReportAbuseProcessorService.js';
import { TickChartsProcessorService } from './processors/TickChartsProcessorService.js';
import { AggregateRetentionProcessorService } from './processors/AggregateRetentionProcessorService.js';
import { ExportFavoritesProcessorService } from './processors/ExportFavoritesProcessorService.js';
Expand Down Expand Up @@ -64,6 +65,7 @@ import { RelationshipProcessorService } from './processors/RelationshipProcessor
DeleteFileProcessorService,
CleanRemoteFilesProcessorService,
RelationshipProcessorService,
ReportAbuseProcessorService,
WebhookDeliverProcessorService,
EndedPollNotificationProcessorService,
DeliverProcessorService,
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/queue/QueueProcessorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ExportFavoritesProcessorService } from './processors/ExportFavoritesPro
import { CleanRemoteFilesProcessorService } from './processors/CleanRemoteFilesProcessorService.js';
import { DeleteFileProcessorService } from './processors/DeleteFileProcessorService.js';
import { RelationshipProcessorService } from './processors/RelationshipProcessorService.js';
import { ReportAbuseProcessorService } from './processors/ReportAbuseProcessorService.js';
import { TickChartsProcessorService } from './processors/TickChartsProcessorService.js';
import { ResyncChartsProcessorService } from './processors/ResyncChartsProcessorService.js';
import { CleanChartsProcessorService } from './processors/CleanChartsProcessorService.js';
Expand Down Expand Up @@ -102,6 +103,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
private deleteFileProcessorService: DeleteFileProcessorService,
private cleanRemoteFilesProcessorService: CleanRemoteFilesProcessorService,
private relationshipProcessorService: RelationshipProcessorService,
private reportAbuseProcessorService: ReportAbuseProcessorService,
private tickChartsProcessorService: TickChartsProcessorService,
private resyncChartsProcessorService: ResyncChartsProcessorService,
private cleanChartsProcessorService: CleanChartsProcessorService,
Expand Down Expand Up @@ -174,6 +176,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
case 'importCustomEmojis': return this.importCustomEmojisProcessorService.process(job);
case 'importAntennas': return this.importAntennasProcessorService.process(job);
case 'deleteAccount': return this.deleteAccountProcessorService.process(job);
case 'reportAbuse': return this.reportAbuseProcessorService.process(job);
default: throw new Error(`unrecognized job type ${job.name} for db`);
}
}, {
Expand Down
Loading