fix: default sensitive not letting users unmark files

This commit is contained in:
Marie 2024-10-20 11:04:48 +02:00
parent ba17776b19
commit 65ac5fef46
No known key found for this signature in database
GPG Key ID: 7ADF6C9CD9A28555
8 changed files with 35 additions and 5 deletions

View File

@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: marie and sharkey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class DefaultSensitive1729414690009 {
name = 'DefaultSensitive1729414690009'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" ADD "defaultSensitive" boolean NOT NULL DEFAULT false`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "defaultSensitive"`);
}
}

View File

@ -560,7 +560,7 @@ export class DriveService {
file.maybeSensitive = info.sensitive; file.maybeSensitive = info.sensitive;
file.maybePorn = info.porn; file.maybePorn = info.porn;
file.isSensitive = user file.isSensitive = user
? this.userEntityService.isLocalUser(user) && profile!.alwaysMarkNsfw ? true : ? this.userEntityService.isLocalUser(user) && (profile!.alwaysMarkNsfw || profile!.defaultSensitive) ? true :
sensitive ?? false sensitive ?? false
: false; : false;

View File

@ -627,6 +627,7 @@ export class UserEntityService implements OnModuleInit {
injectFeaturedNote: profile!.injectFeaturedNote, injectFeaturedNote: profile!.injectFeaturedNote,
receiveAnnouncementEmail: profile!.receiveAnnouncementEmail, receiveAnnouncementEmail: profile!.receiveAnnouncementEmail,
alwaysMarkNsfw: profile!.alwaysMarkNsfw, alwaysMarkNsfw: profile!.alwaysMarkNsfw,
defaultSensitive: profile!.defaultSensitive,
autoSensitive: profile!.autoSensitive, autoSensitive: profile!.autoSensitive,
carefulBot: profile!.carefulBot, carefulBot: profile!.carefulBot,
autoAcceptFollowed: profile!.autoAcceptFollowed, autoAcceptFollowed: profile!.autoAcceptFollowed,

View File

@ -196,6 +196,11 @@ export class MiUserProfile {
}) })
public alwaysMarkNsfw: boolean; public alwaysMarkNsfw: boolean;
@Column('boolean', {
default: false,
})
public defaultSensitive: boolean;
@Column('boolean', { @Column('boolean', {
default: false, default: false,
}) })

View File

@ -516,6 +516,10 @@ export const packedMeDetailedOnlySchema = {
type: 'boolean', type: 'boolean',
nullable: false, optional: false, nullable: false, optional: false,
}, },
defaultSensitive: {
type: 'boolean',
nullable: false, optional: false,
},
autoSensitive: { autoSensitive: {
type: 'boolean', type: 'boolean',
nullable: false, optional: false, nullable: false, optional: false,

View File

@ -193,6 +193,7 @@ export const paramDef = {
injectFeaturedNote: { type: 'boolean' }, injectFeaturedNote: { type: 'boolean' },
receiveAnnouncementEmail: { type: 'boolean' }, receiveAnnouncementEmail: { type: 'boolean' },
alwaysMarkNsfw: { type: 'boolean' }, alwaysMarkNsfw: { type: 'boolean' },
defaultSensitive: { type: 'boolean' },
autoSensitive: { type: 'boolean' }, autoSensitive: { type: 'boolean' },
followingVisibility: { type: 'string', enum: ['public', 'followers', 'private'] }, followingVisibility: { type: 'string', enum: ['public', 'followers', 'private'] },
followersVisibility: { type: 'string', enum: ['public', 'followers', 'private'] }, followersVisibility: { type: 'string', enum: ['public', 'followers', 'private'] },
@ -349,6 +350,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (policies.alwaysMarkNsfw) throw new ApiError(meta.errors.restrictedByRole); if (policies.alwaysMarkNsfw) throw new ApiError(meta.errors.restrictedByRole);
profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw; profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
} }
if (typeof ps.defaultSensitive === 'boolean') profileUpdates.defaultSensitive = ps.defaultSensitive;
if (ps.emailNotificationTypes !== undefined) profileUpdates.emailNotificationTypes = ps.emailNotificationTypes; if (ps.emailNotificationTypes !== undefined) profileUpdates.emailNotificationTypes = ps.emailNotificationTypes;
if (ps.avatarId) { if (ps.avatarId) {

View File

@ -48,7 +48,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.keepOriginalFilename }}</template> <template #label>{{ i18n.ts.keepOriginalFilename }}</template>
<template #caption>{{ i18n.ts.keepOriginalFilenameDescription }}</template> <template #caption>{{ i18n.ts.keepOriginalFilenameDescription }}</template>
</MkSwitch> </MkSwitch>
<MkSwitch v-model="alwaysMarkNsfw" @update:modelValue="saveProfile()"> <MkSwitch v-model="defaultSensitive" @update:modelValue="saveProfile()">
<template #label>{{ i18n.ts.alwaysMarkSensitive }}</template> <template #label>{{ i18n.ts.alwaysMarkSensitive }}</template>
</MkSwitch> </MkSwitch>
</div> </div>
@ -80,7 +80,7 @@ const fetching = ref(true);
const usage = ref<number | null>(null); const usage = ref<number | null>(null);
const capacity = ref<number | null>(null); const capacity = ref<number | null>(null);
const uploadFolder = ref<Misskey.entities.DriveFolder | null>(null); const uploadFolder = ref<Misskey.entities.DriveFolder | null>(null);
const alwaysMarkNsfw = ref($i.alwaysMarkNsfw); const defaultSensitive = ref($i.defaultSensitive);
const meterStyle = computed(() => { const meterStyle = computed(() => {
if (!capacity.value || !usage.value) return {}; if (!capacity.value || !usage.value) return {};
@ -127,14 +127,14 @@ function chooseUploadFolder() {
function saveProfile() { function saveProfile() {
misskeyApi('i/update', { misskeyApi('i/update', {
alwaysMarkNsfw: !!alwaysMarkNsfw.value, defaultSensitive: !!defaultSensitive.value,
}).catch(err => { }).catch(err => {
os.alert({ os.alert({
type: 'error', type: 'error',
title: i18n.ts.error, title: i18n.ts.error,
text: err.message, text: err.message,
}); });
alwaysMarkNsfw.value = true; defaultSensitive.value = true;
}); });
} }

View File

@ -3994,6 +3994,7 @@ export type components = {
injectFeaturedNote: boolean; injectFeaturedNote: boolean;
receiveAnnouncementEmail: boolean; receiveAnnouncementEmail: boolean;
alwaysMarkNsfw: boolean; alwaysMarkNsfw: boolean;
defaultSensitive: boolean;
autoSensitive: boolean; autoSensitive: boolean;
carefulBot: boolean; carefulBot: boolean;
autoAcceptFollowed: boolean; autoAcceptFollowed: boolean;
@ -20545,6 +20546,7 @@ export type operations = {
injectFeaturedNote?: boolean; injectFeaturedNote?: boolean;
receiveAnnouncementEmail?: boolean; receiveAnnouncementEmail?: boolean;
alwaysMarkNsfw?: boolean; alwaysMarkNsfw?: boolean;
defaultSensitive?: boolean;
autoSensitive?: boolean; autoSensitive?: boolean;
/** @enum {string} */ /** @enum {string} */
followingVisibility?: 'public' | 'followers' | 'private'; followingVisibility?: 'public' | 'followers' | 'private';