|
@@ -529,17 +529,10 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
// find page by path
|
|
// find page by path
|
|
|
pageSchema.statics.findPageByPath = function(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);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (path == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.findOne({path});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
pageSchema.statics.findListByPageIds = function(ids, options) {
|
|
pageSchema.statics.findListByPageIds = function(ids, options) {
|
|
@@ -918,6 +911,7 @@ module.exports = function(crowi) {
|
|
|
grant = GRANT_PUBLIC;
|
|
grant = GRANT_PUBLIC;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let savedPage = undefined;
|
|
|
return Page.findOne({path: path})
|
|
return Page.findOne({path: path})
|
|
|
.then(pageData => {
|
|
.then(pageData => {
|
|
|
if (pageData) {
|
|
if (pageData) {
|
|
@@ -939,14 +933,18 @@ module.exports = function(crowi) {
|
|
|
return newPage.save();
|
|
return newPage.save();
|
|
|
})
|
|
})
|
|
|
.then((newPage) => {
|
|
.then((newPage) => {
|
|
|
- const newRevision = Revision.prepareRevision(newPage, body, user, {format: format});
|
|
|
|
|
- return Page.pushRevision(newPage, newRevision, user)
|
|
|
|
|
- .then(() => {
|
|
|
|
|
- return Page.updateGrantUserGroup(newPage, grant, grantUserGroupId, user);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ savedPage = newPage;
|
|
|
})
|
|
})
|
|
|
- .then((data) => {
|
|
|
|
|
- pageEvent.emit('create', data, user);
|
|
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ const newRevision = Revision.prepareRevision(savedPage, body, user, {format: format});
|
|
|
|
|
+ return Page.pushRevision(savedPage, newRevision, user);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ return Page.updateGrantUserGroup(savedPage, grant, grantUserGroupId, user);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ pageEvent.emit('create', savedPage, user);
|
|
|
|
|
+ return savedPage;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -959,14 +957,22 @@ module.exports = function(crowi) {
|
|
|
// update existing page
|
|
// update existing page
|
|
|
var newRevision = Revision.prepareRevision(pageData, body, user);
|
|
var newRevision = Revision.prepareRevision(pageData, body, user);
|
|
|
|
|
|
|
|
|
|
+ let savedPage = undefined;
|
|
|
return Page.pushRevision(pageData, newRevision, user)
|
|
return Page.pushRevision(pageData, newRevision, user)
|
|
|
- .then(function(revision) {
|
|
|
|
|
- return Page.updateGrant(pageData, grant, user, grantUserGroupId);
|
|
|
|
|
|
|
+ .then((revision) => {
|
|
|
|
|
+ // fetch Page
|
|
|
|
|
+ return Page.findPageByPath(revision.path).populate('revision');
|
|
|
})
|
|
})
|
|
|
- .then(function(data) {
|
|
|
|
|
|
|
+ .then((page) => {
|
|
|
|
|
+ savedPage = page;
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ return Page.updateGrant(savedPage, grant, user, grantUserGroupId);
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((data) => {
|
|
|
debug('Page grant update:', data);
|
|
debug('Page grant update:', data);
|
|
|
- pageEvent.emit('update', data, user);
|
|
|
|
|
- return data;
|
|
|
|
|
|
|
+ pageEvent.emit('update', savedPage, user);
|
|
|
|
|
+ return savedPage;
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|