Răsfoiți Sursa

Merge branch 'feat/descendant-notifications' into feat/create-notification-when-parentPages-are-reverted-afeter-deletion

Shun Murai 3 ani în urmă
părinte
comite
2a1b09bd77

+ 9 - 8
packages/app/src/server/service/page.ts

@@ -169,7 +169,7 @@ class PageService {
 
     // Change the parameter of the function into the pages
     // rename
-    this.pageEvent.on('rename', async(page, descendantPages, user) => {
+    this.pageEvent.on('rename', async(page, user, descendantPages?) => {
       const isRecursively = descendantPages != null;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_RENAME : SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME;
       try {
@@ -191,7 +191,7 @@ class PageService {
     });
 
     // delete
-    this.pageEvent.on('delete', async(page, descendantPages, user) => {
+    this.pageEvent.on('delete', async(page, user, descendantPages?) => {
       const isRecursively = descendantPages != null;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_DELETE : SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE;
       try {
@@ -547,7 +547,7 @@ class PageService {
       update.updatedAt = new Date();
     }
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
-    this.pageEvent.emit('rename', page, null, user);
+    this.pageEvent.emit('rename', page, user);
 
     // create page redirect
     if (options.createRedirectPage) {
@@ -693,7 +693,7 @@ class PageService {
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
     }
 
-    this.pageEvent.emit('rename', page, null, user);
+    this.pageEvent.emit('rename', page, user);
 
     return renamedPage;
   }
@@ -848,7 +848,7 @@ class PageService {
           await renameDescendants(
             batch, user, options, pathRegExp, newPagePathPrefix, shouldUseV4Process,
           );
-          pageEvent.emit('rename', targetPage, batch, user);
+          pageEvent.emit('rename', targetPage, user, batch);
           logger.debug(`Renaming pages progressing: (count=${count})`);
         }
         catch (err) {
@@ -1424,7 +1424,8 @@ class PageService {
       this.deleteRecursivelyMainOperation(page, user, pageOp._id);
     }
     else {
-      this.pageEvent.emit('delete', page, null, user);
+
+      this.pageEvent.emit('delete', page, user);
     }
 
     return deletedPage;
@@ -1612,7 +1613,7 @@ class PageService {
         try {
           count += batch.length;
           await deleteDescendants(batch, user);
-          pageEvent.emit('delete', targetPage, batch, user);
+          pageEvent.emit('delete', targetPage, user, batch);
           logger.debug(`Deleting pages progressing: (count=${count})`);
         }
         catch (err) {
@@ -2264,7 +2265,7 @@ class PageService {
     const activity = await activityService.createByParameters(parameters);
     // Get user to be notified
     let targetUsers = await activity.getNotificationTargetUsers();
-    if (descendantPages !== undefined && descendantPages.length > 0) {
+    if (descendantPages != null && descendantPages.length > 0) {
       const User = this.crowi.model('User');
       const targetDescendantsUsers = await Subscription.getSubscriptions(descendantPages);
       const descendantsUsers = targetDescendantsUsers.filter(item => (item.toString() !== user._id.toString()));

+ 4 - 4
packages/app/test/integration/service/page.test.js

@@ -350,7 +350,7 @@ describe('PageService', () => {
 
         expect(xssSpy).toHaveBeenCalled();
 
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename1, null, testUser2);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename1, testUser2);
 
         expect(resultPage.path).toBe('/renamed1');
         expect(resultPage.updatedAt).toEqual(parentForRename1.updatedAt);
@@ -363,7 +363,7 @@ describe('PageService', () => {
 
         expect(xssSpy).toHaveBeenCalled();
 
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename2, null, testUser2);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename2, testUser2);
 
         expect(resultPage.path).toBe('/renamed2');
         expect(resultPage.updatedAt).toEqual(dateToUse);
@@ -375,7 +375,7 @@ describe('PageService', () => {
         const resultPage = await crowi.pageService.renamePage(parentForRename3, '/renamed3', testUser2, { createRedirectPage: true });
 
         expect(xssSpy).toHaveBeenCalled();
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename3, null, testUser2);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename3, testUser2);
 
         expect(resultPage.path).toBe('/renamed3');
         expect(resultPage.updatedAt).toEqual(parentForRename3.updatedAt);
@@ -388,7 +388,7 @@ describe('PageService', () => {
 
         expect(xssSpy).toHaveBeenCalled();
         expect(renameDescendantsWithStreamSpy).toHaveBeenCalled();
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, null, testUser2);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, testUser2);
 
         expect(resultPage.path).toBe('/renamed4');
         expect(resultPage.updatedAt).toEqual(parentForRename4.updatedAt);