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

enhance(Page): ページを非公開にできるように #821

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9497,6 +9497,18 @@ export interface Locale extends ILocale {
* 特殊
*/
"specialBlocks": string;
/**
* 公開範囲
*/
"visibility": string;
/**
* 公開
*/
"public": string;
/**
* 非公開
*/
"private": string;
"blocks": {
/**
* テキスト
Expand Down
3 changes: 3 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,9 @@ _pages:
contentBlocks: "コンテンツ"
inputBlocks: "入力"
specialBlocks: "特殊"
visibility: "公開範囲"
public: "公開"
private: "非公開"
blocks:
text: "テキスト"
textarea: "テキストエリア"
Expand Down
19 changes: 19 additions & 0 deletions packages/backend/migration/1733563840208-page-visibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class PageVisibility1733563840208 {
name = 'PageVisibility1733563840208'

async up(queryRunner) {
await queryRunner.query(`ALTER TYPE "public"."page_visibility_enum" RENAME TO "page_visibility_enum_old"`);
await queryRunner.query(`CREATE TYPE "public"."page_visibility_enum" AS ENUM('public', 'private')`);
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" TYPE "public"."page_visibility_enum" USING "visibility"::"text"::"public"."page_visibility_enum"`);
await queryRunner.query(`DROP TYPE "public"."page_visibility_enum_old"`);
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" SET DEFAULT 'public'`);
}

async down(queryRunner) {
await queryRunner.query(`CREATE TYPE "public"."page_visibility_enum_old" AS ENUM('followers', 'public', 'specified')`);
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" TYPE "public"."page_visibility_enum_old" USING "visibility"::"text"::"public"."page_visibility_enum_old"`);
await queryRunner.query(`DROP TYPE "public"."page_visibility_enum"`);
await queryRunner.query(`ALTER TYPE "public"."page_visibility_enum_old" RENAME TO "page_visibility_enum"`);
await queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "visibility" DROP DEFAULT`);
}
}
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/PageEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class PageEntityService {
attachedFiles: this.driveFileEntityService.packMany((await Promise.all(attachedFiles)).filter(isNotNull), me),
likedCount: page.likedCount,
isLiked: meId ? await this.pageLikesRepository.exists({ where: { pageId: page.id, userId: meId } }) : undefined,
visibility: page.visibility,
});
}

Expand Down
15 changes: 5 additions & 10 deletions packages/backend/src/models/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,13 @@ export class MiPage {

/**
* public ... 公開
* followers ... フォロワーのみ
* specified ... visibleUserIds で指定したユーザーのみ
* private ... 非公開
*/
@Column('enum', { enum: ['public', 'followers', 'specified'] })
public visibility: 'public' | 'followers' | 'specified';

@Index()
@Column({
...id(),
array: true, default: '{}',
@Column('enum', {
enum: ['public', 'private'],
default: 'public',
})
public visibleUserIds: MiUser['id'][];
public visibility: 'public' | 'private';

@Column('integer', {
default: 0,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/json-schema/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ export const packedPageSchema = {
type: 'boolean',
optional: true, nullable: false,
},
visibility: {
type: 'string',
optional: false, nullable: false,
enum: ['public', 'private'],
},
},
} as const;

Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/server/api/endpoints/pages/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const paramDef = {
font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' },
alignCenter: { type: 'boolean', default: false },
hideTitleWhenPinned: { type: 'boolean', default: false },
visibility: { type: 'string', enum: ['public', 'private'] },
},
required: ['title', 'name', 'content', 'variables', 'script'],
} as const;
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
script: ps.script,
eyeCatchingImageId: eyeCatchingImage ? eyeCatchingImage.id : null,
userId: me.id,
visibility: 'public',
visibility: ps.visibility,
alignCenter: ps.alignCenter,
hideTitleWhenPinned: ps.hideTitleWhenPinned,
font: ps.font,
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/server/api/endpoints/pages/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchPage);
}

if (page.visibility === 'private' && (me == null || (page.userId !== me.id))) {
throw new ApiError(meta.errors.noSuchPage);
}

return await this.pageEntityService.pack(page, me);
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/server/api/endpoints/pages/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const paramDef = {
font: { type: 'string', enum: ['serif', 'sans-serif'] },
alignCenter: { type: 'boolean' },
hideTitleWhenPinned: { type: 'boolean' },
visibility: { type: 'string', enum: ['public', 'private'] },
},
required: ['pageId', 'title', 'name', 'content', 'variables', 'script'],
} as const;
Expand Down Expand Up @@ -129,6 +130,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
hideTitleWhenPinned: ps.hideTitleWhenPinned === undefined ? page.hideTitleWhenPinned : ps.hideTitleWhenPinned,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
font: ps.font === undefined ? page.font : ps.font,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
visibility: ps.visibility === undefined ? page.visibility : ps.visibility,
eyeCatchingImageId: ps.eyeCatchingImageId === null
? null
: ps.eyeCatchingImageId === undefined
Expand Down
1 change: 1 addition & 0 deletions packages/backend/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const page = async (user: UserToken, page: Partial<misskey.entities.Page>
eyeCatchingImageId: null,
font: 'sans-serif' as FIXME,
hideTitleWhenPinned: false,
visibility: 'public',
name: '1678594845072',
script: '',
summary: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkPagePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<article>
<header>
<h1 :title="page.title">{{ page.title }}</h1>
<h1 :title="page.title">{{ page.title || page.name }} <i v-if="page.visibility === 'private'" class="ti ti-lock"></i></h1>
</header>
<p v-if="page.summary" :title="page.summary">{{ page.summary.length > 85 ? page.summary.slice(0, 85) + '…' : page.summary }}</p>
<footer>
Expand Down
13 changes: 11 additions & 2 deletions packages/frontend/src/pages/page-editor/page-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<option value="sans-serif">{{ i18n.ts._pages.fontSansSerif }}</option>
</MkSelect>

<MkSelect v-model="visibility">
<template #label>{{ i18n.ts._pages.visibility }}</template>
<option value="public">{{ i18n.ts._pages.public }}</option>
<option value="private">{{ i18n.ts._pages.private }}</option>
</MkSelect>

<MkSwitch v-model="hideTitleWhenPinned">{{ i18n.ts._pages.hideTitleWhenPinned }}</MkSwitch>

<div class="eyeCatch">
Expand Down Expand Up @@ -96,6 +102,7 @@ const name = ref(Date.now().toString());
const eyeCatchingImage = ref<Misskey.entities.DriveFile | null>(null);
const eyeCatchingImageId = ref<string | null>(null);
const font = ref('sans-serif');
const visibility = ref('public');
const content = ref<Misskey.entities.Page['content']>([]);
const alignCenter = ref(false);
const hideTitleWhenPinned = ref(false);
Expand All @@ -119,6 +126,7 @@ function getSaveOptions() {
name: name.value.trim(),
summary: summary.value,
font: font.value,
visibility: visibility.value,
script: '',
hideTitleWhenPinned: hideTitleWhenPinned.value,
alignCenter: alignCenter.value,
Expand Down Expand Up @@ -256,6 +264,7 @@ async function init() {
currentName.value = page.value.name;
summary.value = page.value.summary;
font.value = page.value.font;
visibility.value = page.value.visibility;
hideTitleWhenPinned.value = page.value.hideTitleWhenPinned;
alignCenter.value = page.value.alignCenter;
content.value = page.value.content;
Expand Down Expand Up @@ -286,8 +295,8 @@ const headerTabs = computed(() => [{

definePageMetadata(() => ({
title: props.initPageId ? i18n.ts._pages.editPage
: props.initPageName && props.initUser ? i18n.ts._pages.readPage
: i18n.ts._pages.newPage,
: props.initPageName && props.initUser ? i18n.ts._pages.readPage
: i18n.ts._pages.newPage,
icon: 'ti ti-pencil',
}));
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SPDX-License-Identifier: AGPL-3.0-only
/>
</div>
<div :class="$style.pageBannerTitle" class="_gaps_s">
<h1>{{ page.title || page.name }}</h1>
<h1>{{ page.title || page.name }} <i v-if="page.visibility === 'private'" class="ti ti-lock"></i></h1>
<div :class="$style.pageBannerTitleSub">
<div v-if="page.user" :class="$style.pageBannerTitleUser">
<MkAvatar :user="page.user" :class="$style.avatar" indicator link preview/> <MkA :to="`/@${username}`"><MkUserName :user="page.user" :nowrap="false"/></MkA>
Expand Down Expand Up @@ -80,7 +80,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<div :class="$style.pageLinks">
<MkA v-if="!$i || $i.id !== page.userId" :to="`/@${username}/pages/${pageName}/view-source`" class="link">{{ i18n.ts._pages.viewSource }}</MkA>
<template v-if="$i && $i.id === page.userId">
<template v-if="($i && $i.id === page.userId) && page.visibility === 'public'">
<MkA :to="`/pages/edit/${page.id}`" class="link">{{ i18n.ts._pages.editThisPage }}</MkA>
<button v-if="$i.pinnedPageId === page.id" class="link _textButton" @click="pin(false)">{{ i18n.ts.unpin }}</button>
<button v-else class="link _textButton" @click="pin(true)">{{ i18n.ts.pin }}</button>
Expand Down
6 changes: 6 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,8 @@ export type components = {
attachedFiles: components['schemas']['DriveFile'][];
likedCount: number;
isLiked?: boolean;
/** @enum {string} */
visibility: 'public' | 'private';
};
PageBlock: OneOf<[{
id: string;
Expand Down Expand Up @@ -25230,6 +25232,8 @@ export type operations = {
alignCenter?: boolean;
/** @default false */
hideTitleWhenPinned?: boolean;
/** @enum {string} */
visibility?: 'public' | 'private';
};
};
};
Expand Down Expand Up @@ -25564,6 +25568,8 @@ export type operations = {
font?: 'serif' | 'sans-serif';
alignCenter?: boolean;
hideTitleWhenPinned?: boolean;
/** @enum {string} */
visibility?: 'public' | 'private';
};
};
};
Expand Down
Loading