Futa Arai пре 2 година
родитељ
комит
be868b0f5c
2 измењених фајлова са 6 додато и 12 уклоњено
  1. 2 4
      apps/app/src/server/models/page.ts
  2. 4 8
      apps/app/src/server/service/page-grant.ts

+ 2 - 4
apps/app/src/server/models/page.ts

@@ -3,6 +3,7 @@
 import nodePath from 'path';
 
 import {
+  GrantedGroup,
   GroupType, HasObjectId, pagePathUtils, pathUtils,
 } from '@growi/core';
 import { collectAncestorPaths } from '@growi/core/dist/utils/page-path-utils/collect-ancestor-paths';
@@ -974,10 +975,7 @@ schema.statics.findNonEmptyClosestAncestor = async function(path: string): Promi
 
 export type PageCreateOptions = {
   format?: string
-  grantUserGroupIds?: {
-    type: string,
-    item: ObjectIdLike
-  }[],
+  grantUserGroupIds?: GrantedGroup[],
   grant?: number
   overwriteScopesOfDescendants?: boolean
 }

+ 4 - 8
apps/app/src/server/service/page-grant.ts

@@ -13,6 +13,7 @@ import { PageDocument, PageModel } from '~/server/models/page';
 import UserGroup from '~/server/models/user-group';
 import { isIncludesObjectId, excludeTestIdsFromTargetIds, hasIntersection } from '~/server/util/compare-objectId';
 
+import { ObjectIdLike } from '../interfaces/mongoose-utils';
 import { divideByType } from '../util/granted-group';
 
 const { addTrailingSlash } = pathUtils;
@@ -20,15 +21,10 @@ const { isTopPage } = pagePathUtils;
 
 const LIMIT_FOR_MULTIPLE_PAGE_OP = 20;
 
-type ObjectIdLike = mongoose.Types.ObjectId | string;
-
 type ComparableTarget = {
   grant: number,
   grantedUserIds?: ObjectIdLike[],
-  grantedGroupIds?: {
-    type: GroupType,
-    item: ObjectIdLike,
-  }[],
+  grantedGroupIds?: GrantedGroup[],
   applicableUserIds?: ObjectIdLike[],
   applicableGroupIds?: ObjectIdLike[],
 };
@@ -246,7 +242,7 @@ class PageGrantService {
         const applicableExternalUserGroups = (await Promise.all(targetExternalUserGroups.map((group) => {
           return ExternalUserGroup.findGroupsWithDescendantsById(group._id);
         }))).flat();
-        applicableGroupIds = [...applicableUserGroups, ...applicableExternalUserGroups].map(g => g._id) || null;
+        applicableGroupIds = [...applicableUserGroups, ...applicableExternalUserGroups].map(g => g._id);
       }
 
       return {
@@ -547,7 +543,7 @@ class PageGrantService {
       const isUserExistInExternalUserGroup = (await Promise.all(targetExternalUserGroups.map((group) => {
         return ExternalUserGroupRelation.countByGroupIdAndUser(group, user);
       }))).some(count => count > 0);
-      const isUserExistInGroup = await isUserExistInUserGroup || isUserExistInExternalUserGroup;
+      const isUserExistInGroup = isUserExistInUserGroup || isUserExistInExternalUserGroup;
 
       if (isUserExistInGroup) {
         data[PageGrant.GRANT_OWNER] = null;