Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/import-service
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Aug 13, 2024
2 parents e534ade + a29562b commit e7bbc7d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
11 changes: 6 additions & 5 deletions apps/app/src/server/routes/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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'));
Expand All @@ -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.');
}

Expand Down Expand Up @@ -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.');
}

Expand Down
8 changes: 5 additions & 3 deletions apps/app/src/server/service/activity.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions apps/app/src/server/service/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ class PageService implements IPageService {
await this.renameDescendantsWithStream(page, newPagePath, user, options, false, descendantsSubscribedSets);
const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref<IUser>[];

const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers });
const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers });

this.activityEvent.emit('updated', activity, page, preNotify);
}
Expand Down Expand Up @@ -1702,7 +1702,7 @@ class PageService implements IPageService {

const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref<IUser>[];

const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers });
const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers });

this.activityEvent.emit('updated', activity, page, preNotify);

Expand Down Expand Up @@ -2021,7 +2021,7 @@ class PageService implements IPageService {
await this.deleteCompletelyDescendantsWithStream(page, user, options, false, descendantsSubscribedSets);
const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref<IUser>[];

const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers });
const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers });

this.activityEvent.emit('updated', activity, page, preNotify);

Expand Down Expand Up @@ -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<IUser>[];

const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers });
const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers });

this.activityEvent.emit('updated', activity, page, preNotify);

Expand Down Expand Up @@ -2304,7 +2304,7 @@ class PageService implements IPageService {
await this.revertDeletedDescendantsWithStream(page, user, options, false, descendantsSubscribedSets);
const descendantsSubscribedUsers = Array.from(descendantsSubscribedSets) as Ref<IUser>[];

const preNotify = preNotifyService.generatePreNotify(activity, () => { return descendantsSubscribedUsers });
const preNotify = preNotifyService.generatePreNotify(activity, async() => { return descendantsSubscribedUsers });

this.activityEvent.emit('updated', activity, page, preNotify);

Expand Down
7 changes: 3 additions & 4 deletions apps/app/src/server/service/pre-notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export type PreNotifyProps = {
}

export type PreNotify = (props: PreNotifyProps) => Promise<void>;
export type GeneratePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: (activity?: ActivityDocument) => Ref<IUser>[]) => PreNotify;

export type GetAdditionalTargetUsers = (activity: ActivityDocument) => Ref<IUser>[];
export type GetAdditionalTargetUsers = (activity: ActivityDocument) => Promise<Ref<IUser>[]>;
export type GeneratePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: GetAdditionalTargetUsers) => PreNotify;

interface IPreNotifyService {
generateInitialPreNotifyProps: (PreNotifyProps) => { notificationTargetUsers?: Ref<IUser>[] },
Expand Down Expand Up @@ -48,7 +47,7 @@ class PreNotifyService implements IPreNotifyService {
notificationTargetUsers?.push(...activeNotificationUsers);
}
else {
const AdditionalTargetUsers = getAdditionalTargetUsers(activity);
const AdditionalTargetUsers = await getAdditionalTargetUsers(activity);

notificationTargetUsers?.push(
...activeNotificationUsers,
Expand Down

0 comments on commit e7bbc7d

Please sign in to comment.