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 1 commit
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
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5318,6 +5318,10 @@ export interface Locale extends ILocale {
* 選択した項目のみ許可
*/
"consentSelected": string;
/**
* 公開
*/
"isPublic": string;
mattyatea marked this conversation as resolved.
Show resolved Hide resolved
"_bubbleGame": {
/**
* 遊び方
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ pleaseConsentToTracking: "{host}は[プライバシーポリシー]({privacyPoli
consentEssential: "必須項目のみ許可"
consentAll: "全て許可"
consentSelected: "選択した項目のみ許可"
isPublic: "公開"
mattyatea marked this conversation as resolved.
Show resolved Hide resolved

_bubbleGame:
howToPlay: "遊び方"
Expand Down
21 changes: 21 additions & 0 deletions packages/backend/migration/1731806320819-pageIsPublic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export class PageIsPublic1731806320819 {
name = 'PageIsPublic1731806320819'

async up(queryRunner) {
await queryRunner.query(`DROP INDEX "public"."IDX_90148bbc2bf0854428786bfc15"`);
await queryRunner.query(`ALTER TABLE "page" DROP COLUMN "visibility"`);
await queryRunner.query(`DROP TYPE "public"."page_visibility_enum"`);
await queryRunner.query(`ALTER TABLE "page" DROP COLUMN "visibleUserIds"`);
await queryRunner.query(`ALTER TABLE "page" ADD "isPublish" boolean NOT NULL DEFAULT true`);
await queryRunner.query(`CREATE INDEX "IDX_dce798cab7e5478ba4fc15e515" ON "page" ("isPublish") `);
}

async down(queryRunner) {
await queryRunner.query(`DROP INDEX "public"."IDX_dce798cab7e5478ba4fc15e515"`);
await queryRunner.query(`CREATE TYPE "public"."user_profile_followersVisibility_enum_old" AS ENUM('public', 'followers', 'private')`);
await queryRunner.query(`ALTER TABLE "page" ADD "visibleUserIds" character varying(32) array NOT NULL DEFAULT '{}'`);
await queryRunner.query(`CREATE TYPE "public"."page_visibility_enum" AS ENUM('public', 'followers', 'specified')`);
await queryRunner.query(`ALTER TABLE "page" ADD "visibility" "public"."page_visibility_enum" NOT NULL`);
await queryRunner.query(`CREATE INDEX "IDX_90148bbc2bf0854428786bfc15" ON "page" ("visibleUserIds") `);
}
}
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 @@ -99,6 +99,7 @@ export class PageEntityService {
hideTitleWhenPinned: page.hideTitleWhenPinned,
alignCenter: page.alignCenter,
font: page.font,
isPublish: page.isPublish,
script: page.script,
eyeCatchingImageId: page.eyeCatchingImageId,
eyeCatchingImage: page.eyeCatchingImageId ? await this.driveFileEntityService.pack(page.eyeCatchingImageId, me) : null,
Expand Down
15 changes: 3 additions & 12 deletions packages/backend/src/models/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,11 @@ export class MiPage {
})
public script: string;

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

@Index()
@Column({
...id(),
array: true, default: '{}',
@Column('boolean', {
default: true,
})
public visibleUserIds: MiUser['id'][];
public isPublish: boolean;

@Column('integer', {
default: 0,
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 @@ -60,6 +60,7 @@ export const paramDef = {
variables: { type: 'array', items: {
type: 'object', additionalProperties: true,
} },
isPublish: { type: 'boolean' },
script: { type: 'string' },
eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true },
font: { type: 'string', enum: ['serif', 'sans-serif'], default: 'sans-serif' },
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',
isPublish: ps.isPublish,
alignCenter: ps.alignCenter,
hideTitleWhenPinned: ps.hideTitleWhenPinned,
font: ps.font,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const query = this.pagesRepository.createQueryBuilder('page')
.where('page.visibility = \'public\'')
.where('page.isPublish = true')
.andWhere('page.likedCount > 0')
.orderBy('page.likedCount', 'DESC');

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.isPublish && (me == null || (page.userId !== me.id))) {
throw new ApiError(meta.errors.noSuchPage);
}

return await this.pageEntityService.pack(page, me);
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/pages/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const paramDef = {
variables: { type: 'array', items: {
type: 'object', additionalProperties: true,
} },
isPublish: { type: 'boolean' },
script: { type: 'string' },
eyeCatchingImageId: { type: 'string', format: 'misskey:id', nullable: true },
font: { type: 'string', enum: ['serif', 'sans-serif'] },
Expand Down Expand Up @@ -123,6 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
content: ps.content,
variables: ps.variables,
script: ps.script,
isPublish: ps.isPublish,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
alignCenter: ps.alignCenter === undefined ? page.alignCenter : ps.alignCenter,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/endpoints/users/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.pagesRepository.createQueryBuilder('page'), ps.sinceId, ps.untilId)
.andWhere('page.userId = :userId', { userId: ps.userId })
.andWhere('page.visibility = \'public\'');
.andWhere('page.isPublish = true');

const pages = await query
.limit(ps.limit)
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/pages/page-editor/page-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ SPDX-License-Identifier: AGPL-3.0-only

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

<MkSwitch v-model="isPublish">{{ i18n.ts.publish }}</MkSwitch>

<MkSelect v-model="font">
<template #label>{{ i18n.ts._pages.font }}</template>
<option value="serif">{{ i18n.ts._pages.fontSerif }}</option>
Expand Down Expand Up @@ -98,6 +100,7 @@ const eyeCatchingImageId = ref<string | null>(null);
const font = ref('sans-serif');
const content = ref<Misskey.entities.Page['content']>([]);
const alignCenter = ref(false);
const isPublish = ref(false);
const hideTitleWhenPinned = ref(false);

provide('readonly', readonly.value);
Expand All @@ -122,6 +125,7 @@ function getSaveOptions() {
script: '',
hideTitleWhenPinned: hideTitleWhenPinned.value,
alignCenter: alignCenter.value,
isPublish: isPublish.value,
content: content.value,
variables: [],
eyeCatchingImageId: eyeCatchingImageId.value,
Expand Down Expand Up @@ -258,6 +262,7 @@ async function init() {
font.value = page.value.font;
hideTitleWhenPinned.value = page.value.hideTitleWhenPinned;
alignCenter.value = page.value.alignCenter;
isPublish.value = page.value.isPublish;
content.value = page.value.content;
eyeCatchingImageId.value = page.value.eyeCatchingImageId;
} else {
Expand Down
Loading