-
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 7 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'); | ||
|
@@ -590,6 +592,7 @@ export class DriveService { | |
if (info.sensitive && profile!.autoSensitive) file.isSensitive = true; | ||
if (info.sensitive && instance.setSensitiveFlagAutomatically) file.isSensitive = true; | ||
if (userRoleNSFW) file.isSensitive = true; | ||
if (file.isSensitiveByModerator) file.isSensitive = true; | ||
riku6460 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (url !== null) { | ||
file.src = url; | ||
|
@@ -660,6 +663,7 @@ 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(); | ||
|
@@ -680,6 +684,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 +697,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 +707,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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,12 @@ export const meta = { | |
code: 'RESTRICTED_BY_ROLE', | ||
id: '7f59dccb-f465-75ab-5cf4-3ce44e3282f7', | ||
}, | ||
|
||
restrictedByModerator: { | ||
message: 'The isSensitive specified by the administrator cannot be changed.', | ||
code: 'RESTRICTED_BY_ADMINISTRATOR', | ||
id: '20e6c501-e579-400d-97e4-1c7efc286f35', | ||
}, | ||
}, | ||
res: { | ||
type: 'object', | ||
|
@@ -90,6 +96,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | |
throw new ApiError(meta.errors.accessDenied); | ||
} | ||
|
||
if (!await this.roleService.isModerator(me) && file.isSensitiveByModerator) { | ||
throw new ApiError(meta.errors.restrictedByModerator); | ||
} | ||
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. ロールでの処理が updateFile の中にあるので、それに合わせてそっちに移動したほうが良いかも |
||
|
||
let packedFile; | ||
|
||
try { | ||
|
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行目にも付けた方が違和感がないと思う