|
|
@@ -1053,9 +1053,13 @@ export default (crowi: Crowi): any => {
|
|
|
throw Error('Crowi is not set up');
|
|
|
}
|
|
|
|
|
|
- const isPageMigrated = pageData.parent != null;
|
|
|
+ const isExRestricted = pageData.grant === GRANT_RESTRICTED;
|
|
|
+ const isChildrenExist = pageData?.descendantCount > 0;
|
|
|
+ const exParent = pageData.parent;
|
|
|
+
|
|
|
+ const isPageOnTree = pageData.parent != null || isTopPage(pageData.path);
|
|
|
const isV5Compatible = crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
|
|
|
- if (!isV5Compatible || !isPageMigrated) {
|
|
|
+ if (!isExRestricted && (!isV5Compatible || !isPageOnTree)) {
|
|
|
// v4 compatible process
|
|
|
return this.updatePageV4(pageData, body, previousBody, user, options);
|
|
|
}
|
|
|
@@ -1069,6 +1073,16 @@ export default (crowi: Crowi): any => {
|
|
|
const newPageData = pageData;
|
|
|
|
|
|
if (grant === GRANT_RESTRICTED) {
|
|
|
+
|
|
|
+ if (isPageOnTree && isChildrenExist) {
|
|
|
+ // Update children's parent with new parent
|
|
|
+ const newParentForChildren = await this.createEmptyPage(pageData.path, pageData.parent, pageData.descendantCount);
|
|
|
+ await this.updateMany(
|
|
|
+ { parent: pageData._id },
|
|
|
+ { parent: newParentForChildren._id },
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
newPageData.parent = null;
|
|
|
}
|
|
|
else {
|
|
|
@@ -1088,6 +1102,11 @@ export default (crowi: Crowi): any => {
|
|
|
if (!isGrantNormalized) {
|
|
|
throw Error('The selected grant or grantedGroup is not assignable to this page.');
|
|
|
}
|
|
|
+
|
|
|
+ if (isExRestricted) {
|
|
|
+ const newParent = await this.getParentAndFillAncestors(newPageData.path, user);
|
|
|
+ newPageData.parent = newParent._id;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
newPageData.applyScope(user, grant, grantUserGroupId);
|
|
|
@@ -1104,6 +1123,10 @@ export default (crowi: Crowi): any => {
|
|
|
|
|
|
pageEvent.emit('update', savedPage, user);
|
|
|
|
|
|
+ if (isPageOnTree && !isChildrenExist) {
|
|
|
+ await this.removeLeafEmptyPagesRecursively(exParent);
|
|
|
+ }
|
|
|
+
|
|
|
return savedPage;
|
|
|
};
|
|
|
|