From 6ba754ddd4720dac912acc5e3fc21c3bae50f3f5 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Mon, 9 Sep 2024 12:58:02 +0000 Subject: [PATCH 1/3] fix error handling --- apps/app/src/client/components/PageComment.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/app/src/client/components/PageComment.tsx b/apps/app/src/client/components/PageComment.tsx index 55826a1a851..616f2b4594b 100644 --- a/apps/app/src/client/components/PageComment.tsx +++ b/apps/app/src/client/components/PageComment.tsx @@ -93,8 +93,12 @@ export const PageComment: FC = memo((props: PageCommentProps): onDeleteCommentAfterOperation(); } catch (error: unknown) { - setErrorMessageOnDelete(error as string); - toastError(`error: ${error}`); + const message = error instanceof Error + ? error.message + : (error as any).toString(); + + setErrorMessageOnDelete(message); + toastError(message); } }, [commentToBeDeleted, onDeleteCommentAfterOperation]); From b92e31de5a046f5a50d6ab0fb5d1de0a42f6db5e Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Mon, 9 Sep 2024 13:02:05 +0000 Subject: [PATCH 2/3] fix API route --- apps/app/src/server/routes/comment.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/app/src/server/routes/comment.js b/apps/app/src/server/routes/comment.js index 321a8796991..cbcf33261e4 100644 --- a/apps/app/src/server/routes/comment.js +++ b/apps/app/src/server/routes/comment.js @@ -1,4 +1,5 @@ +import { getIdStringForRef } from '@growi/core'; import { serializeUserSecurely } from '@growi/core/dist/models/serializers'; import { Comment, CommentEvent, commentEvent } from '~/features/comment/server'; @@ -56,7 +57,6 @@ module.exports = function(crowi, app) { const logger = loggerFactory('growi:routes:comment'); const User = crowi.model('User'); const Page = crowi.model('Page'); - const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting'); const ApiResponse = require('../util/apiResponse'); const activityEvent = crowi.event('activity'); @@ -465,6 +465,7 @@ module.exports = function(crowi, app) { } try { + /** @type {import('mongoose').HydratedDocument} */ const comment = await Comment.findById(commentId).exec(); if (comment == null) { @@ -472,12 +473,12 @@ module.exports = function(crowi, app) { } // check whether accessible - const pageId = comment.page; + const pageId = getIdStringForRef(comment.page); const isAccessible = await Page.isAccessiblePageByViewer(pageId, req.user); if (!isAccessible) { throw new Error('Current user is not accessible to this page.'); } - if (req.user._id !== comment.creator.toString()) { + if (getIdStringForRef(req.user) !== getIdStringForRef(comment.creator)) { throw new Error('Current user is not operatable to this comment.'); } From 554ca25719ca1a87b57c9aeb650ee3aff01fd989 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 10 Sep 2024 10:16:34 +0000 Subject: [PATCH 3/3] setup launch-dev --- .github/workflows/ci-app.yml | 4 ++-- apps/app/package.json | 2 +- apps/app/turbo.json | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-app.yml b/.github/workflows/ci-app.yml index bb3f3014856..c943c797f16 100644 --- a/.github/workflows/ci-app.yml +++ b/.github/workflows/ci-app.yml @@ -206,11 +206,11 @@ jobs: yarn global add node-gyp yarn --frozen-lockfile - - name: turbo run dev:ci + - name: turbo run launch-dev:ci working-directory: ./apps/app run: | cp config/ci/.env.local.for-ci .env.development.local - turbo run dev:ci --env-mode=loose + turbo run launch-dev:ci --env-mode=loose env: MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi_dev diff --git a/apps/app/package.json b/apps/app/package.json index aaef901aac5..4357251a65d 100644 --- a/apps/app/package.json +++ b/apps/app/package.json @@ -26,7 +26,7 @@ "dev:migrate:up": "yarn dev:migrate-mongo up -f config/migrate-mongo-config.js", "dev:migrate:down": "yarn dev:migrate-mongo down -f config/migrate-mongo-config.js", "//// for CI": "", - "dev:ci": "yarn cross-env NODE_ENV=development yarn ts-node src/server/app.ts --ci", + "launch-dev:ci": "yarn cross-env NODE_ENV=development yarn dev:migrate && yarn ts-node src/server/app.ts --ci", "lint:typecheck": "npx -y tspc", "lint:eslint": "yarn eslint --quiet \"**/*.{js,jsx,ts,tsx}\"", "lint:styles": "stylelint \"src/**/*.scss\"", diff --git a/apps/app/turbo.json b/apps/app/turbo.json index 03a84546bc1..4b2b0557d79 100644 --- a/apps/app/turbo.json +++ b/apps/app/turbo.json @@ -49,8 +49,9 @@ "cache": false, "persistent": true }, - "dev:ci": { - "dependsOn": ["^dev", "dev:migrate", "dev:styles-prebuilt"], + + "launch-dev:ci": { + "dependsOn": ["^dev", "dev:styles-prebuilt"], "cache": false },