|
|
@@ -18,34 +18,6 @@ module.exports = function(crowi) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- function populatePageData(pageData, revisionId) {
|
|
|
- var Page = crowi.model('Page');
|
|
|
-
|
|
|
- pageData.latestRevision = pageData.revision;
|
|
|
- if (revisionId) {
|
|
|
- pageData.revision = revisionId;
|
|
|
- }
|
|
|
- pageData.likerCount = pageData.liker.length || 0;
|
|
|
- pageData.seenUsersCount = pageData.seenUsers.length || 0;
|
|
|
-
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
- pageData.populate([
|
|
|
- {path: 'creator', model: 'User', select: USER_PUBLIC_FIELDS},
|
|
|
- {path: 'revision', model: 'Revision'},
|
|
|
- //{path: 'liker', options: { limit: 11 }},
|
|
|
- //{path: 'seenUsers', options: { limit: 11 }},
|
|
|
- ], function (err, pageData) {
|
|
|
- Page.populate(pageData, {path: 'revision.author', model: 'User', select: USER_PUBLIC_FIELDS}, function(err, data) {
|
|
|
- if (err) {
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
-
|
|
|
- return resolve(data);
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
pageSchema = new mongoose.Schema({
|
|
|
path: { type: String, required: true, index: true },
|
|
|
revision: { type: ObjectId, ref: 'Revision' },
|
|
|
@@ -203,6 +175,34 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.populatePageData = function(pageData, revisionId) {
|
|
|
+ var Page = crowi.model('Page');
|
|
|
+
|
|
|
+ pageData.latestRevision = pageData.revision;
|
|
|
+ if (revisionId) {
|
|
|
+ pageData.revision = revisionId;
|
|
|
+ }
|
|
|
+ pageData.likerCount = pageData.liker.length || 0;
|
|
|
+ pageData.seenUsersCount = pageData.seenUsers.length || 0;
|
|
|
+
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ pageData.populate([
|
|
|
+ {path: 'creator', model: 'User', select: USER_PUBLIC_FIELDS},
|
|
|
+ {path: 'revision', model: 'Revision'},
|
|
|
+ //{path: 'liker', options: { limit: 11 }},
|
|
|
+ //{path: 'seenUsers', options: { limit: 11 }},
|
|
|
+ ], function (err, pageData) {
|
|
|
+ Page.populate(pageData, {path: 'revision.author', model: 'User', select: USER_PUBLIC_FIELDS}, function(err, data) {
|
|
|
+ if (err) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resolve(data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.updateCommentCount = function (page, num)
|
|
|
{
|
|
|
var self = this;
|
|
|
@@ -255,6 +255,7 @@ module.exports = function(crowi) {
|
|
|
/^\/_api\/.*/,
|
|
|
/^\/\-\/.*/,
|
|
|
/^\/_r\/.*/,
|
|
|
+ /^\/user\/[^\/]+\/(bookmarks|comments|activities|pages|recent-create|recent-edit)/, // reserved
|
|
|
/.+\/edit$/,
|
|
|
/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments).+/,
|
|
|
];
|
|
|
@@ -297,7 +298,7 @@ module.exports = function(crowi) {
|
|
|
return reject(err);
|
|
|
}
|
|
|
|
|
|
- return populatePageData(pageData, null).then(resolve);
|
|
|
+ return Page.populatePageData(pageData, null).then(resolve);
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
@@ -343,12 +344,31 @@ module.exports = function(crowi) {
|
|
|
return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
|
|
|
}
|
|
|
|
|
|
- populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
|
|
|
+ self.populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.findListByPageIds = function(ids, option) {
|
|
|
+ var Page = this;
|
|
|
+ var limit = option.limit || 50;
|
|
|
+ var offset = option.skip || 0;
|
|
|
+
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ Page
|
|
|
+ .find({ _id: { $in: ids }, grant: GRANT_PUBLIC })
|
|
|
+ //.sort({createdAt: -1}) // TODO optionize
|
|
|
+ .skip(offset)
|
|
|
+ .limit(limit)
|
|
|
+ .populate('revision')
|
|
|
+ .exec(function(err, pages) {
|
|
|
+ if (err) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resolve(pages);
|
|
|
+ });
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.findListByCreator = function(user, option) {
|
|
|
@@ -362,6 +382,7 @@ module.exports = function(crowi) {
|
|
|
.sort({createdAt: -1})
|
|
|
.skip(offset)
|
|
|
.limit(limit)
|
|
|
+ .populate('revision')
|
|
|
.exec(function(err, pages) {
|
|
|
if (err) {
|
|
|
return reject(err);
|