Skip to content

Commit

Permalink
Merge pull request #9083 from weseek/fix/removing-comment
Browse files Browse the repository at this point in the history
fix: Removing comment doesn't work
  • Loading branch information
mergify[bot] authored Sep 10, 2024
2 parents ca70593 + 554ca25 commit a4dae48
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
8 changes: 6 additions & 2 deletions apps/app/src/client/components/PageComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ export const PageComment: FC<PageCommentProps> = 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]);

Expand Down
7 changes: 4 additions & 3 deletions apps/app/src/server/routes/comment.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -465,19 +465,20 @@ module.exports = function(crowi, app) {
}

try {
/** @type {import('mongoose').HydratedDocument<import('~/interfaces/comment').IComment>} */
const comment = await Comment.findById(commentId).exec();

if (comment == null) {
throw new Error('This comment does not exist.');
}

// 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.');
}

Expand Down
5 changes: 3 additions & 2 deletions apps/app/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},

Expand Down

0 comments on commit a4dae48

Please sign in to comment.