|
|
@@ -850,22 +850,40 @@ describe('Page', () => {
|
|
|
expect(page2.grantedGroup).toBeUndefined(); // no group should be set
|
|
|
});
|
|
|
test('Fail to change to GRANT_USER_GROUP if the group to set is an ancestor of the parent page group', async() => {
|
|
|
- const path1 = '/mup33_C';
|
|
|
- const path2 = '/mup33_C/mup34_owner';
|
|
|
- const _page1 = await Page.findOne({ path: path1, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC }); // groupC
|
|
|
- const _page2 = await Page.findOne({ path: path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser3] });
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: groupIdA }; // change to groupA which is the grandParent
|
|
|
+ // path
|
|
|
+ const _path1 = '/mup33_C';
|
|
|
+ const _path2 = '/mup33_C/mup34_owner';
|
|
|
+ // page
|
|
|
+ const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC }); // groupC
|
|
|
+ const _page2 = await Page.findOne({ path: _path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser3] }); // update target
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- await expect(updatePage(_page2, 'new', 'old', pModelUser3, options))
|
|
|
+ // group
|
|
|
+ const _groupA = await UserGroup.findById(groupIdA);
|
|
|
+ const _groupB = await UserGroup.findById(groupIdB);
|
|
|
+ const _groupC = await UserGroup.findById(groupIdC);
|
|
|
+ expect(_groupA).toBeTruthy();
|
|
|
+ expect(_groupB).toBeTruthy();
|
|
|
+ expect(_groupC).toBeTruthy();
|
|
|
+ // group parent check
|
|
|
+ expect(_groupA.parent).toBeUndefined(); // parent of groupA is undefined
|
|
|
+ expect(_groupB.parent).toStrictEqual(_groupA._id); // parent of groupB is groupA
|
|
|
+ expect(_groupC.parent).toStrictEqual(_groupB._id); // parent of groupC is groupB
|
|
|
+
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: groupIdA };
|
|
|
+ // this should fail because the groupC is a descendant of groupA
|
|
|
+ await expect(updatePage(_page2, 'new', 'old', pModelUser3, options)) // from GRANT_OWNER to GRANT_USER_GROUP(groupIdA)
|
|
|
.rejects.toThrow(new Error('The selected grant or grantedGroup is not assignable to this page.'));
|
|
|
- const page2 = await Page.findOne({ path: path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser3] });
|
|
|
- const pageN = await Page.findOne({ path: path2, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC }); // not exist
|
|
|
+
|
|
|
+ const page1 = await Page.findById(_page1._id);
|
|
|
+ const page2 = await Page.findById(_page2._id);
|
|
|
+ expect(page1).toBeTruthy();
|
|
|
expect(page2).toBeTruthy();
|
|
|
- expect(pageN).toBeNull();
|
|
|
- expect(page2.grant).toBe(Page.GRANT_OWNER);
|
|
|
- expect(page2.grantedUsers).toStrictEqual([pModelUser3._id]);
|
|
|
+
|
|
|
+ expect(page2.grant).toBe(Page.GRANT_OWNER); // should be the same before the update
|
|
|
+ expect(page2.grantedUsers).toStrictEqual([pModelUser3._id]); // should be the same before the update
|
|
|
+ expect(page2.grantedGroup).toBeUndefined(); // no group should be set
|
|
|
});
|
|
|
});
|
|
|
describe('update grant of a page under a page with GRANT_OWNER', () => {
|