enhance(Page): ページを非公開にできるように (MisskeyIO#821)
This commit is contained in:
parent
6a416468e3
commit
1a81d3fa46
14 changed files with 75 additions and 16 deletions
12
locales/index.d.ts
vendored
12
locales/index.d.ts
vendored
|
@ -9497,6 +9497,18 @@ export interface Locale extends ILocale {
|
|||
* 特殊
|
||||
*/
|
||||
"specialBlocks": string;
|
||||
/**
|
||||
* 公開範囲
|
||||
*/
|
||||
"visibility": string;
|
||||
/**
|
||||
* 公開
|
||||
*/
|
||||
"public": string;
|
||||
/**
|
||||
* 非公開
|
||||
*/
|
||||
"private": string;
|
||||
"blocks": {
|
||||
/**
|
||||
* テキスト
|
||||
|
|
|
@ -2495,6 +2495,9 @@ _pages:
|
|||
contentBlocks: "コンテンツ"
|
||||
inputBlocks: "入力"
|
||||
specialBlocks: "特殊"
|
||||
visibility: "公開範囲"
|
||||
public: "公開"
|
||||
private: "非公開"
|
||||
blocks:
|
||||
text: "テキスト"
|
||||
textarea: "テキストエリア"
|
||||
|
|
19
packages/backend/migration/1733563840208-page-visibility.js
Normal file
19
packages/backend/migration/1733563840208-page-visibility.js
Normal file
|
@ -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`);
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
@ -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>
|
||||
|
|
|
@ -4619,6 +4619,8 @@ export type components = {
|
|||
attachedFiles: components['schemas']['DriveFile'][];
|
||||
likedCount: number;
|
||||
isLiked?: boolean;
|
||||
/** @enum {string} */
|
||||
visibility: 'public' | 'private';
|
||||
};
|
||||
PageBlock: OneOf<[{
|
||||
id: string;
|
||||
|
@ -25230,6 +25232,8 @@ export type operations = {
|
|||
alignCenter?: boolean;
|
||||
/** @default false */
|
||||
hideTitleWhenPinned?: boolean;
|
||||
/** @enum {string} */
|
||||
visibility?: 'public' | 'private';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -25564,6 +25568,8 @@ export type operations = {
|
|||
font?: 'serif' | 'sans-serif';
|
||||
alignCenter?: boolean;
|
||||
hideTitleWhenPinned?: boolean;
|
||||
/** @enum {string} */
|
||||
visibility?: 'public' | 'private';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue