|
@@ -610,11 +610,24 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * findListByStartWith
|
|
|
|
|
|
|
+ * find the page that is match with `path` and its descendants
|
|
|
|
|
+ */
|
|
|
|
|
+ pageSchema.statics.findListWithDescendants = function(path, userData, option) {
|
|
|
|
|
+ var Page = this;
|
|
|
|
|
+
|
|
|
|
|
+ // add slash to the last
|
|
|
|
|
+ path = Page.addSlashOfEnd(path);
|
|
|
|
|
+ // escape
|
|
|
|
|
+ path = escapeStringRegexp(path);
|
|
|
|
|
+
|
|
|
|
|
+ return Page.findListByStartWith(path, userData, option);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * find pages that start with `path`
|
|
|
*
|
|
*
|
|
|
* If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
* If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
|
* If `path` doesn't have `/` at the end, returns '{path}*'
|
|
* If `path` doesn't have `/` at the end, returns '{path}*'
|
|
|
- * e.g.
|
|
|
|
|
*/
|
|
*/
|
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
var Page = this;
|
|
@@ -657,12 +670,32 @@ module.exports = function(crowi) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * generate the query to find the page that is match with `path` and its descendants
|
|
|
|
|
+ */
|
|
|
|
|
+ pageSchema.statics.generateQueryToListWithDescendants = function(path, userData, option) {
|
|
|
|
|
+ var Page = this;
|
|
|
|
|
+
|
|
|
|
|
+ // add slash to the last
|
|
|
|
|
+ path = Page.addSlashOfEnd(path);
|
|
|
|
|
+ // escape
|
|
|
|
|
+ path = escapeStringRegexp(path);
|
|
|
|
|
+
|
|
|
|
|
+ return Page.generateQueryToListByStartWith(path, userData, option);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * generate the query to find pages that start with `path`
|
|
|
|
|
+ *
|
|
|
|
|
+ * If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
|
|
|
+ * If `path` doesn't have `/` at the end, returns '{path}*'
|
|
|
|
|
+ */
|
|
|
pageSchema.statics.generateQueryToListByStartWith = function(path, userData, option) {
|
|
pageSchema.statics.generateQueryToListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
var Page = this;
|
|
|
var pathCondition = [];
|
|
var pathCondition = [];
|
|
|
var includeDeletedPage = option.includeDeletedPage || false;
|
|
var includeDeletedPage = option.includeDeletedPage || false;
|
|
|
|
|
|
|
|
- var queryReg = new RegExp('^' + escapeStringRegexp(path));
|
|
|
|
|
|
|
+ var queryReg = new RegExp('^' + path);
|
|
|
pathCondition.push({path: queryReg});
|
|
pathCondition.push({path: queryReg});
|
|
|
if (path.match(/\/$/)) {
|
|
if (path.match(/\/$/)) {
|
|
|
debug('Page list by ending with /, so find also upper level page');
|
|
debug('Page list by ending with /, so find also upper level page');
|
|
@@ -890,7 +923,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
return new Promise(function (resolve, reject) {
|
|
|
Page
|
|
Page
|
|
|
- .generateQueryToListByStartWith(path, user, options)
|
|
|
|
|
|
|
+ .generateQueryToListWithDescendants(path, user, options)
|
|
|
.then(function (pages) {
|
|
.then(function (pages) {
|
|
|
Promise.all(pages.map(function (page) {
|
|
Promise.all(pages.map(function (page) {
|
|
|
return Page.deletePage(page, user, options);
|
|
return Page.deletePage(page, user, options);
|
|
@@ -941,7 +974,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
return new Promise(function (resolve, reject) {
|
|
|
Page
|
|
Page
|
|
|
- .generateQueryToListByStartWith(path, user, options)
|
|
|
|
|
|
|
+ .generateQueryToListWithDescendants(path, user, options)
|
|
|
.then(function (pages) {
|
|
.then(function (pages) {
|
|
|
Promise.all(pages.map(function (page) {
|
|
Promise.all(pages.map(function (page) {
|
|
|
return Page.revertDeletedPage(page, user, options);
|
|
return Page.revertDeletedPage(page, user, options);
|
|
@@ -997,7 +1030,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
return new Promise(function (resolve, reject) {
|
|
|
Page
|
|
Page
|
|
|
- .generateQueryToListByStartWith(path, user, options)
|
|
|
|
|
|
|
+ .generateQueryToListWithDescendants(path, user, options)
|
|
|
.then(function (pages) {
|
|
.then(function (pages) {
|
|
|
Promise.all(pages.map(function (page) {
|
|
Promise.all(pages.map(function (page) {
|
|
|
return Page.completelyDeletePage(page, user, options);
|
|
return Page.completelyDeletePage(page, user, options);
|
|
@@ -1095,7 +1128,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
return new Promise(function(resolve, reject) {
|
|
|
Page
|
|
Page
|
|
|
- .generateQueryToListByStartWith(path, user, options)
|
|
|
|
|
|
|
+ .generateQueryToListWithDescendants(path, user, options)
|
|
|
.then(function(pages) {
|
|
.then(function(pages) {
|
|
|
Promise.all(pages.map(function(page) {
|
|
Promise.all(pages.map(function(page) {
|
|
|
newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
|
|
@@ -1114,6 +1147,17 @@ module.exports = function(crowi) {
|
|
|
return;
|
|
return;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * return path that added slash to the end for specified path
|
|
|
|
|
+ */
|
|
|
|
|
+ pageSchema.statics.addSlashOfEnd = function(path) {
|
|
|
|
|
+ let returnPath = path;
|
|
|
|
|
+ if (!path.match(/\/$/)) {
|
|
|
|
|
+ returnPath += '/';
|
|
|
|
|
+ }
|
|
|
|
|
+ return returnPath;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pageSchema.statics.GRANT_PUBLIC = GRANT_PUBLIC;
|
|
pageSchema.statics.GRANT_PUBLIC = GRANT_PUBLIC;
|
|
|
pageSchema.statics.GRANT_RESTRICTED = GRANT_RESTRICTED;
|
|
pageSchema.statics.GRANT_RESTRICTED = GRANT_RESTRICTED;
|
|
|
pageSchema.statics.GRANT_SPECIFIED = GRANT_SPECIFIED;
|
|
pageSchema.statics.GRANT_SPECIFIED = GRANT_SPECIFIED;
|