-
Notifications
You must be signed in to change notification settings - Fork 15
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
Enhance(sensitive-flag):センシティブフラグの機能の強化 #936
base: io
Are you sure you want to change the base?
Changes from all commits
f2b93eb
a5b67b0
9d8dd37
31b4963
7878c32
bdc24d0
13cccfd
303e1f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class SensitiveFlag1739335129758 { | ||
name = 'SensitiveFlag1739335129758' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "drive_file" ADD "isSensitiveByModerator" boolean NOT NULL DEFAULT false`); | ||
await queryRunner.query(`CREATE INDEX "IDX_e779d1afdfa44dc3d64213cd2e" ON "drive_file" ("isSensitiveByModerator") `); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "public"."IDX_e779d1afdfa44dc3d64213cd2e"`); | ||
await queryRunner.query(`ALTER TABLE "drive_file" DROP COLUMN "isSensitiveByModerator"`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ import { correctFilename } from '@/misc/correct-filename.js'; | |
import { isMimeImage } from '@/misc/is-mime-image.js'; | ||
import { ModerationLogService } from '@/core/ModerationLogService.js'; | ||
import { LoggerService } from '@/core/LoggerService.js'; | ||
import { NotificationService } from '@/core/NotificationService.js'; | ||
|
||
type AddFileArgs = { | ||
/** User who wish to add file */ | ||
|
@@ -129,6 +130,7 @@ export class DriveService { | |
private driveChart: DriveChart, | ||
private perUserDriveChart: PerUserDriveChart, | ||
private instanceChart: InstanceChart, | ||
private notificationService: NotificationService, | ||
) { | ||
const logger = this.loggerService.getLogger('drive', 'blue'); | ||
this.registerLogger = logger.createSubLogger('register', 'yellow'); | ||
|
@@ -660,12 +662,13 @@ export class DriveService { | |
@bindThis | ||
public async updateFile(file: MiDriveFile, values: Partial<MiDriveFile>, updater: MiUser) { | ||
const alwaysMarkNsfw = (await this.roleService.getUserPolicies(file.userId)).alwaysMarkNsfw; | ||
const isModerator = await this.roleService.isModerator(updater); | ||
|
||
if (values.name != null && !this.driveFileEntityService.validateFileName(values.name)) { | ||
throw new DriveService.InvalidFileNameError(); | ||
} | ||
|
||
if (values.isSensitive !== undefined && values.isSensitive !== file.isSensitive && alwaysMarkNsfw && !values.isSensitive) { | ||
if ((values.isSensitive !== undefined && values.isSensitive !== file.isSensitive && alwaysMarkNsfw || (!isModerator && file.isSensitiveByModerator)) && !values.isSensitive) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 括弧の位置間違ってると思う |
||
throw new DriveService.CannotUnmarkSensitiveError(); | ||
} | ||
|
||
|
@@ -680,6 +683,10 @@ export class DriveService { | |
} | ||
} | ||
|
||
if (isModerator && file.userId !== updater.id) { | ||
values.isSensitiveByModerator = values.isSensitive; | ||
} | ||
Comment on lines
+686
to
+688
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. モデレータがアップロードしたファイルを、別のモデレータがセンシティブに設定し、その後本人がセンシティブを解除した場合、おかしな状態になると思う |
||
|
||
await this.driveFilesRepository.update(file.id, values); | ||
|
||
const fileObj = await this.driveFileEntityService.pack(file.id, updater, { self: true }); | ||
|
@@ -689,7 +696,7 @@ export class DriveService { | |
this.globalEventService.publishDriveStream(file.userId, 'fileUpdated', fileObj); | ||
} | ||
|
||
if (await this.roleService.isModerator(updater) && (file.userId !== updater.id)) { | ||
if (isModerator && (file.userId !== updater.id)) { | ||
if (values.isSensitive !== undefined && values.isSensitive !== file.isSensitive) { | ||
const user = file.userId ? await this.usersRepository.findOneByOrFail({ id: file.userId }) : null; | ||
if (values.isSensitive) { | ||
|
@@ -699,6 +706,11 @@ export class DriveService { | |
fileUserUsername: user?.username ?? null, | ||
fileUserHost: user?.host ?? null, | ||
}); | ||
if (file.userId) { | ||
this.notificationService.createNotification(file.userId, 'sensitiveFlagAssigned', { | ||
fileId: file.id, | ||
}); | ||
} | ||
} else { | ||
this.moderationLogService.log(updater, 'unmarkSensitiveDriveFile', { | ||
fileId: file.id, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1行目に句点が付いているので2行目にも付けた方が違和感がないと思う