Преглед изворни кода

use activityEventEmitter with page duplicate

Shun Miyazawa пре 3 година
родитељ
комит
d7ad6b6e99

+ 8 - 1
packages/app/src/server/routes/apiv3/pages.js

@@ -694,7 +694,7 @@ module.exports = (crowi) => {
    *          500:
    *            description: Internal server error.
    */
-  router.post('/duplicate', accessTokenParser, loginRequiredStrictly, csrf, validator.duplicatePage, apiV3FormValidator, async(req, res) => {
+  router.post('/duplicate', accessTokenParser, loginRequiredStrictly, csrf, addActivity, validator.duplicatePage, apiV3FormValidator, async(req, res) => {
     const { pageId, isRecursively } = req.body;
 
     const newPagePath = pathUtils.normalizePath(req.body.pageNameInput);
@@ -740,6 +740,13 @@ module.exports = (crowi) => {
       logger.error('Failed to create subscription document', err);
     }
 
+    const parameters = {
+      targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
+      target: page,
+      action: SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE,
+    };
+    activityEvent.emit('update', res.locals.activity._id, parameters, page);
+
     return res.apiv3(result);
   });
 

+ 0 - 12
packages/app/src/server/service/page.ts

@@ -155,16 +155,6 @@ class PageService {
     this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
     this.pageEvent.on('addSeenUsers', this.pageEvent.onAddSeenUsers);
 
-    // duplicate
-    this.pageEvent.on('duplicate', async(page, user) => {
-      try {
-        await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE);
-      }
-      catch (err) {
-        logger.error(err);
-      }
-    });
-
     // delete
     this.pageEvent.on('delete', async(page, user) => {
       try {
@@ -967,7 +957,6 @@ class PageService {
         newPagePath, page.revision.body, user, options,
       );
     }
-    this.pageEvent.emit('duplicate', page, user);
 
     // 4. Take over tags
     const originTags = await page.findRelatedTagsById();
@@ -1061,7 +1050,6 @@ class PageService {
     const createdPage = await this.crowi.pageService.create(
       newPagePath, page.revision.body, user, options,
     );
-    this.pageEvent.emit('duplicate', page, user);
 
     if (isRecursively) {
       this.duplicateDescendantsWithStream(page, newPagePath, user);