|
|
@@ -282,6 +282,7 @@ module.exports = function(crowi) {
|
|
|
/^\/\-\/.*/,
|
|
|
/^\/_r\/.*/,
|
|
|
/^\/user\/[^\/]+\/(bookmarks|comments|activities|pages|recent-create|recent-edit)/, // reserved
|
|
|
+ /^http:\/\/.+$/, // avoid miss in renaming
|
|
|
/.+\/edit$/,
|
|
|
/.+\.md$/,
|
|
|
/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments).+/,
|
|
|
@@ -376,6 +377,21 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ // find page by path
|
|
|
+ pageSchema.statics.findPageByPath = function(path) {
|
|
|
+ var Page = this;
|
|
|
+
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ Page.findOne({path: path}, function(err, pageData) {
|
|
|
+ if (err || pageData === null) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resolve(pageData);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.findListByPageIds = function(ids, option) {
|
|
|
var Page = this;
|
|
|
var User = crowi.model('User');
|
|
|
@@ -486,10 +502,17 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.updatePage = function(page, updateData, cb) {
|
|
|
- // TODO foreach して save
|
|
|
- this.update({_id: page._id}, {$set: updateData}, function(err, data) {
|
|
|
- return cb(err, data);
|
|
|
+ pageSchema.statics.updatePage = function(page, updateData) {
|
|
|
+ var Page = this;
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ // TODO foreach して save
|
|
|
+ Page.update({_id: page._id}, {$set: updateData}, function(err, data) {
|
|
|
+ if (err) {
|
|
|
+ return reject(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resolve(data);
|
|
|
+ });
|
|
|
});
|
|
|
};
|
|
|
|
|
|
@@ -606,33 +629,29 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.rename = function(pageData, newPageName, user, options, cb) {
|
|
|
+ pageSchema.statics.rename = function(pageData, newPagePath, user, options) {
|
|
|
var Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, path = pageData.path
|
|
|
, createRedirectPage = options.createRedirectPage || 0
|
|
|
, moveUnderTrees = options.moveUnderTrees || 0;
|
|
|
|
|
|
- // pageData の path を変更
|
|
|
- this.updatePage(pageData, {updatedAt: Date.now(), path: newPageName}, function(err, data) {
|
|
|
- if (err) {
|
|
|
- return cb(err, null);
|
|
|
- }
|
|
|
-
|
|
|
- // reivisions の path を変更
|
|
|
- Revision.updateRevisionListByPath(path, {path: newPageName}, {}, function(err, data) {
|
|
|
- if (err) {
|
|
|
- return cb(err, null);
|
|
|
- }
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ // pageData の path を変更
|
|
|
+ Page.updatePage(pageData, {updatedAt: Date.now(), path: newPagePath})
|
|
|
+ .then(function(data) {
|
|
|
+ debug('Before ', pageData);
|
|
|
+ // reivisions の path を変更
|
|
|
+ return Revision.updateRevisionListByPath(path, {path: newPagePath}, {})
|
|
|
+ }).then(function(data) {
|
|
|
+ debug('After ', pageData);
|
|
|
+ pageData.path = newPagePath;
|
|
|
|
|
|
- pageData.path = newPageName;
|
|
|
if (createRedirectPage) {
|
|
|
- Page.create(path, 'redirect ' + newPageName, user, {redirectTo: newPageName}, function(err, data) {
|
|
|
- // @TODO error handling
|
|
|
- return cb(err, pageData);
|
|
|
- });
|
|
|
+ var body = 'redirect ' + newPagePath;
|
|
|
+ return Page.create(path, body, user, {redirectTo: newPagePath}).then(resolve).catch(reject);
|
|
|
} else {
|
|
|
- return cb(err, pageData);
|
|
|
+ return resolve(data);
|
|
|
}
|
|
|
});
|
|
|
});
|