|
|
@@ -444,6 +444,9 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * とりあえず、公開ページであり、redirectTo が無いものだけを出すためだけのAPI
|
|
|
+ */
|
|
|
pageSchema.statics.findListByCreator = function(user, option) {
|
|
|
var Page = this;
|
|
|
var User = crowi.model('User');
|
|
|
@@ -452,30 +455,31 @@ module.exports = function(crowi) {
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
Page
|
|
|
- .find({ creator: user._id, grant: GRANT_PUBLIC })
|
|
|
+ .find({ creator: user._id, grant: GRANT_PUBLIC, redirectTo: null })
|
|
|
.sort({createdAt: -1})
|
|
|
.skip(offset)
|
|
|
.limit(limit)
|
|
|
.populate('revision')
|
|
|
- .exec(function(err, pages) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS}, function(err, data) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- return resolve(data);
|
|
|
- });
|
|
|
+ .exec()
|
|
|
+ .then(function(pages) {
|
|
|
+ return Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS});
|
|
|
+ }).then(function(pages) {
|
|
|
+ return resolve(data);
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * findListByStartWith
|
|
|
+ *
|
|
|
+ * If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
|
+ * If `path` doesn't have `/` at the end, returns '{path}*'
|
|
|
+ * e.g.
|
|
|
+ */
|
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
|
var User = crowi.model('User');
|
|
|
+ var pathCondition = [];
|
|
|
|
|
|
if (!option) {
|
|
|
option = {sort: 'updatedAt', desc: -1, offset: 0, limit: 50};
|
|
|
@@ -491,10 +495,15 @@ module.exports = function(crowi) {
|
|
|
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) {
|
|
|
// FIXME: might be heavy
|
|
|
var q = Page.find({
|
|
|
- path: queryReg,
|
|
|
redirectTo: null,
|
|
|
$or: [
|
|
|
{grant: null},
|
|
|
@@ -502,26 +511,21 @@ module.exports = function(crowi) {
|
|
|
{grant: GRANT_RESTRICTED, grantedUsers: userData._id},
|
|
|
{grant: GRANT_SPECIFIED, grantedUsers: userData._id},
|
|
|
{grant: GRANT_OWNER, grantedUsers: userData._id},
|
|
|
- ],
|
|
|
+ ],})
|
|
|
+ .populate('revision')
|
|
|
+ .and({
|
|
|
+ $or: pathCondition
|
|
|
+ })
|
|
|
+ .sort(sortOpt)
|
|
|
+ .skip(opt.offset)
|
|
|
+ .limit(opt.limit);
|
|
|
+
|
|
|
+ q.exec()
|
|
|
+ .then(function(pages) {
|
|
|
+ Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS})
|
|
|
+ .then(resolve)
|
|
|
+ .catch(reject);
|
|
|
})
|
|
|
- .populate('revision')
|
|
|
- .sort(sortOpt)
|
|
|
- .skip(opt.offset)
|
|
|
- .limit(opt.limit);
|
|
|
-
|
|
|
- q.exec(function(err, pages) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS}, function(err, data) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- return resolve(data);
|
|
|
- });
|
|
|
- });
|
|
|
});
|
|
|
};
|
|
|
|