|
|
@@ -149,7 +149,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdAB,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -158,7 +158,7 @@ describe('Page', () => {
|
|
|
creator: upodUserB,
|
|
|
lastUpdateUser: upodUserB,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdB,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdB, type: 'UserGroup' }],
|
|
|
parent: upodPageIdgAB1,
|
|
|
},
|
|
|
{
|
|
|
@@ -167,7 +167,7 @@ describe('Page', () => {
|
|
|
creator: upodUserB,
|
|
|
lastUpdateUser: upodUserB,
|
|
|
grantedUsers: [upodUserB._id],
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: upodPageIdgAB1,
|
|
|
},
|
|
|
// case 2
|
|
|
@@ -178,7 +178,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -187,7 +187,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdA,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdA, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic2,
|
|
|
},
|
|
|
{
|
|
|
@@ -196,7 +196,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdAIsolated,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdAIsolated, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic2,
|
|
|
},
|
|
|
{
|
|
|
@@ -205,7 +205,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: [upodUserA._id],
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: upodPageIdPublic2,
|
|
|
},
|
|
|
// case 3
|
|
|
@@ -216,7 +216,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -225,7 +225,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdAB,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic3,
|
|
|
},
|
|
|
{
|
|
|
@@ -234,7 +234,7 @@ describe('Page', () => {
|
|
|
creator: upodUserB,
|
|
|
lastUpdateUser: upodUserB,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdB,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdB, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic3,
|
|
|
},
|
|
|
{
|
|
|
@@ -243,7 +243,7 @@ describe('Page', () => {
|
|
|
creator: upodUserB,
|
|
|
lastUpdateUser: upodUserB,
|
|
|
grantedUsers: [upodUserB._id],
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: upodPageIdPublic3,
|
|
|
},
|
|
|
// case 4
|
|
|
@@ -254,7 +254,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -263,7 +263,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdA,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdA, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic4,
|
|
|
},
|
|
|
{
|
|
|
@@ -272,7 +272,7 @@ describe('Page', () => {
|
|
|
creator: upodUserC,
|
|
|
lastUpdateUser: upodUserC,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdC,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdC, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic4,
|
|
|
},
|
|
|
// case 5
|
|
|
@@ -283,7 +283,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -292,7 +292,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: upodUserGroupIdA,
|
|
|
+ grantedGroups: [{ item: upodUserGroupIdA, type: 'UserGroup' }],
|
|
|
parent: upodPageIdPublic5,
|
|
|
},
|
|
|
{
|
|
|
@@ -301,7 +301,7 @@ describe('Page', () => {
|
|
|
creator: upodUserC,
|
|
|
lastUpdateUser: upodUserC,
|
|
|
grantedUsers: [upodUserC._id],
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: upodPageIdPublic5,
|
|
|
},
|
|
|
// case 6
|
|
|
@@ -312,7 +312,7 @@ describe('Page', () => {
|
|
|
creator: upodUserA,
|
|
|
lastUpdateUser: upodUserA,
|
|
|
grantedUsers: null,
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: rootPage._id,
|
|
|
},
|
|
|
{
|
|
|
@@ -321,7 +321,7 @@ describe('Page', () => {
|
|
|
creator: upodUserC,
|
|
|
lastUpdateUser: upodUserC,
|
|
|
grantedUsers: [upodUserC._id],
|
|
|
- grantedGroup: null,
|
|
|
+ grantedGroups: null,
|
|
|
parent: upodPageIdPublic6,
|
|
|
},
|
|
|
]);
|
|
|
@@ -610,7 +610,7 @@ describe('Page', () => {
|
|
|
{
|
|
|
path: '/mup20',
|
|
|
grant: Page.GRANT_USER_GROUP,
|
|
|
- grantedGroup: userGroupIdPModelA,
|
|
|
+ grantedGroups: [{ item: userGroupIdPModelA, type: 'UserGroup' }],
|
|
|
creator: pModelUserId1,
|
|
|
lastUpdateUser: pModelUserId1,
|
|
|
isEmpty: false,
|
|
|
@@ -638,7 +638,7 @@ describe('Page', () => {
|
|
|
{
|
|
|
path: '/mup22/mup23',
|
|
|
grant: Page.GRANT_USER_GROUP,
|
|
|
- grantedGroup: userGroupIdPModelA,
|
|
|
+ grantedGroups: [{ item: userGroupIdPModelA, type: 'UserGroup' }],
|
|
|
creator: pModelUserId1,
|
|
|
lastUpdateUser: pModelUserId1,
|
|
|
isEmpty: false,
|
|
|
@@ -696,7 +696,7 @@ describe('Page', () => {
|
|
|
_id: pageIdUpd16,
|
|
|
path: '/mup29_A',
|
|
|
grant: Page.GRANT_USER_GROUP,
|
|
|
- grantedGroup: userGroupIdPModelA,
|
|
|
+ grantedGroups: [{ item: userGroupIdPModelA, type: 'UserGroup' }],
|
|
|
creator: pModelUserId1,
|
|
|
lastUpdateUser: pModelUserId1,
|
|
|
isEmpty: false,
|
|
|
@@ -717,7 +717,7 @@ describe('Page', () => {
|
|
|
_id: pageIdUpd17,
|
|
|
path: '/mup31_A',
|
|
|
grant: Page.GRANT_USER_GROUP,
|
|
|
- grantedGroup: userGroupIdPModelA,
|
|
|
+ grantedGroups: [{ item: userGroupIdPModelA, type: 'UserGroup' }],
|
|
|
creator: pModelUserId1,
|
|
|
lastUpdateUser: pModelUserId1,
|
|
|
isEmpty: false,
|
|
|
@@ -738,7 +738,7 @@ describe('Page', () => {
|
|
|
_id: pageIdUpd18,
|
|
|
path: '/mup33_C',
|
|
|
grant: Page.GRANT_USER_GROUP,
|
|
|
- grantedGroup: userGroupIdPModelC,
|
|
|
+ grantedGroups: [{ item: userGroupIdPModelC, type: 'UserGroup' }],
|
|
|
creator: pModelUserId3,
|
|
|
lastUpdateUser: pModelUserId3,
|
|
|
isEmpty: false,
|
|
|
@@ -804,7 +804,7 @@ describe('Page', () => {
|
|
|
expect(page1).toBeTruthy();
|
|
|
expect(page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_RESTRICTED, grantUserGroupId: null };
|
|
|
+ const options = { grant: Page.GRANT_RESTRICTED, grantUserGroupIds: null };
|
|
|
await updatePage(page2, 'newRevisionBody', 'oldRevisionBody', dummyUser1, options);
|
|
|
|
|
|
const _pageT = await Page.findOne({ path: pathT });
|
|
|
@@ -954,7 +954,7 @@ describe('Page', () => {
|
|
|
});
|
|
|
test('successfully change to GRANT_OWNER from GRANT_USER_GROUP', async() => {
|
|
|
const path = '/mup20';
|
|
|
- const _page = await Page.findOne({ path, grant: Page.GRANT_USER_GROUP, grantedGroup: userGroupIdPModelA });
|
|
|
+ const _page = await Page.findOne({ path, grant: Page.GRANT_USER_GROUP, grantedGroups: { $elemMatch: { item: userGroupIdPModelA } } });
|
|
|
expect(_page).toBeTruthy();
|
|
|
|
|
|
await updatePage(_page, 'newRevisionBody', 'oldRevisionBody', pModelUser1, { grant: Page.GRANT_OWNER });
|
|
|
@@ -962,7 +962,7 @@ describe('Page', () => {
|
|
|
const page = await Page.findOne({ path });
|
|
|
expect(page.grant).toBe(Page.GRANT_OWNER);
|
|
|
expect(page.grantedUsers).toStrictEqual([pModelUser1._id]);
|
|
|
- expect(page.grantedGroup).toBeNull();
|
|
|
+ expect(page.grantedGroups.length).toBe(0);
|
|
|
});
|
|
|
test('successfully change to GRANT_OWNER from GRANT_RESTRICTED', async() => {
|
|
|
const path = '/mup21';
|
|
|
@@ -979,7 +979,7 @@ describe('Page', () => {
|
|
|
const path1 = '/mup22';
|
|
|
const path2 = '/mup22/mup23';
|
|
|
const _page1 = await Page.findOne({ path: path1, grant: Page.GRANT_PUBLIC });
|
|
|
- const _page2 = await Page.findOne({ path: path2, grant: Page.GRANT_USER_GROUP, grantedGroup: userGroupIdPModelA });
|
|
|
+ const _page2 = await Page.findOne({ path: path2, grant: Page.GRANT_USER_GROUP, grantedGroups: { $elemMatch: { item: userGroupIdPModelA } } });
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
@@ -1004,7 +1004,7 @@ describe('Page', () => {
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelA };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelA, type: 'UserGroup' }] };
|
|
|
const updatedPage = await updatePage(_page2, 'new', 'old', pModelUser1, options); // from GRANT_PUBLIC to GRANT_USER_GROUP(userGroupIdPModelA)
|
|
|
|
|
|
const page1 = await Page.findById(_page1._id);
|
|
|
@@ -1016,7 +1016,7 @@ describe('Page', () => {
|
|
|
|
|
|
// check page2 grant and group
|
|
|
expect(page2.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- expect(page2.grantedGroup._id).toStrictEqual(userGroupIdPModelA);
|
|
|
+ expect(page2.grantedGroups.map(g => g.item)).toStrictEqual([userGroupIdPModelA]);
|
|
|
});
|
|
|
|
|
|
test('successfully change to GRANT_USER_GROUP from GRANT_RESTRICTED if parent page is GRANT_PUBLIC', async() => {
|
|
|
@@ -1026,7 +1026,7 @@ describe('Page', () => {
|
|
|
const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_RESTRICTED });
|
|
|
expect(_page1).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelA };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelA, type: 'UserGroup' }] };
|
|
|
const updatedPage = await updatePage(_page1, 'new', 'old', pModelUser1, options); // from GRANT_RESTRICTED to GRANT_USER_GROUP(userGroupIdPModelA)
|
|
|
|
|
|
const page1 = await Page.findById(_page1._id);
|
|
|
@@ -1036,7 +1036,7 @@ describe('Page', () => {
|
|
|
|
|
|
// updated page
|
|
|
expect(page1.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- expect(page1.grantedGroup._id).toStrictEqual(userGroupIdPModelA);
|
|
|
+ expect(page1.grantedGroups.map(g => g.item)).toStrictEqual([userGroupIdPModelA]);
|
|
|
|
|
|
// parent's grant check
|
|
|
const parent = await Page.findById(page1.parent);
|
|
|
@@ -1056,7 +1056,7 @@ describe('Page', () => {
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelA };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelA, type: 'UserGroup' }] };
|
|
|
const updatedPage = await updatePage(_page2, 'new', 'old', pModelUser1, options); // from GRANT_OWNER to GRANT_USER_GROUP(userGroupIdPModelA)
|
|
|
|
|
|
const page1 = await Page.findById(_page1._id);
|
|
|
@@ -1068,7 +1068,7 @@ describe('Page', () => {
|
|
|
|
|
|
// grant check
|
|
|
expect(page2.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- expect(page2.grantedGroup._id).toStrictEqual(userGroupIdPModelA);
|
|
|
+ expect(page2.grantedGroups.map(g => g.item)).toStrictEqual([userGroupIdPModelA]);
|
|
|
expect(page2.grantedUsers.length).toBe(0);
|
|
|
});
|
|
|
});
|
|
|
@@ -1078,14 +1078,14 @@ describe('Page', () => {
|
|
|
const _path1 = '/mup29_A';
|
|
|
const _path2 = '/mup29_A/mup30_owner';
|
|
|
// page
|
|
|
- const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroup: userGroupIdPModelA }); // out of update scope
|
|
|
+ const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroups: { $elemMatch: { item: userGroupIdPModelA } } }); // out of update scope
|
|
|
const _page2 = await Page.findOne({ // update target
|
|
|
path: _path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser1], parent: _page1._id,
|
|
|
});
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelB };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelB, type: 'UserGroup' }] };
|
|
|
|
|
|
// First round
|
|
|
// Group relation(parent -> child): userGroupIdPModelA -> userGroupIdPModelB -> userGroupIdPModelC
|
|
|
@@ -1099,24 +1099,28 @@ describe('Page', () => {
|
|
|
expect(updatedPage._id).toStrictEqual(page2._id);
|
|
|
|
|
|
expect(page2.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- expect(page2.grantedGroup._id).toStrictEqual(userGroupIdPModelB);
|
|
|
+ expect(page2.grantedGroups.map(g => g.item)).toStrictEqual([userGroupIdPModelB]);
|
|
|
expect(page2.grantedUsers.length).toBe(0);
|
|
|
|
|
|
// Second round
|
|
|
// Update group to groupC which is a grandchild from pageA's point of view
|
|
|
- const secondRoundOptions = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelC }; // from GRANT_USER_GROUP(userGroupIdPModelB) to GRANT_USER_GROUP(userGroupIdPModelC)
|
|
|
+ const secondRoundOptions = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelC, type: 'UserGroup' }] }; // from GRANT_USER_GROUP(userGroupIdPModelB) to GRANT_USER_GROUP(userGroupIdPModelC)
|
|
|
+ // undo grantedGroups populate to prevent Page.hydrate error
|
|
|
+ _page2.grantedGroups.forEach((group) => {
|
|
|
+ group.item = group.item._id;
|
|
|
+ });
|
|
|
const secondRoundUpdatedPage = await updatePage(_page2, 'new', 'new', pModelUser3, secondRoundOptions);
|
|
|
|
|
|
expect(secondRoundUpdatedPage).toBeTruthy();
|
|
|
expect(secondRoundUpdatedPage.grant).toBe(Page.GRANT_USER_GROUP);
|
|
|
- expect(secondRoundUpdatedPage.grantedGroup._id).toStrictEqual(userGroupIdPModelC);
|
|
|
+ expect(secondRoundUpdatedPage.grantedGroups.map(g => g.item._id)).toStrictEqual([userGroupIdPModelC]);
|
|
|
});
|
|
|
test('Fail to change to GRANT_USER_GROUP if the group to set is NOT the child or descendant of the parent page group', async() => {
|
|
|
// path
|
|
|
const _path1 = '/mup31_A';
|
|
|
const _path2 = '/mup31_A/mup32_owner';
|
|
|
// page
|
|
|
- const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroup: userGroupIdPModelA });
|
|
|
+ const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroups: { $elemMatch: { item: userGroupIdPModelA } } });
|
|
|
const _page2 = await Page.findOne({ // update target
|
|
|
path: _path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser1._id], parent: _page1._id,
|
|
|
});
|
|
|
@@ -1129,7 +1133,7 @@ describe('Page', () => {
|
|
|
// group parent check
|
|
|
expect(_groupIsolated.parent).toBeUndefined(); // should have no parent
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelIsolate };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelIsolate, type: 'UserGroup' }] };
|
|
|
await expect(updatePage(_page2, 'new', 'old', pModelUser1, options)) // from GRANT_OWNER to GRANT_USER_GROUP(userGroupIdPModelIsolate)
|
|
|
.rejects.toThrow(new Error('The selected grant or grantedGroup is not assignable to this page.'));
|
|
|
|
|
|
@@ -1140,21 +1144,21 @@ describe('Page', () => {
|
|
|
|
|
|
expect(page2.grant).toBe(Page.GRANT_OWNER); // should be the same before the update
|
|
|
expect(page2.grantedUsers).toStrictEqual([pModelUser1._id]); // should be the same before the update
|
|
|
- expect(page2.grantedGroup).toBeUndefined(); // no group should be set
|
|
|
+ expect(page2.grantedGroups.length).toBe(0); // 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() => {
|
|
|
// 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: userGroupIdPModelC }); // groupC
|
|
|
+ const _page1 = await Page.findOne({ path: _path1, grant: Page.GRANT_USER_GROUP, grantedGroups: { $elemMatch: { item: userGroupIdPModelC } } }); // groupC
|
|
|
const _page2 = await Page.findOne({ // update target
|
|
|
path: _path2, grant: Page.GRANT_OWNER, grantedUsers: [pModelUser3], parent: _page1._id,
|
|
|
});
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelA };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelA, type: 'UserGroup' }] };
|
|
|
|
|
|
// Group relation(parent -> child): userGroupIdPModelA -> userGroupIdPModelB -> userGroupIdPModelC
|
|
|
// this should fail because the groupC is a descendant of groupA
|
|
|
@@ -1168,7 +1172,7 @@ describe('Page', () => {
|
|
|
|
|
|
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
|
|
|
+ expect(page2.grantedGroups.length).toBe(0); // no group should be set
|
|
|
});
|
|
|
});
|
|
|
describe('update grant of a page under a page with GRANT_OWNER', () => {
|
|
|
@@ -1184,7 +1188,7 @@ describe('Page', () => {
|
|
|
expect(_page1).toBeTruthy();
|
|
|
expect(_page2).toBeTruthy();
|
|
|
|
|
|
- const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupId: userGroupIdPModelA };
|
|
|
+ const options = { grant: Page.GRANT_USER_GROUP, grantUserGroupIds: [{ item: userGroupIdPModelA, type: 'UserGroup' }] };
|
|
|
await expect(updatePage(_page2, 'new', 'old', pModelUser1, options)) // from GRANT_OWNER to GRANT_USER_GROUP(userGroupIdPModelA)
|
|
|
.rejects.toThrow(new Error('The selected grant or grantedGroup is not assignable to this page.'));
|
|
|
|
|
|
@@ -1194,7 +1198,7 @@ describe('Page', () => {
|
|
|
expect(page2).toBeTruthy();
|
|
|
expect(page2.grant).toBe(Page.GRANT_OWNER); // should be the same before the update
|
|
|
expect(page2.grantedUsers).toStrictEqual([pModelUser1._id]); // should be the same before the update
|
|
|
- expect(page2.grantedGroup).toBeUndefined(); // no group should be set
|
|
|
+ expect(page2.grantedGroups.length).toBe(0); // no group should be set
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -1233,7 +1237,7 @@ describe('Page', () => {
|
|
|
expect(updatedPage.grant).toBe(newGrant);
|
|
|
// Not changed
|
|
|
expect(upodPagegBUpdated.grant).toBe(PageGrant.GRANT_USER_GROUP);
|
|
|
- expect(upodPagegBUpdated.grantedGroup).toStrictEqual(upodPagegB.grantedGroup);
|
|
|
+ expect(upodPagegBUpdated.grantedGroups).toStrictEqual(upodPagegB.grantedGroups);
|
|
|
expect(upodPageonlyBUpdated.grant).toBe(PageGrant.GRANT_OWNER);
|
|
|
expect(upodPageonlyBUpdated.grantedUsers).toStrictEqual(upodPageonlyB.grantedUsers);
|
|
|
});
|
|
|
@@ -1297,7 +1301,7 @@ describe('Page', () => {
|
|
|
// Update
|
|
|
const options = {
|
|
|
grant: PageGrant.GRANT_USER_GROUP,
|
|
|
- grantUserGroupId: upodUserGroupIdAB,
|
|
|
+ grantUserGroupIds: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
overwriteScopesOfDescendants: true,
|
|
|
};
|
|
|
const updatedPage = await updatePage(upodPagePublic, 'newRevisionBody', 'oldRevisionBody', upodUserA, options);
|
|
|
@@ -1310,12 +1314,12 @@ describe('Page', () => {
|
|
|
const newGrant = PageGrant.GRANT_USER_GROUP;
|
|
|
const newGrantedGroup = upodUserGroupIdAB;
|
|
|
expect(updatedPage.grant).toBe(newGrant);
|
|
|
- expect(updatedPage.grantedGroup._id).toStrictEqual(newGrantedGroup);
|
|
|
+ expect(updatedPage.grantedGroups.map(g => g.item._id)).toStrictEqual([newGrantedGroup]);
|
|
|
expect(upodPagegABUpdated.grant).toBe(newGrant);
|
|
|
- expect(upodPagegABUpdated.grantedGroup._id).toStrictEqual(newGrantedGroup);
|
|
|
+ expect(upodPagegABUpdated.grantedGroups.map(g => g.item)).toStrictEqual([newGrantedGroup]);
|
|
|
// Not changed
|
|
|
expect(upodPagegBUpdated.grant).toBe(PageGrant.GRANT_USER_GROUP);
|
|
|
- expect(upodPagegBUpdated.grantedGroup._id).toStrictEqual(upodPagegB.grantedGroup);
|
|
|
+ expect(upodPagegBUpdated.grantedGroups).toStrictEqual(upodPagegB.grantedGroups);
|
|
|
expect(upodPageonlyBUpdated.grant).toBe(PageGrant.GRANT_OWNER);
|
|
|
expect(upodPageonlyBUpdated.grantedUsers).toStrictEqual(upodPageonlyB.grantedUsers);
|
|
|
});
|
|
|
@@ -1337,7 +1341,7 @@ describe('Page', () => {
|
|
|
// Update
|
|
|
const options = {
|
|
|
grant: PageGrant.GRANT_USER_GROUP,
|
|
|
- grantUserGroupId: upodUserGroupIdAB,
|
|
|
+ grantUserGroupIds: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
overwriteScopesOfDescendants: true,
|
|
|
};
|
|
|
const updatedPagePromise = updatePage(upodPagePublic, 'newRevisionBody', 'oldRevisionBody', upodUserA, options);
|
|
|
@@ -1362,7 +1366,7 @@ describe('Page', () => {
|
|
|
// Update
|
|
|
const options = {
|
|
|
grant: PageGrant.GRANT_USER_GROUP,
|
|
|
- grantUserGroupId: upodUserGroupIdAB,
|
|
|
+ grantUserGroupIds: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
overwriteScopesOfDescendants: true,
|
|
|
};
|
|
|
const updatedPagePromise = updatePage(upodPagePublic, 'newRevisionBody', 'oldRevisionBody', upodUserA, options);
|
|
|
@@ -1382,7 +1386,7 @@ describe('Page', () => {
|
|
|
// Update
|
|
|
const options = {
|
|
|
grant: PageGrant.GRANT_USER_GROUP,
|
|
|
- grantUserGroupId: upodUserGroupIdAB,
|
|
|
+ grantUserGroupIds: [{ item: upodUserGroupIdAB, type: 'UserGroup' }],
|
|
|
overwriteScopesOfDescendants: true,
|
|
|
};
|
|
|
const updatedPagePromise = updatePage(upodPagePublic, 'newRevisionBody', 'oldRevisionBody', upodUserA, options);
|