Просмотр исходного кода

Calc childrenOrItselfGroupIds correctly

Taichi Masuyama 3 лет назад
Родитель
Сommit
f38e5e0acd

+ 1 - 0
packages/app/src/server/models/user-group.ts

@@ -109,6 +109,7 @@ schema.statics.findGroupsWithAncestorsRecursively = async function(group, ancest
 };
 
 /**
+ * TODO: use $graphLookup
  * Find all descendant groups starting from the UserGroups in the initial groups in "groups".
  * Set "descendants" as "[]" if the initial groups are unnecessary as result.
  * @param groups UserGroupDocument[] including at least one UserGroup

+ 3 - 1
packages/app/src/server/service/page-grant.ts

@@ -560,12 +560,14 @@ class PageGrantService {
       }
       const UserGroupRelation = mongoose.model('UserGroupRelation') as any; // TODO: Typescriptize model
       const userIds = await UserGroupRelation.findAllUserIdsForUserGroup(grantUserGroupId);
+      const childrenOrItselfGroupIds = await UserGroup.findGroupsWithDescendantsById(grantUserGroupId).map(d => d._id);
+
       updateGrantInfo = {
         grant: PageGrant.GRANT_USER_GROUP,
         grantedUserGroupInfo: {
           groupId: grantUserGroupId,
           userIds: new Set<ObjectIdLike>(userIds),
-          childrenOrItselfGroupIds: new Set<ObjectIdLike>(),
+          childrenOrItselfGroupIds: new Set<ObjectIdLike>(childrenOrItselfGroupIds),
         },
       };
     }