@@ -8,6 +8,11 @@ module.exports = function(crowi) {
8
8
, GRANT_OWNER = 4
9
9
, PAGE_GRANT_ERROR = 1
10
10
11
+ , STATUS_WIP = 'wip'
12
+ , STATUS_PUBLISHED = 'published'
13
+ , STATUS_DELEDED = 'deleted'
14
+ , STATUS_DEPRECATED = 'deprecated'
15
+
11
16
, pageEvent = crowi . event ( 'page' )
12
17
13
18
, pageSchema ;
@@ -24,6 +29,7 @@ module.exports = function(crowi) {
24
29
path : { type : String , required : true , index : true } ,
25
30
revision : { type : ObjectId , ref : 'Revision' } ,
26
31
redirectTo : { type : String , index : true } ,
32
+ status : { type : String , default : STATUS_PUBLISHED , index : true } ,
27
33
grant : { type : Number , default : GRANT_PUBLIC , index : true } ,
28
34
grantedUsers : [ { type : ObjectId , ref : 'User' } ] ,
29
35
creator : { type : ObjectId , ref : 'User' , index : true } ,
@@ -54,6 +60,23 @@ module.exports = function(crowi) {
54
60
pageEvent . on ( 'create' , pageEvent . onCreate ) ;
55
61
pageEvent . on ( 'update' , pageEvent . onUpdate ) ;
56
62
63
+ pageSchema . methods . isWIP = function ( ) {
64
+ return this . status === STATUS_WIP ;
65
+ } ;
66
+
67
+ pageSchema . methods . isPublished = function ( ) {
68
+ // null: this is for B.C.
69
+ return this . status === null || this . status === STATUS_PUBLISHED ;
70
+ } ;
71
+
72
+ pageSchema . methods . isDeleted = function ( ) {
73
+ return this . status === STATUS_DELEDED ;
74
+ } ;
75
+
76
+ pageSchema . methods . isDeprecated = function ( ) {
77
+ return this . status === STATUS_DEPRECATED ;
78
+ } ;
79
+
57
80
pageSchema . methods . isPublic = function ( ) {
58
81
if ( ! this . grant || this . grant == GRANT_PUBLIC ) {
59
82
return true ;
@@ -322,6 +345,32 @@ module.exports = function(crowi) {
322
345
return '/user/' + user . username ;
323
346
} ;
324
347
348
+ pageSchema . statics . getDeletedPageName = function ( path ) {
349
+ if ( path . match ( '\/' ) ) {
350
+ path = path . substr ( 1 ) ;
351
+ }
352
+ return '/trash/' + path ;
353
+ } ;
354
+
355
+ pageSchema . statics . getRevertDeletedPageName = function ( path ) {
356
+ return path . replace ( '\/trash' , '' ) ;
357
+ } ;
358
+
359
+ pageSchema . statics . isDeletableName = function ( path ) {
360
+ var notDeletable = [
361
+ / ^ \/ u s e r \/ [ ^ \/ ] + $ / , // user page
362
+ ] ;
363
+
364
+ for ( var i = 0 ; i < notDeletable . length ; i ++ ) {
365
+ var pattern = notDeletable [ i ] ;
366
+ if ( path . match ( pattern ) ) {
367
+ return false ;
368
+ }
369
+ }
370
+
371
+ return true ;
372
+ } ;
373
+
325
374
pageSchema . statics . isCreatableName = function ( name ) {
326
375
var forbiddenPages = [
327
376
/ \^ | \$ | \* | \+ | \# / ,
@@ -694,6 +743,7 @@ module.exports = function(crowi) {
694
743
newPage . updatedAt = Date . now ( ) ;
695
744
newPage . redirectTo = redirectTo ;
696
745
newPage . grant = grant ;
746
+ newPage . status = STATUS_PUBLISHED ;
697
747
newPage . grantedUsers = [ ] ;
698
748
newPage . grantedUsers . push ( user ) ;
699
749
@@ -743,6 +793,27 @@ module.exports = function(crowi) {
743
793
} ) ;
744
794
} ;
745
795
796
+ pageSchema . statics . deletePage = function ( pageData , user , options ) {
797
+ var Page = this
798
+ , newPath = Page . getDeletedPageName ( pageData . path )
799
+ ;
800
+ if ( Page . isDeletableName ( pageData . path ) ) {
801
+ return new Promise ( function ( resolve , reject ) {
802
+ Page . updatePageProperty ( pageData , { status : STATUS_DELEDED } )
803
+ . then ( function ( pageData ) {
804
+ return Page . rename ( pageData , newPath , user , { createRedirectPage : true } )
805
+ } ) . then ( function ( pageData ) {
806
+ resolve ( pageData ) ;
807
+ } ) . catch ( reject ) ;
808
+ } ) ;
809
+ } else {
810
+ return Promise . reject ( 'Page is not deletable.' ) ;
811
+ }
812
+ } ;
813
+
814
+ pageSchema . statics . revertDeletedPage = function ( pageData , user , options ) {
815
+ } ;
816
+
746
817
pageSchema . statics . rename = function ( pageData , newPagePath , user , options ) {
747
818
var Page = this
748
819
, Revision = crowi . model ( 'Revision' )
@@ -772,10 +843,6 @@ module.exports = function(crowi) {
772
843
} ) ;
773
844
} ;
774
845
775
- pageSchema . statics . deletePage = function ( pageData , options ) {
776
- var Page = this ,
777
- } ;
778
-
779
846
pageSchema . statics . getHistories = function ( ) {
780
847
// TODO
781
848
return ;
0 commit comments