Futa Arai 2 лет назад
Родитель
Сommit
95b5930a9b

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

@@ -536,13 +536,13 @@ class PageGrantService {
       }))).flat();
       const applicableGroups = [...applicableUserGroups, ...applicableExternalUserGroups];
 
-      const isUserExistInUserGroup = () => targetUserGroups.some(async(group) => {
-        return await UserGroupRelation.countByGroupIdAndUser(group, user) > 0;
-      });
-      const isUserExistInExternalUserGroup = () => targetExternalUserGroups.some(async(group) => {
-        return await ExternalUserGroupRelation.countByGroupIdAndUser(group, user) > 0;
-      });
-      const isUserExistInGroup = isUserExistInUserGroup() || isUserExistInExternalUserGroup();
+      const isUserExistInUserGroup = (await Promise.all(targetUserGroups.map((group) => {
+        return UserGroupRelation.countByGroupIdAndUser(group, user);
+      }))).some(count => count > 0);
+      const isUserExistInExternalUserGroup = (await Promise.all(targetExternalUserGroups.map((group) => {
+        return ExternalUserGroupRelation.countByGroupIdAndUser(group, user);
+      }))).some(count => count > 0);
+      const isUserExistInGroup = await isUserExistInUserGroup || isUserExistInExternalUserGroup;
 
       if (isUserExistInGroup) {
         data[PageGrant.GRANT_OWNER] = null;

+ 18 - 18
apps/app/test/integration/service/page-grant.test.js

@@ -647,26 +647,26 @@ describe('PageGrantService', () => {
       );
 
       // // OnlyMe
-      // const onlyInsideTheGroupOnlyMePage = await Page.findOne({ path: pageOnlyInsideTheGroupOnlyMePath });
-      // const onlyInsideTheGroupOnlyMeRes = await pageGrantService.calcApplicableGrantData(onlyInsideTheGroupOnlyMePage, user1);
-      // expect(onlyInsideTheGroupOnlyMeRes).toStrictEqual(
-      //   {
-      //     [PageGrant.GRANT_RESTRICTED]: null,
-      //     [PageGrant.GRANT_OWNER]: null,
-      //     [PageGrant.GRANT_USER_GROUP]: { applicableGroups },
-      //   },
-      // );
+      const onlyInsideTheGroupOnlyMePage = await Page.findOne({ path: pageOnlyInsideTheGroupOnlyMePath });
+      const onlyInsideTheGroupOnlyMeRes = await pageGrantService.calcApplicableGrantData(onlyInsideTheGroupOnlyMePage, user1);
+      expect(onlyInsideTheGroupOnlyMeRes).toStrictEqual(
+        {
+          [PageGrant.GRANT_RESTRICTED]: null,
+          [PageGrant.GRANT_OWNER]: null,
+          [PageGrant.GRANT_USER_GROUP]: { applicableGroups },
+        },
+      );
 
       // // AnyoneWithTheLink
-      // const onlyInsideTheGroupAnyoneWithTheLinkPage = await Page.findOne({ path: pageOnlyInsideTheGroupAnyoneWithTheLinkPath });
-      // const onlyInsideTheGroupAnyoneWithTheLinkRes = await pageGrantService.calcApplicableGrantData(onlyInsideTheGroupAnyoneWithTheLinkPage, user1);
-      // expect(onlyInsideTheGroupAnyoneWithTheLinkRes).toStrictEqual(
-      //   {
-      //     [PageGrant.GRANT_RESTRICTED]: null,
-      //     [PageGrant.GRANT_OWNER]: null,
-      //     [PageGrant.GRANT_USER_GROUP]: { applicableGroups },
-      //   },
-      // );
+      const onlyInsideTheGroupAnyoneWithTheLinkPage = await Page.findOne({ path: pageOnlyInsideTheGroupAnyoneWithTheLinkPath });
+      const onlyInsideTheGroupAnyoneWithTheLinkRes = await pageGrantService.calcApplicableGrantData(onlyInsideTheGroupAnyoneWithTheLinkPage, user1);
+      expect(onlyInsideTheGroupAnyoneWithTheLinkRes).toStrictEqual(
+        {
+          [PageGrant.GRANT_RESTRICTED]: null,
+          [PageGrant.GRANT_OWNER]: null,
+          [PageGrant.GRANT_USER_GROUP]: { applicableGroups },
+        },
+      );
     });
   });
 });