diff --git a/apps/app/src/server/routes/comment.js b/apps/app/src/server/routes/comment.js index 2f40bd51fa5..321a8796991 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); @@ -367,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')); @@ -393,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.'); } @@ -476,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.'); } 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'; 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); 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,