|
|
@@ -8,6 +8,11 @@ module.exports = function(crowi) {
|
|
|
, GRANT_OWNER = 4
|
|
|
, PAGE_GRANT_ERROR = 1
|
|
|
|
|
|
+ , STATUS_WIP = 'wip'
|
|
|
+ , STATUS_PUBLISHED = 'published'
|
|
|
+ , STATUS_DELEDED = 'deleted'
|
|
|
+ , STATUS_DEPRECATED = 'deprecated'
|
|
|
+
|
|
|
, pageEvent = crowi.event('page')
|
|
|
|
|
|
, pageSchema;
|
|
|
@@ -24,6 +29,7 @@ module.exports = function(crowi) {
|
|
|
path: { type: String, required: true, index: true },
|
|
|
revision: { type: ObjectId, ref: 'Revision' },
|
|
|
redirectTo: { type: String, index: true },
|
|
|
+ status: { type: String, default: STATUS_PUBLISHED, index: true },
|
|
|
grant: { type: Number, default: GRANT_PUBLIC, index: true },
|
|
|
grantedUsers: [{ type: ObjectId, ref: 'User' }],
|
|
|
creator: { type: ObjectId, ref: 'User', index: true },
|
|
|
@@ -54,6 +60,23 @@ module.exports = function(crowi) {
|
|
|
pageEvent.on('create', pageEvent.onCreate);
|
|
|
pageEvent.on('update', pageEvent.onUpdate);
|
|
|
|
|
|
+ pageSchema.methods.isWIP = function() {
|
|
|
+ return this.status === STATUS_WIP;
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.methods.isPublished = function() {
|
|
|
+ // null: this is for B.C.
|
|
|
+ return this.status === null || this.status === STATUS_PUBLISHED;
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.methods.isDeleted = function() {
|
|
|
+ return this.status === STATUS_DELEDED;
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.methods.isDeprecated = function() {
|
|
|
+ return this.status === STATUS_DEPRECATED;
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.methods.isPublic = function() {
|
|
|
if (!this.grant || this.grant == GRANT_PUBLIC) {
|
|
|
return true;
|
|
|
@@ -322,6 +345,32 @@ module.exports = function(crowi) {
|
|
|
return '/user/' + user.username;
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.getDeletedPageName = function(path) {
|
|
|
+ if (path.match('\/')) {
|
|
|
+ path = path.substr(1);
|
|
|
+ }
|
|
|
+ return '/trash/' + path;
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.statics.getRevertDeletedPageName = function(path) {
|
|
|
+ return path.replace('\/trash', '');
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.statics.isDeletableName = function(path) {
|
|
|
+ var notDeletable = [
|
|
|
+ /^\/user\/[^\/]+$/, // user page
|
|
|
+ ];
|
|
|
+
|
|
|
+ for (var i = 0; i < notDeletable.length; i++) {
|
|
|
+ var pattern = notDeletable[i];
|
|
|
+ if (path.match(pattern)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.isCreatableName = function(name) {
|
|
|
var forbiddenPages = [
|
|
|
/\^|\$|\*|\+|\#/,
|
|
|
@@ -694,6 +743,7 @@ module.exports = function(crowi) {
|
|
|
newPage.updatedAt = Date.now();
|
|
|
newPage.redirectTo = redirectTo;
|
|
|
newPage.grant = grant;
|
|
|
+ newPage.status = STATUS_PUBLISHED;
|
|
|
newPage.grantedUsers = [];
|
|
|
newPage.grantedUsers.push(user);
|
|
|
|
|
|
@@ -743,6 +793,27 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ pageSchema.statics.deletePage = function(pageData, user, options) {
|
|
|
+ var Page = this
|
|
|
+ , newPath = Page.getDeletedPageName(pageData.path)
|
|
|
+ ;
|
|
|
+ if (Page.isDeletableName(pageData.path)) {
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ Page.updatePageProperty(pageData, {status: STATUS_DELEDED})
|
|
|
+ .then(function(pageData) {
|
|
|
+ return Page.rename(pageData, newPath, user, {createRedirectPage: true})
|
|
|
+ }).then(function(pageData) {
|
|
|
+ resolve(pageData);
|
|
|
+ }).catch(reject);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return Promise.reject('Page is not deletable.');
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ pageSchema.statics.revertDeletedPage = function(pageData, user, options) {
|
|
|
+ };
|
|
|
+
|
|
|
pageSchema.statics.rename = function(pageData, newPagePath, user, options) {
|
|
|
var Page = this
|
|
|
, Revision = crowi.model('Revision')
|
|
|
@@ -772,10 +843,6 @@ module.exports = function(crowi) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.deletePage = function(pageData, options) {
|
|
|
- var Page = this,
|
|
|
- };
|
|
|
-
|
|
|
pageSchema.statics.getHistories = function() {
|
|
|
// TODO
|
|
|
return;
|