From cc25a4e6a3ac00f5acc5b3d5cf1530f1111f8b63 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 13 Aug 2024 08:33:34 +0000 Subject: [PATCH 1/5] fix GetAdditionalTargetUsers --- apps/app/src/server/service/pre-notify.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/app/src/server/service/pre-notify.ts b/apps/app/src/server/service/pre-notify.ts index 6e8c912c431..6a9eeaeb811 100644 --- a/apps/app/src/server/service/pre-notify.ts +++ b/apps/app/src/server/service/pre-notify.ts @@ -11,9 +11,8 @@ export type PreNotifyProps = { } export type PreNotify = (props: PreNotifyProps) => Promise; -export type GeneratePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: (activity?: ActivityDocument) => Ref[]) => PreNotify; - -export type GetAdditionalTargetUsers = (activity: ActivityDocument) => Ref[]; +export type GetAdditionalTargetUsers = (activity: ActivityDocument) => Promise[]>; +export type GeneratePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: GetAdditionalTargetUsers) => PreNotify; interface IPreNotifyService { generateInitialPreNotifyProps: (PreNotifyProps) => { notificationTargetUsers?: Ref[] }, @@ -48,7 +47,7 @@ class PreNotifyService implements IPreNotifyService { notificationTargetUsers?.push(...activeNotificationUsers); } else { - const AdditionalTargetUsers = getAdditionalTargetUsers(activity); + const AdditionalTargetUsers = await getAdditionalTargetUsers(activity); notificationTargetUsers?.push( ...activeNotificationUsers, From 2366119704cf5d2010ad1c9cd04c80238d6e575e Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 13 Aug 2024 08:33:42 +0000 Subject: [PATCH 2/5] tidy up types --- apps/app/src/server/routes/comment.js | 1 + apps/app/src/server/service/activity.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/app/src/server/routes/comment.js b/apps/app/src/server/routes/comment.js index 2f40bd51fa5..188c72430c2 100644 --- a/apps/app/src/server/routes/comment.js +++ b/apps/app/src/server/routes/comment.js @@ -275,6 +275,7 @@ module.exports = function(crowi, app) { action: SupportedAction.ACTION_COMMENT_CREATE, }; + /** @type {import('../service/pre-notify').GetAdditionalTargetUsers} */ const getAdditionalTargetUsers = async(activity) => { const mentionedUsers = await crowi.commentService.getMentionedUsers(activity.event); diff --git a/apps/app/src/server/service/activity.ts b/apps/app/src/server/service/activity.ts index 699bfbb6448..fddd8dabedd 100644 --- a/apps/app/src/server/service/activity.ts +++ b/apps/app/src/server/service/activity.ts @@ -1,14 +1,16 @@ import type { IPage } from '@growi/core'; import mongoose from 'mongoose'; +import type { IActivity, SupportedActionType } from '~/interfaces/activity'; import { - IActivity, SupportedActionType, AllSupportedActions, ActionGroupSize, + AllSupportedActions, ActionGroupSize, AllEssentialActions, AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions, } from '~/interfaces/activity'; -import Activity, { ActivityDocument } from '~/server/models/activity'; +import type { ActivityDocument } from '~/server/models/activity'; +import Activity from '~/server/models/activity'; import loggerFactory from '../../utils/logger'; -import Crowi from '../crowi'; +import type Crowi from '../crowi'; import type { GeneratePreNotify, GetAdditionalTargetUsers } from './pre-notify'; From 4dab8cc843a046ea697194f37982ecd763f60a19 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 13 Aug 2024 08:53:59 +0000 Subject: [PATCH 3/5] fix parsing body --- apps/app/src/server/routes/comment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/app/src/server/routes/comment.js b/apps/app/src/server/routes/comment.js index 188c72430c2..0ce38be03e4 100644 --- a/apps/app/src/server/routes/comment.js +++ b/apps/app/src/server/routes/comment.js @@ -368,9 +368,9 @@ module.exports = function(crowi, app) { api.update = async function(req, res) { const { commentForm } = req.body; - const commentStr = commentForm.comment; - const commentId = commentForm.comment_id; - const revision = commentForm.revision_id; + const commentStr = commentForm?.comment; + const commentId = commentForm?.comment_id; + const revision = commentForm?.revision_id; if (commentStr === '') { return res.json(ApiResponse.error('Comment text is required')); From 04295e15133bb108cdfcf84d571661707c3ad707 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 13 Aug 2024 08:55:47 +0000 Subject: [PATCH 4/5] fix comparing id --- apps/app/src/server/routes/comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/app/src/server/routes/comment.js b/apps/app/src/server/routes/comment.js index 0ce38be03e4..321a8796991 100644 --- a/apps/app/src/server/routes/comment.js +++ b/apps/app/src/server/routes/comment.js @@ -394,7 +394,7 @@ module.exports = function(crowi, app) { if (!isAccessible) { throw new Error('Current user is not accessible to this page.'); } - if (req.user.id !== comment.creator.toString()) { + if (req.user._id.toString() !== comment.creator.toString()) { throw new Error('Current user is not operatable to this comment.'); } @@ -477,7 +477,7 @@ module.exports = function(crowi, app) { if (!isAccessible) { throw new Error('Current user is not accessible to this page.'); } - if (req.user.id !== comment.creator.toString()) { + if (req.user._id !== comment.creator.toString()) { throw new Error('Current user is not operatable to this comment.'); } From 8d42a576b8a4d7d74dadb8f2964d56ea7965f564 Mon Sep 17 00:00:00 2001 From: Yuki Takei Date: Tue, 13 Aug 2024 09:01:07 +0000 Subject: [PATCH 5/5] fix lint errors --- apps/app/src/server/service/page/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/app/src/server/service/page/index.ts b/apps/app/src/server/service/page/index.ts index 789607b39a0..eee60ab5e78 100644 --- a/apps/app/src/server/service/page/index.ts +++ b/apps/app/src/server/service/page/index.ts @@ -711,7 +711,7 @@ class PageService implements IPageService { await this.renameDescendantsWithStream(page, newPagePath, user, options, false, descendantsSubscribedSets); const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref[]; - const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers }); + const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers }); this.activityEvent.emit('updated', activity, page, preNotify); } @@ -1702,7 +1702,7 @@ class PageService implements IPageService { const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref[]; - const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers }); + const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers }); this.activityEvent.emit('updated', activity, page, preNotify); @@ -2021,7 +2021,7 @@ class PageService implements IPageService { await this.deleteCompletelyDescendantsWithStream(page, user, options, false, descendantsSubscribedSets); const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref[]; - const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers }); + const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers }); this.activityEvent.emit('updated', activity, page, preNotify); @@ -2068,7 +2068,7 @@ class PageService implements IPageService { const pages = await this.deleteCompletelyDescendantsWithStream(page, user, options, true, descendantsSubscribedSets); const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref[]; - const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers }); + const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers }); this.activityEvent.emit('updated', activity, page, preNotify); @@ -2304,7 +2304,7 @@ class PageService implements IPageService { await this.revertDeletedDescendantsWithStream(page, user, options, false, descendantsSubscribedSets); const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref[]; - const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers }); + const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers }); this.activityEvent.emit('updated', activity, page, preNotify);