Răsfoiți Sursa

Added a comment

Taichi Masuyama 3 ani în urmă
părinte
comite
d90b7949e0
1 a modificat fișierele cu 12 adăugiri și 6 ștergeri
  1. 12 6
      packages/app/src/server/service/page.ts

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

@@ -2297,7 +2297,7 @@ class PageService {
         grantedUsers: notEmptyParent.grantedUsers,
         grantedUsers: notEmptyParent.grantedUsers,
       };
       };
 
 
-      systematicallyCreatedPage = await this.createBySystem(
+      systematicallyCreatedPage = await this.forceCreateBySystem(
         path,
         path,
         '',
         '',
         options,
         options,
@@ -3371,7 +3371,7 @@ class PageService {
     return savedPage;
     return savedPage;
   }
   }
 
 
-  private async canProcessCreateBySystem(
+  private async canProcessForceCreateBySystem(
       path: string,
       path: string,
       grantData: {
       grantData: {
         grant: number,
         grant: number,
@@ -3382,7 +3382,13 @@ class PageService {
     return this.canProcessCreate(path, grantData, false);
     return this.canProcessCreate(path, grantData, false);
   }
   }
 
 
-  async createBySystem(path: string, body: string, options: PageCreateOptions & { grantedUsers?: ObjectIdLike[] }): Promise<PageDocument> {
+  /**
+   * This method receives the same arguments as the PageService.create method does except for the added type '{ grantedUsers?: ObjectIdLike[] }'.
+   * This additional value is used to determine the grantedUser of the page to be created by system.
+   * !!This method does not run isGrantNormalized method to validate grant. Run it before use this method if necessary.!!
+   * !!This is because it is not expected to use this method when the grant validation is required.!!
+   */
+  async forceCreateBySystem(path: string, body: string, options: PageCreateOptions & { grantedUsers?: ObjectIdLike[] }): Promise<PageDocument> {
     const Page = mongoose.model('Page') as unknown as PageModel;
     const Page = mongoose.model('Page') as unknown as PageModel;
 
 
     const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
     const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
@@ -3412,9 +3418,9 @@ class PageService {
     if (isGrantOwner && grantedUsers?.length !== 1) {
     if (isGrantOwner && grantedUsers?.length !== 1) {
       throw Error('grantedUser must exist when grant is GRANT_OWNER');
       throw Error('grantedUser must exist when grant is GRANT_OWNER');
     }
     }
-    const canProcessCreateBySystem = await this.canProcessCreateBySystem(path, grantData);
-    if (!canProcessCreateBySystem) {
-      throw Error('Cannnot process createBySystem');
+    const canProcessForceCreateBySystem = await this.canProcessForceCreateBySystem(path, grantData);
+    if (!canProcessForceCreateBySystem) {
+      throw Error('Cannnot process forceCreateBySystem');
     }
     }
 
 
     // Prepare a page document
     // Prepare a page document