|
|
@@ -415,96 +415,96 @@ describe('PageService page operations with non-public pages', () => {
|
|
|
};
|
|
|
|
|
|
test('Should rename/move with descendants with grant normalized pages', async() => {
|
|
|
- const pathD = '/np_rename1_destination';
|
|
|
- const path2 = '/np_rename2';
|
|
|
- const path3 = '/np_rename2/np_rename3';
|
|
|
- const propertiesD = { grant: Page.GRANT_PUBLIC };
|
|
|
- const properties2 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
- const properties3 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC };
|
|
|
- const pageD = await Page.findOne({ path: pathD, ...propertiesD });
|
|
|
- const page2 = await Page.findOne({ path: path2, ...properties2 });
|
|
|
- const page3 = await Page.findOne({ path: path3, ...properties3, parent: page2._id });
|
|
|
- expect(pageD).toBeTruthy();
|
|
|
- expect(page2).toBeTruthy();
|
|
|
- expect(page3).toBeTruthy();
|
|
|
+ const _pathD = '/np_rename1_destination';
|
|
|
+ const _path2 = '/np_rename2';
|
|
|
+ const _path3 = '/np_rename2/np_rename3';
|
|
|
+ const _propertiesD = { grant: Page.GRANT_PUBLIC };
|
|
|
+ const _properties2 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
+ const _properties3 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdC };
|
|
|
+ const _pageD = await Page.findOne({ path: _pathD, ..._propertiesD });
|
|
|
+ const _page2 = await Page.findOne({ path: _path2, ..._properties2 });
|
|
|
+ const _page3 = await Page.findOne({ path: _path3, ..._properties3, parent: _page2._id });
|
|
|
+ expect(_pageD).toBeTruthy();
|
|
|
+ expect(_page2).toBeTruthy();
|
|
|
+ expect(_page3).toBeTruthy();
|
|
|
|
|
|
- const newPathForChild = '/np_rename1_destination/np_rename2';
|
|
|
- const newPathForGrandchild = '/np_rename1_destination/np_rename2/np_rename3';
|
|
|
- await renamePage(page2, newPathForChild, npDummyUser2, {});
|
|
|
+ const newPathForPage2 = '/np_rename1_destination/np_rename2';
|
|
|
+ const newPathForPage3 = '/np_rename1_destination/np_rename2/np_rename3';
|
|
|
+ await renamePage(_page2, newPathForPage2, npDummyUser2, {});
|
|
|
|
|
|
- const _pageD = await Page.findOne({ path: pathD, ...propertiesD });
|
|
|
- const _page2 = await Page.findOne({ path: path2, ...properties2 }); // not exist
|
|
|
- const _page3 = await Page.findOne({ path: path3, ...properties3, parent: page2._id }); // not exist
|
|
|
- const _page2R = await Page.findOne({ path: newPathForChild }); // renamed
|
|
|
- const _page3R = await Page.findOne({ path: newPathForGrandchild }); // renamed
|
|
|
- expect(_pageD).toBeTruthy();
|
|
|
- expect(_page2).toBeNull();
|
|
|
- expect(_page3).toBeNull();
|
|
|
- expect(_page2R).toBeTruthy();
|
|
|
- expect(_page3R).toBeTruthy();
|
|
|
- expect(_page2R.parent).toStrictEqual(pageD._id);
|
|
|
- expect(_page3R.parent).toStrictEqual(_page2R._id);
|
|
|
- expect(_page2R.grantedGroup).toStrictEqual(page2.grantedGroup);
|
|
|
- expect(_page3R.grantedGroup).toStrictEqual(page3.grantedGroup);
|
|
|
+ const pageD = await Page.findOne({ path: _pathD, ..._propertiesD });
|
|
|
+ const page2 = await Page.findOne({ path: _path2, ..._properties2 }); // not exist
|
|
|
+ const page3 = await Page.findOne({ path: _path3, ..._properties3, parent: _page2._id }); // not exist
|
|
|
+ const page2Renamed = await Page.findOne({ path: newPathForPage2 }); // renamed
|
|
|
+ const page3Renamed = await Page.findOne({ path: newPathForPage3 }); // renamed
|
|
|
+ expect(pageD).toBeTruthy();
|
|
|
+ expect(page2).toBeNull();
|
|
|
+ expect(page3).toBeNull();
|
|
|
+ expect(page2Renamed).toBeTruthy();
|
|
|
+ expect(page3Renamed).toBeTruthy();
|
|
|
+ expect(page2Renamed.parent).toStrictEqual(_pageD._id);
|
|
|
+ expect(page3Renamed.parent).toStrictEqual(page2Renamed._id);
|
|
|
+ expect(page2Renamed.grantedGroup).toStrictEqual(_page2.grantedGroup);
|
|
|
+ expect(page3Renamed.grantedGroup).toStrictEqual(_page3.grantedGroup);
|
|
|
expect(xssSpy).toHaveBeenCalled();
|
|
|
});
|
|
|
test('Should throw with NOT grant normalized pages', async() => {
|
|
|
- const pathD = '/np_rename4_destination';
|
|
|
- const path2 = '/np_rename5';
|
|
|
- const path3 = '/np_rename5/np_rename6';
|
|
|
- const propertiesD = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdIsolate };
|
|
|
- const properties2 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
- const properties3 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
- const pageD = await Page.findOne({ path: pathD, ...propertiesD });// isolate
|
|
|
- const page2 = await Page.findOne({ path: path2, ...properties2 });// groupIdB
|
|
|
- const page3 = await Page.findOne({ path: path3, ...properties3, parent: page2 });// groupIdB
|
|
|
- expect(pageD).toBeTruthy();
|
|
|
- expect(page2).toBeTruthy();
|
|
|
- expect(page3).toBeTruthy();
|
|
|
+ const _pathD = '/np_rename4_destination';
|
|
|
+ const _path2 = '/np_rename5';
|
|
|
+ const _path3 = '/np_rename5/np_rename6';
|
|
|
+ const _propertiesD = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdIsolate };
|
|
|
+ const _properties2 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
+ const _properties3 = { grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdB };
|
|
|
+ const _pageD = await Page.findOne({ path: _pathD, ..._propertiesD });// isolate
|
|
|
+ const _page2 = await Page.findOne({ path: _path2, ..._properties2 });// groupIdB
|
|
|
+ const _page3 = await Page.findOne({ path: _path3, ..._properties3, parent: _page2 });// groupIdB
|
|
|
+ expect(_pageD).toBeTruthy();
|
|
|
+ expect(_page2).toBeTruthy();
|
|
|
+ expect(_page3).toBeTruthy();
|
|
|
|
|
|
- const newPath1 = '/np_rename4_destination/np_rename5';
|
|
|
- const newPath2 = '/np_rename4_destination/np_rename5/np_rename6';
|
|
|
+ const newPathForPage2 = '/np_rename4_destination/np_rename5';
|
|
|
+ const newPathForPage3 = '/np_rename4_destination/np_rename5/np_rename6';
|
|
|
let isThrown = false;
|
|
|
try {
|
|
|
- await renamePage(page2, newPath1, dummyUser1, {});
|
|
|
+ await renamePage(_page2, newPathForPage2, dummyUser1, {});
|
|
|
}
|
|
|
catch (err) {
|
|
|
isThrown = true;
|
|
|
}
|
|
|
expect(isThrown).toBe(true);
|
|
|
- const _page2 = await Page.findOne({ path: path2 }); // not renamed thus exist
|
|
|
- const _page3 = await Page.findOne({ path: path3 }); // not renamed thus exist
|
|
|
- const _page2R = await Page.findOne({ path: newPath1 }); // not exist
|
|
|
- const _page3R = await Page.findOne({ path: newPath2 }); // not exist
|
|
|
- expect(_page2).toBeTruthy();
|
|
|
- expect(_page3).toBeTruthy();
|
|
|
- expect(_page2R).toBeNull();
|
|
|
- expect(_page3R).toBeNull();
|
|
|
- });
|
|
|
- test('Should rename/move multiple pages: child page with GRANT_RESTRICTED should NOT be renamed.', async() => {
|
|
|
- const pathD = '/np_rename7_destination';
|
|
|
- const path2 = '/np_rename8';
|
|
|
- const path3 = '/np_rename8/np_rename9';
|
|
|
- const pageD = await Page.findOne({ path: pathD, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdIsolate });
|
|
|
- const page2 = await Page.findOne({ path: path2, grant: Page.GRANT_RESTRICTED });
|
|
|
- const page3 = await Page.findOne({ path: path3, grant: Page.GRANT_RESTRICTED });
|
|
|
- expect(pageD).toBeTruthy();
|
|
|
+ const page2 = await Page.findOne({ path: _path2 }); // not renamed thus exist
|
|
|
+ const page3 = await Page.findOne({ path: _path3 }); // not renamed thus exist
|
|
|
+ const page2Renamed = await Page.findOne({ path: newPathForPage2 }); // not exist
|
|
|
+ const page3Renamed = await Page.findOne({ path: newPathForPage3 }); // not exist
|
|
|
expect(page2).toBeTruthy();
|
|
|
expect(page3).toBeTruthy();
|
|
|
+ expect(page2Renamed).toBeNull();
|
|
|
+ expect(page3Renamed).toBeNull();
|
|
|
+ });
|
|
|
+ test('Should rename/move multiple pages: child page with GRANT_RESTRICTED should NOT be renamed.', async() => {
|
|
|
+ const _pathD = '/np_rename7_destination';
|
|
|
+ const _path2 = '/np_rename8';
|
|
|
+ const _path3 = '/np_rename8/np_rename9';
|
|
|
+ const _pageD = await Page.findOne({ path: _pathD, grant: Page.GRANT_USER_GROUP, grantedGroup: groupIdIsolate });
|
|
|
+ const _page2 = await Page.findOne({ path: _path2, grant: Page.GRANT_RESTRICTED });
|
|
|
+ const _page3 = await Page.findOne({ path: _path3, grant: Page.GRANT_RESTRICTED });
|
|
|
+ expect(_pageD).toBeTruthy();
|
|
|
+ expect(_page2).toBeTruthy();
|
|
|
+ expect(_page3).toBeTruthy();
|
|
|
|
|
|
const newPathForPage2 = '/np_rename7_destination/np_rename8';
|
|
|
const newpathForPage3 = '/np_rename7_destination/np_rename8/np_rename9';
|
|
|
- await renamePage(page2, newPathForPage2, npDummyUser1, { isRecursively: true });
|
|
|
+ await renamePage(_page2, newPathForPage2, npDummyUser1, { isRecursively: true });
|
|
|
|
|
|
- const _page2 = await Page.findOne({ path: path2 }); // not exist
|
|
|
- const _page3 = await Page.findOne({ path: path3 }); // not renamed thus exist
|
|
|
- const _page2R = await Page.findOne({ path: newPathForPage2 }); // exist
|
|
|
- const _page3R = await Page.findOne({ path: newpathForPage3 }); // not exist
|
|
|
- expect(_page2).toBeNull();
|
|
|
- expect(_page3).toBeTruthy();
|
|
|
- expect(_page2R).toBeTruthy();
|
|
|
- expect(_page3R).toBeNull();
|
|
|
- expect(_page2R.parent).toBeNull();
|
|
|
+ const page2 = await Page.findOne({ path: _path2 }); // not exist
|
|
|
+ const page3 = await Page.findOne({ path: _path3 }); // not renamed thus exist
|
|
|
+ const page2Renamed = await Page.findOne({ path: newPathForPage2 }); // exist
|
|
|
+ const page3Renamed = await Page.findOne({ path: newpathForPage3 }); // not exist
|
|
|
+ expect(page2).toBeNull();
|
|
|
+ expect(page3).toBeTruthy();
|
|
|
+ expect(page2Renamed).toBeTruthy();
|
|
|
+ expect(page3Renamed).toBeNull();
|
|
|
+ expect(page2Renamed.parent).toBeNull();
|
|
|
expect(xssSpy).toHaveBeenCalled();
|
|
|
});
|
|
|
});
|