|
|
@@ -961,12 +961,14 @@ module.exports = function(crowi) {
|
|
|
return pageData.save();
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.create = function(path, body, user, options) {
|
|
|
+ pageSchema.statics.create = function(path, body, user, options = {}) {
|
|
|
const Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, format = options.format || 'markdown'
|
|
|
, redirectTo = options.redirectTo || null
|
|
|
- , grantUserGroupId = options.grantUserGroupId || null;
|
|
|
+ , grantUserGroupId = options.grantUserGroupId || null
|
|
|
+ , socketClientId = options.socketClientId || null
|
|
|
+ ;
|
|
|
|
|
|
let grant = options.grant || GRANT_PUBLIC;
|
|
|
|
|
|
@@ -1010,18 +1012,22 @@ module.exports = function(crowi) {
|
|
|
return Page.updateGrantUserGroup(savedPage, grant, grantUserGroupId, user);
|
|
|
})
|
|
|
.then(() => {
|
|
|
- pageEvent.emit('create', savedPage, user);
|
|
|
+ if (socketClientId != null) {
|
|
|
+ pageEvent.emit('create', savedPage, user, socketClientId);
|
|
|
+ }
|
|
|
return savedPage;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.updatePage = async function(pageData, body, user, options) {
|
|
|
+ pageSchema.statics.updatePage = async function(pageData, body, user, options = {}) {
|
|
|
const Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, grant = options.grant || null
|
|
|
, grantUserGroupId = options.grantUserGroupId || null
|
|
|
, isSyncRevisionToHackmd = options.isSyncRevisionToHackmd
|
|
|
+ , socketClientId = options.socketClientId || null
|
|
|
;
|
|
|
+
|
|
|
// update existing page
|
|
|
const newRevision = await Revision.prepareRevision(pageData, body, user);
|
|
|
|
|
|
@@ -1036,14 +1042,17 @@ module.exports = function(crowi) {
|
|
|
savedPage = await Page.syncRevisionToHackmd(savedPage);
|
|
|
}
|
|
|
|
|
|
- pageEvent.emit('update', savedPage, user);
|
|
|
+ if (socketClientId != null) {
|
|
|
+ pageEvent.emit('update', savedPage, user, socketClientId);
|
|
|
+ }
|
|
|
return savedPage;
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.deletePage = function(pageData, user, options) {
|
|
|
+ pageSchema.statics.deletePage = async function(pageData, user, options = {}) {
|
|
|
const Page = this
|
|
|
, newPath = Page.getDeletedPageName(pageData.path)
|
|
|
, isTrashed = checkIfTrashed(pageData.path)
|
|
|
+ , socketClientId = options.socketClientId || null
|
|
|
;
|
|
|
|
|
|
if (Page.isDeletableName(pageData.path)) {
|
|
|
@@ -1051,13 +1060,13 @@ module.exports = function(crowi) {
|
|
|
return Page.completelyDeletePage(pageData, user, options);
|
|
|
}
|
|
|
|
|
|
- return Page.rename(pageData, newPath, user, {createRedirectPage: true})
|
|
|
- .then((updatedPageData) => {
|
|
|
- return Page.updatePageProperty(updatedPageData, {status: STATUS_DELETED, lastUpdateUser: user});
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- return pageData;
|
|
|
- });
|
|
|
+ let updatedPageData = await Page.rename(pageData, newPath, user, {createRedirectPage: true});
|
|
|
+ await Page.updatePageProperty(updatedPageData, {status: STATUS_DELETED, lastUpdateUser: user});
|
|
|
+
|
|
|
+ if (socketClientId != null) {
|
|
|
+ pageEvent.emit('delete', updatedPageData, user, socketClientId);
|
|
|
+ }
|
|
|
+ return updatedPageData;
|
|
|
}
|
|
|
else {
|
|
|
return Promise.reject('Page is not deletable.');
|
|
|
@@ -1069,11 +1078,11 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.deletePageRecursively = function(pageData, user, options) {
|
|
|
- var Page = this
|
|
|
+ const Page = this
|
|
|
, path = pageData.path
|
|
|
- , options = options || {}
|
|
|
- , isTrashed = checkIfTrashed(pageData.path);
|
|
|
+ , isTrashed = checkIfTrashed(pageData.path)
|
|
|
;
|
|
|
+ options = options || {};
|
|
|
|
|
|
if (isTrashed) {
|
|
|
return Page.completelyDeletePageRecursively(pageData, user, options);
|
|
|
@@ -1092,7 +1101,7 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.revertDeletedPage = function(pageData, user, options) {
|
|
|
- var Page = this
|
|
|
+ const Page = this
|
|
|
, newPath = Page.getRevertDeletedPageName(pageData.path)
|
|
|
;
|
|
|
|
|
|
@@ -1106,7 +1115,7 @@ module.exports = function(crowi) {
|
|
|
throw new Error('The new page of to revert is exists and the redirect path of the page is not the deleted page.');
|
|
|
}
|
|
|
|
|
|
- return Page.completelyDeletePage(originPageData);
|
|
|
+ return Page.completelyDeletePage(originPageData, options);
|
|
|
}).then(function(done) {
|
|
|
return Page.updatePageProperty(pageData, {status: STATUS_PUBLISHED, lastUpdateUser: user});
|
|
|
}).then(function(done) {
|
|
|
@@ -1121,11 +1130,11 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.revertDeletedPageRecursively = function(pageData, user, options) {
|
|
|
- var Page = this
|
|
|
+ pageSchema.statics.revertDeletedPageRecursively = function(pageData, user, options = {}) {
|
|
|
+ const Page = this
|
|
|
, path = pageData.path
|
|
|
- , options = options || { includeDeletedPage: true}
|
|
|
;
|
|
|
+ options = Object.assign({ includeDeletedPage: true }, options);
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
Page
|
|
|
@@ -1145,15 +1154,16 @@ module.exports = function(crowi) {
|
|
|
/**
|
|
|
* This is danger.
|
|
|
*/
|
|
|
- pageSchema.statics.completelyDeletePage = function(pageData, user, options) {
|
|
|
+ pageSchema.statics.completelyDeletePage = function(pageData, user, options = {}) {
|
|
|
// Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
- var Bookmark = crowi.model('Bookmark')
|
|
|
+ const Bookmark = crowi.model('Bookmark')
|
|
|
, Attachment = crowi.model('Attachment')
|
|
|
, Comment = crowi.model('Comment')
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, PageGroupRelation = crowi.model('PageGroupRelation')
|
|
|
, Page = this
|
|
|
, pageId = pageData._id
|
|
|
+ , socketClientId = options.socketClientId || null
|
|
|
;
|
|
|
|
|
|
debug('Completely delete', pageData.path);
|
|
|
@@ -1174,18 +1184,20 @@ module.exports = function(crowi) {
|
|
|
}).then(function(done) {
|
|
|
return PageGroupRelation.removeAllByPage(pageData);
|
|
|
}).then(function(done) {
|
|
|
- pageEvent.emit('delete', pageData, user); // update as renamed page
|
|
|
+ if (socketClientId != null) {
|
|
|
+ pageEvent.emit('delete', pageData, user, socketClientId); // update as renamed page
|
|
|
+ }
|
|
|
resolve(pageData);
|
|
|
}).catch(reject);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.completelyDeletePageRecursively = function(pageData, user, options) {
|
|
|
+ pageSchema.statics.completelyDeletePageRecursively = function(pageData, user, options = {}) {
|
|
|
// Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
- var Page = this
|
|
|
+ const Page = this
|
|
|
, path = pageData.path
|
|
|
- , options = options || { includeDeletedPage: true }
|
|
|
;
|
|
|
+ options = Object.assign({ includeDeletedPage: true }, options);
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
Page
|
|
|
@@ -1253,32 +1265,31 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.rename = function(pageData, newPagePath, user, options) {
|
|
|
+ pageSchema.statics.rename = async function(pageData, newPagePath, user, options) {
|
|
|
const Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
, path = pageData.path
|
|
|
, createRedirectPage = options.createRedirectPage || 0
|
|
|
+ , socketClientId = options.socketClientId || null
|
|
|
;
|
|
|
|
|
|
// sanitize path
|
|
|
newPagePath = crowi.xss.process(newPagePath);
|
|
|
|
|
|
- return Page.updatePageProperty(pageData, {updatedAt: Date.now(), path: newPagePath, lastUpdateUser: user}) // pageData の path を変更
|
|
|
- .then((data) => {
|
|
|
+ await Page.updatePageProperty(pageData, {updatedAt: Date.now(), path: newPagePath, lastUpdateUser: user});
|
|
|
// reivisions の path を変更
|
|
|
- return Revision.updateRevisionListByPath(path, {path: newPagePath}, {});
|
|
|
- })
|
|
|
- .then(function(data) {
|
|
|
- pageData.path = newPagePath;
|
|
|
+ await Revision.updateRevisionListByPath(path, {path: newPagePath}, {});
|
|
|
|
|
|
if (createRedirectPage) {
|
|
|
const body = 'redirect ' + newPagePath;
|
|
|
- Page.create(path, body, user, {redirectTo: newPagePath});
|
|
|
+ await Page.create(path, body, user, {redirectTo: newPagePath});
|
|
|
}
|
|
|
- pageEvent.emit('update', pageData, user); // update as renamed page
|
|
|
|
|
|
- return pageData;
|
|
|
- });
|
|
|
+ let updatedPageData = await Page.findOne({path: newPagePath});
|
|
|
+ pageEvent.emit('delete', pageData, user, socketClientId);
|
|
|
+ pageEvent.emit('create', updatedPageData, user, socketClientId);
|
|
|
+
|
|
|
+ return updatedPageData;
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.renameRecursively = function(pageData, newPagePathPrefix, user, options) {
|