This commit is contained in:
syuilo 2025-05-04 13:39:37 +09:00
parent 5aeedf59ff
commit b78a58a2f0
10 changed files with 90 additions and 3 deletions

4
locales/index.d.ts vendored
View File

@ -6380,6 +6380,10 @@ export interface Locale extends ILocale {
* semver 使>= 2024.3.1 2024.3.1-custom.0 >= 2024.3.1-0 prerelease
*/
"deliverSuspendedSoftwareDescription": string;
/**
*
*/
"visibleUserGeneratedContentsForNonLoggedInVisitors": string;
};
"_accountMigration": {
/**

View File

@ -1621,6 +1621,7 @@ _serverSettings:
thisSettingWillAutomaticallyOffWhenModeratorsInactive: "一定期間モデレーターのアクティビティが検出されなかった場合、スパム防止のためこの設定は自動でオフになります。"
deliverSuspendedSoftware: "配信停止中のソフトウェア"
deliverSuspendedSoftwareDescription: "脆弱性などの理由で、サーバーのソフトウェアの名前及びバージョンの範囲を指定して配信を停止できます。このバージョン情報はサーバーが提供したものであり、信頼性は保証されません。バージョン指定には semver の範囲指定が使用できますが、>= 2024.3.1 と指定すると 2024.3.1-custom.0 のようなカスタムバージョンが含まれないため、>= 2024.3.1-0 のように prerelease の指定を行うことを推奨します。"
visibleUserGeneratedContentsForNonLoggedInVisitors: "非ログイン訪問者に対するユーザー作成コンテンツの公開範囲"
_accountMigration:
moveFrom: "別のアカウントからこのアカウントに移行"

View File

@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class VisibleUserGeneratedContentsForNonLoggedInVisitors1746330901644 {
name = 'VisibleUserGeneratedContentsForNonLoggedInVisitors1746330901644'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "visibleUserGeneratedContentsForNonLoggedInVisitors" character varying(128) NOT NULL DEFAULT 'local'`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "visibleUserGeneratedContentsForNonLoggedInVisitors"`);
}
}

View File

@ -659,6 +659,12 @@ export class MiMeta {
})
public federationHosts: string[];
@Column('varchar', {
length: 128,
default: 'local',
})
public visibleUserGeneratedContentsForNonLoggedInVisitors: 'all' | 'local' | 'none';
@Column('varchar', {
length: 64,
nullable: true,

View File

@ -546,6 +546,11 @@ export const meta = {
},
},
},
visibleUserGeneratedContentsForNonLoggedInVisitors: {
type: 'string',
enum: ['all', 'local', 'none'],
optional: false, nullable: false,
},
},
},
} as const;
@ -691,6 +696,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
federation: instance.federation,
federationHosts: instance.federationHosts,
deliverSuspendedSoftware: instance.deliverSuspendedSoftware,
visibleUserGeneratedContentsForNonLoggedInVisitors: instance.visibleUserGeneratedContentsForNonLoggedInVisitors,
};
});
}

View File

@ -196,6 +196,10 @@ export const paramDef = {
required: ['software', 'versionRange'],
},
},
visibleUserGeneratedContentsForNonLoggedInVisitors: {
type: 'string',
enum: ['all', 'local', 'none'],
},
},
required: [],
} as const;
@ -690,6 +694,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.federationHosts = ps.federationHosts.filter(Boolean).map(x => x.toLowerCase());
}
if (ps.visibleUserGeneratedContentsForNonLoggedInVisitors !== undefined) {
set.visibleUserGeneratedContentsForNonLoggedInVisitors = ps.visibleUserGeneratedContentsForNonLoggedInVisitors;
}
const before = await this.metaService.fetch(true);
await this.metaService.update(set);

View File

@ -3,10 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { GetterService } from '@/server/api/GetterService.js';
import { DI } from '@/di-symbols.js';
import { MiMeta } from '@/models/Meta.js';
import { ApiError } from '../../error.js';
export const meta = {
@ -46,6 +48,9 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.meta)
private serverSettings: MiMeta,
private noteEntityService: NoteEntityService,
private getterService: GetterService,
) {
@ -59,6 +64,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.signinRequired);
}
if (this.serverSettings.visibleUserGeneratedContentsForNonLoggedInVisitors === 'none' && me == null) {
throw new ApiError(meta.errors.signinRequired);
}
if (this.serverSettings.visibleUserGeneratedContentsForNonLoggedInVisitors === 'local' && note.userHost != null && me == null) {
throw new ApiError(meta.errors.signinRequired);
}
return await this.noteEntityService.pack(note, me, {
detail: true,
});

View File

@ -513,7 +513,12 @@ export class ClientServerService {
vary(reply.raw, 'Accept');
if (user != null) {
if (
user != null && (
this.meta.visibleUserGeneratedContentsForNonLoggedInVisitors === 'all' ||
(this.meta.visibleUserGeneratedContentsForNonLoggedInVisitors === 'local' && user.host == null)
)
) {
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
const me = profile.fields
? profile.fields
@ -577,7 +582,13 @@ export class ClientServerService {
relations: ['user'],
});
if (note && !note.user!.requireSigninToViewContents) {
if (
note &&
!note.user!.requireSigninToViewContents &&
(this.meta.visibleUserGeneratedContentsForNonLoggedInVisitors === 'all' ||
(this.meta.visibleUserGeneratedContentsForNonLoggedInVisitors === 'local' && note.userHost == null)
)
) {
const _note = await this.noteEntityService.pack(note);
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: note.userId });
reply.header('Cache-Control', 'public, max-age=15');

View File

@ -20,6 +20,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.emailRequiredForSignup }}</template>
</MkSwitch>
<MkSelect v-model="visibleUserGeneratedContentsForNonLoggedInVisitors" @update:modelValue="onChange_visibleUserGeneratedContentsForNonLoggedInVisitors">
<template #label>{{ i18n.ts._serverSettings.visibleUserGeneratedContentsForNonLoggedInVisitors }}</template>
<option value="all">{{ i18n.ts.all }}</option>
<option value="local">{{ i18n.ts.localOnly }}</option>
<option value="none">{{ i18n.ts.none }}</option>
</MkSelect>
<FormLink to="/admin/server-rules">{{ i18n.ts.serverRules }}</FormLink>
<MkFolder>
@ -137,9 +144,11 @@ import { definePage } from '@/page.js';
import MkButton from '@/components/MkButton.vue';
import FormLink from '@/components/form/link.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkSelect from '@/components/MkSelect.vue';
const enableRegistration = ref<boolean>(false);
const emailRequiredForSignup = ref<boolean>(false);
const visibleUserGeneratedContentsForNonLoggedInVisitors = ref<string>('all');
const sensitiveWords = ref<string>('');
const prohibitedWords = ref<string>('');
const prohibitedWordsForNameOfUser = ref<string>('');
@ -153,6 +162,7 @@ async function init() {
const meta = await misskeyApi('admin/meta');
enableRegistration.value = !meta.disableRegistration;
emailRequiredForSignup.value = meta.emailRequiredForSignup;
visibleUserGeneratedContentsForNonLoggedInVisitors.value = meta.visibleUserGeneratedContentsForNonLoggedInVisitors;
sensitiveWords.value = meta.sensitiveWords.join('\n');
prohibitedWords.value = meta.prohibitedWords.join('\n');
prohibitedWordsForNameOfUser.value = meta.prohibitedWordsForNameOfUser.join('\n');
@ -189,6 +199,14 @@ function onChange_emailRequiredForSignup(value: boolean) {
});
}
function onChange_visibleUserGeneratedContentsForNonLoggedInVisitors(value: string) {
os.apiWithDialog('admin/update-meta', {
visibleUserGeneratedContentsForNonLoggedInVisitors: value,
}).then(() => {
fetchInstance(true);
});
}
function save_preservedUsernames() {
os.apiWithDialog('admin/update-meta', {
preservedUsernames: preservedUsernames.value.split('\n'),

View File

@ -8769,6 +8769,8 @@ export type operations = {
software: string;
versionRange: string;
}[];
/** @enum {string} */
visibleUserGeneratedContentsForNonLoggedInVisitors: 'all' | 'local' | 'none';
};
};
};
@ -11439,6 +11441,8 @@ export type operations = {
software: string;
versionRange: string;
}[];
/** @enum {string} */
visibleUserGeneratedContentsForNonLoggedInVisitors?: 'all' | 'local' | 'none';
};
};
};