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: ノートの閲覧にログイン必須にする設定 #14799

Merged
merged 13 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Unreleased

### General
-
- Feat: コンテンツの表示にログインを必須にできるように

### Client
- Enhance: Bull DashboardでRelationship Queueの状態も確認できるように
Expand Down
22 changes: 22 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5190,6 +5190,28 @@ export interface Locale extends ILocale {
* 名前に禁止されている文字列が含まれています。この名前を使用したい場合は、サーバー管理者にお問い合わせください。
*/
"yourNameContainsProhibitedWordsDescription": string;
/**
* このコンテンツの閲覧にはログインが必要と作者によって設定されています
*/
"thisContentsAreMarkedAsSigninRequiredByAuthor": string;
"_accountSettings": {
/**
* コンテンツの表示にログインを必須にする
*/
"signinRequiredForShowContents": string;
/**
* あなたのプロフィールやノートなどの作成したコンテンツを表示するのにログインを必須にします。クローラーから情報を収集されるのを防ぐ効果が期待できます。
*/
"signinRequiredForShowContentsDescription1": string;
/**
* URLのプレビューや、コンテンツの埋め込みも使用不可になります。
*/
"signinRequiredForShowContentsDescription2": string;
/**
* リモートサーバーに連合されたコンテンツにはこれらの制限は適用されません。
*/
"signinRequiredForShowContentsDescription3": string;
};
"_abuseUserReport": {
/**
* 転送
Expand Down
7 changes: 7 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,13 @@ prohibitedWordsForNameOfUser: "禁止ワード(ユーザーの名前)"
prohibitedWordsForNameOfUserDescription: "このリストに含まれる文字列がユーザーの名前に含まれる場合、ユーザーの名前の変更を拒否します。モデレーター権限を持つユーザーはこの制限の影響を受けません。"
yourNameContainsProhibitedWords: "変更しようとした名前に禁止された文字列が含まれています"
yourNameContainsProhibitedWordsDescription: "名前に禁止されている文字列が含まれています。この名前を使用したい場合は、サーバー管理者にお問い合わせください。"
thisContentsAreMarkedAsSigninRequiredByAuthor: "このコンテンツの閲覧にはログインが必要と作者によって設定されています"

_accountSettings:
signinRequiredForShowContents: "コンテンツの表示にログインを必須にする"
signinRequiredForShowContentsDescription1: "あなたのプロフィールやノートなどの作成したコンテンツを表示するのにログインを必須にします。クローラーから情報を収集されるのを防ぐ効果が期待できます。"
signinRequiredForShowContentsDescription2: "URLのプレビューや、コンテンツの埋め込みも使用不可になります。"
signinRequiredForShowContentsDescription3: "リモートサーバーに連合されたコンテンツにはこれらの制限は適用されません。"

_abuseUserReport:
forward: "転送"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class SigninRequiredForShowContents1729333924409 {
name = 'SigninRequiredForShowContents1729333924409'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" ADD "signinRequiredForShowContents" boolean NOT NULL DEFAULT false`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "signinRequiredForShowContents"`);
}
}
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/ApRendererService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export class ApRendererService {
summary: profile.description ? this.mfmService.toHtml(mfm.parse(profile.description)) : null,
_misskey_summary: profile.description,
_misskey_followedMessage: profile.followedMessage,
_misskey_signinRequiredForShowContents: user.signinRequiredForShowContents,
icon: avatar ? this.renderImage(avatar) : null,
image: banner ? this.renderImage(banner) : null,
tag,
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/misc/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ const extension_context_definition = {
'_misskey_votes': 'misskey:_misskey_votes',
'_misskey_summary': 'misskey:_misskey_summary',
'_misskey_followedMessage': 'misskey:_misskey_followedMessage',
'_misskey_signinRequiredForShowContents': 'misskey:_misskey_signinRequiredForShowContents',
'isCat': 'misskey:isCat',
// vcard
vcard: 'http://www.w3.org/2006/vcard/ns#',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export class ApPersonService implements OnModuleInit {
tags,
isBot,
isCat: (person as any).isCat === true,
signinRequiredForShowContents: (person as any).signinRequiredForShowContents === true,
emojis,
})) as MiRemoteUser;

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IObject {
summary?: string;
_misskey_summary?: string;
_misskey_followedMessage?: string | null;
_misskey_signinRequiredForShowContents?: boolean;
published?: string;
cc?: ApObject;
to?: ApObject;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export class NoteEntityService implements OnModuleInit {
}
}

if (packedNote.user.signinRequiredForShowContents && meId == null) {
hide = true;
}

if (hide) {
packedNote.visibleUserIds = undefined;
packedNote.fileIds = [];
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export class UserEntityService implements OnModuleInit {
}))) : [],
isBot: user.isBot,
isCat: user.isCat,
signinRequiredForShowContents: user.signinRequiredForShowContents === false ? undefined : true,
instance: user.host ? this.federatedInstanceService.federatedInstanceCache.fetch(user.host).then(instance => instance ? {
name: instance.name,
softwareName: instance.softwareName,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ export class MiUser {
})
public isHibernated: boolean;

@Column('boolean', {
default: false,
})
public signinRequiredForShowContents: boolean;

// アカウントが削除されたかどうかのフラグだが、完全に削除される際は物理削除なので実質削除されるまでの「削除が進行しているかどうか」のフラグ
@Column('boolean', {
default: false,
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export const packedUserLiteSchema = {
type: 'boolean',
nullable: false, optional: true,
},
signinRequiredForShowContents: {
type: 'boolean',
nullable: false, optional: true,
},
instance: {
type: 'object',
nullable: false, optional: true,
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/src/server/api/GetterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export class GetterService {
return note;
}

@bindThis
public async getNoteWithUser(noteId: MiNote['id']) {
const note = await this.notesRepository.findOne({ where: { id: noteId }, relations: ['user'] });

if (note == null) {
throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', 'No such note.');
}

return note;
}

/**
* Get user for API processing
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const paramDef = {
autoAcceptFollowed: { type: 'boolean' },
noCrawle: { type: 'boolean' },
preventAiLearning: { type: 'boolean' },
signinRequiredForShowContents: { type: 'boolean' },
isBot: { type: 'boolean' },
isCat: { type: 'boolean' },
injectFeaturedNote: { type: 'boolean' },
Expand Down Expand Up @@ -334,6 +335,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (typeof ps.autoAcceptFollowed === 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.noCrawle === 'boolean') profileUpdates.noCrawle = ps.noCrawle;
if (typeof ps.preventAiLearning === 'boolean') profileUpdates.preventAiLearning = ps.preventAiLearning;
if (typeof ps.signinRequiredForShowContents === 'boolean') updates.signinRequiredForShowContents = ps.signinRequiredForShowContents;
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
Expand Down
12 changes: 11 additions & 1 deletion packages/backend/src/server/api/endpoints/notes/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const meta = {
code: 'NO_SUCH_NOTE',
id: '24fcbfc6-2e37-42b6-8388-c29b3861a08d',
},

signinRequired: {
message: 'Signin required.',
code: 'SIGNIN_REQUIRED',
id: '8e75455b-738c-471d-9f80-62693f33372e',
},
},
} as const;

Expand All @@ -44,11 +50,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private getterService: GetterService,
) {
super(meta, paramDef, async (ps, me) => {
const note = await this.getterService.getNote(ps.noteId).catch(err => {
const note = await this.getterService.getNoteWithUser(ps.noteId).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
throw err;
});

if (note.user!.signinRequiredForShowContents && me == null) {
throw new ApiError(meta.errors.signinRequired);
}

return await this.noteEntityService.pack(note, me, {
detail: true,
});
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export const meta = {
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: '91c8cb9f-36ed-46e7-9ca2-7df96ed6e222',
},

signinRequired: {
message: 'Signin required.',
code: 'SIGNIN_REQUIRED',
id: 'd1588a9e-4b4d-4c07-807f-16f1486577a2',
},
},
} as const;

Expand Down
11 changes: 7 additions & 4 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,15 @@ export class ClientServerService {
fastify.get<{ Params: { note: string; } }>('/notes/:note', async (request, reply) => {
vary(reply.raw, 'Accept');

const note = await this.notesRepository.findOneBy({
id: request.params.note,
visibility: In(['public', 'home']),
const note = await this.notesRepository.findOne({
where: {
id: request.params.note,
visibility: In(['public', 'home']),
},
relations: ['user'],
});

if (note) {
if (note && !note.user!.signinRequiredForShowContents) {
const _note = await this.noteEntityService.pack(note);
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: note.userId });
reply.header('Cache-Control', 'public, max-age=15');
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkFollowButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { host } from '@@/js/config.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { useStream } from '@/stream.js';
import { i18n } from '@/i18n.js';
import { claimAchievement } from '@/scripts/achievements.js';
import { pleaseLogin } from '@/scripts/please-login.js';
import { host } from '@@/js/config.js';
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
Expand Down Expand Up @@ -80,7 +80,7 @@ function onFollowChange(user: Misskey.entities.UserDetailed) {
}
async function onClick() {
pleaseLogin(undefined, { type: 'web', path: `/@${props.user.username}@${props.user.host ?? host}` });
pleaseLogin({ openOnRemote: { type: 'web', path: `/@${props.user.username}@${props.user.host ?? host}` } });
wait.value = true;
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/components/MkNote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ if (!props.mock) {
}
function renote(viaKeyboard = false) {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
showMovedDialog();
const { menu } = getRenoteMenu({ note: note.value, renoteButton, mock: props.mock });
Expand All @@ -429,7 +429,7 @@ function renote(viaKeyboard = false) {
}
function reply(): void {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
if (props.mock) {
return;
}
Expand All @@ -442,7 +442,7 @@ function reply(): void {
}
function react(): void {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
showMovedDialog();
if (appearNote.value.reactionAcceptance === 'likeOnly') {
sound.playMisskeySfx('reaction');
Expand Down Expand Up @@ -563,7 +563,7 @@ function showRenoteMenu(): void {
}
if (isMyRenote) {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
os.popupMenu([
getCopyNoteLinkMenu(note.value, i18n.ts.copyLinkRenote),
{ type: 'divider' },
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/src/components/MkNoteDetailed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ import { computed, inject, onMounted, provide, ref, shallowRef } from 'vue';
import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js';
import { isLink } from '@@/js/is-link.js';
import { host } from '@@/js/config.js';
import MkNoteSub from '@/components/MkNoteSub.vue';
import MkNoteSimple from '@/components/MkNoteSimple.vue';
import MkReactionsViewer from '@/components/MkReactionsViewer.vue';
Expand All @@ -230,7 +231,6 @@ import { reactionPicker } from '@/scripts/reaction-picker.js';
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm.js';
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
import { host } from '@@/js/config.js';
import { getNoteClipMenu, getNoteMenu, getRenoteMenu } from '@/scripts/get-note-menu.js';
import { useNoteCapture } from '@/scripts/use-note-capture.js';
import { deepClone } from '@/scripts/clone.js';
Expand Down Expand Up @@ -404,15 +404,15 @@ if (appearNote.value.reactionAcceptance === 'likeOnly') {
}
function renote() {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
showMovedDialog();
const { menu } = getRenoteMenu({ note: note.value, renoteButton });
os.popupMenu(menu, renoteButton.value);
}
function reply(): void {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
showMovedDialog();
os.post({
reply: appearNote.value,
Expand All @@ -423,7 +423,7 @@ function reply(): void {
}
function react(): void {
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
showMovedDialog();
if (appearNote.value.reactionAcceptance === 'likeOnly') {
sound.playMisskeySfx('reaction');
Expand Down Expand Up @@ -499,7 +499,7 @@ async function clip(): Promise<void> {
function showRenoteMenu(): void {
if (!isMyRenote) return;
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
os.popupMenu([{
text: i18n.ts.unrenote,
icon: 'ti ti-trash',
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/MkPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { computed, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { host } from '@@/js/config.js';
import { useInterval } from '@@/js/use-interval.js';
import type { OpenOnRemoteOptions } from '@/scripts/please-login.js';
import { sum } from '@/scripts/array.js';
import { pleaseLogin } from '@/scripts/please-login.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
import { host } from '@@/js/config.js';
import { useInterval } from '@@/js/use-interval.js';
const props = defineProps<{
noteId: string;
Expand Down Expand Up @@ -85,7 +85,7 @@ if (props.poll.expiresAt) {
const vote = async (id) => {
if (props.readOnly || closed.value || isVoted.value) return;
pleaseLogin(undefined, pleaseLoginContext.value);
pleaseLogin({ openOnRemote: pleaseLoginContext.value });
const { canceled } = await os.confirm({
type: 'question',
Expand Down
Loading
Loading