|
@@ -593,8 +593,6 @@ module.exports = function(crowi) {
|
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
var Page = this;
|
|
|
var User = crowi.model('User');
|
|
var User = crowi.model('User');
|
|
|
- var pathCondition = [];
|
|
|
|
|
- var includeDeletedPage = option.includeDeletedPage || false
|
|
|
|
|
|
|
|
|
|
if (!option) {
|
|
if (!option) {
|
|
|
option = {sort: 'updatedAt', desc: -1, offset: 0, limit: 50};
|
|
option = {sort: 'updatedAt', desc: -1, offset: 0, limit: 50};
|
|
@@ -607,52 +605,60 @@ module.exports = function(crowi) {
|
|
|
};
|
|
};
|
|
|
var sortOpt = {};
|
|
var sortOpt = {};
|
|
|
sortOpt[opt.sort] = opt.desc;
|
|
sortOpt[opt.sort] = opt.desc;
|
|
|
- var queryReg = new RegExp('^' + path);
|
|
|
|
|
- var sliceOption = option.revisionSlice || {$slice: 1};
|
|
|
|
|
-
|
|
|
|
|
- pathCondition.push({path: queryReg});
|
|
|
|
|
- if (path.match(/\/$/)) {
|
|
|
|
|
- debug('Page list by ending with /, so find also upper level page');
|
|
|
|
|
- pathCondition.push({path: path.substr(0, path.length -1)});
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
return new Promise(function(resolve, reject) {
|
|
|
- // FIXME: might be heavy
|
|
|
|
|
- var q = Page.find({
|
|
|
|
|
- redirectTo: null,
|
|
|
|
|
- $or: [
|
|
|
|
|
- {grant: null},
|
|
|
|
|
- {grant: GRANT_PUBLIC},
|
|
|
|
|
- {grant: GRANT_RESTRICTED, grantedUsers: userData._id},
|
|
|
|
|
- {grant: GRANT_SPECIFIED, grantedUsers: userData._id},
|
|
|
|
|
- {grant: GRANT_OWNER, grantedUsers: userData._id},
|
|
|
|
|
- ],})
|
|
|
|
|
|
|
+ var q = Page.generateQueryToListByStartWith(path, userData, option)
|
|
|
.populate('revision')
|
|
.populate('revision')
|
|
|
- .and({
|
|
|
|
|
- $or: pathCondition
|
|
|
|
|
- })
|
|
|
|
|
.sort(sortOpt)
|
|
.sort(sortOpt)
|
|
|
.skip(opt.offset)
|
|
.skip(opt.offset)
|
|
|
.limit(opt.limit);
|
|
.limit(opt.limit);
|
|
|
|
|
|
|
|
- if (!includeDeletedPage) {
|
|
|
|
|
- q.and({
|
|
|
|
|
- $or: [
|
|
|
|
|
- {status: null},
|
|
|
|
|
- {status: STATUS_PUBLISHED},
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
q.exec()
|
|
q.exec()
|
|
|
- .then(function(pages) {
|
|
|
|
|
- Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS})
|
|
|
|
|
- .then(resolve)
|
|
|
|
|
- .catch(reject);
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ .then(function(pages) {
|
|
|
|
|
+ Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS})
|
|
|
|
|
+ .then(resolve)
|
|
|
|
|
+ .catch(reject);
|
|
|
|
|
+ })
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ pageSchema.statics.generateQueryToListByStartWith = function(path, userData, option) {
|
|
|
|
|
+ var Page = this;
|
|
|
|
|
+ var pathCondition = [];
|
|
|
|
|
+ var includeDeletedPage = option.includeDeletedPage || false;
|
|
|
|
|
+
|
|
|
|
|
+ var queryReg = new RegExp('^' + path);
|
|
|
|
|
+ pathCondition.push({path: queryReg});
|
|
|
|
|
+ if (path.match(/\/$/)) {
|
|
|
|
|
+ debug('Page list by ending with /, so find also upper level page');
|
|
|
|
|
+ pathCondition.push({path: path.substr(0, path.length -1)});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var q = Page.find({
|
|
|
|
|
+ redirectTo: null,
|
|
|
|
|
+ $or: [
|
|
|
|
|
+ {grant: null},
|
|
|
|
|
+ {grant: GRANT_PUBLIC},
|
|
|
|
|
+ {grant: GRANT_RESTRICTED, grantedUsers: userData._id},
|
|
|
|
|
+ {grant: GRANT_SPECIFIED, grantedUsers: userData._id},
|
|
|
|
|
+ {grant: GRANT_OWNER, grantedUsers: userData._id},
|
|
|
|
|
+ ],})
|
|
|
|
|
+ .and({
|
|
|
|
|
+ $or: pathCondition
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (!includeDeletedPage) {
|
|
|
|
|
+ q.and({
|
|
|
|
|
+ $or: [
|
|
|
|
|
+ {status: null},
|
|
|
|
|
+ {status: STATUS_PUBLISHED},
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return q;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pageSchema.statics.updatePageProperty = function(page, updateData) {
|
|
pageSchema.statics.updatePageProperty = function(page, updateData) {
|
|
|
var Page = this;
|
|
var Page = this;
|
|
|
return new Promise(function(resolve, reject) {
|
|
return new Promise(function(resolve, reject) {
|