|
@@ -2,6 +2,7 @@
|
2
|
2
|
import marshmallow
|
3
|
3
|
from marshmallow import post_load
|
4
|
4
|
from marshmallow.validate import OneOf
|
|
5
|
+from marshmallow.validate import Range
|
5
|
6
|
|
6
|
7
|
from tracim.lib.utils.utils import DATETIME_FORMAT
|
7
|
8
|
from tracim.models.auth import Profile
|
|
@@ -83,15 +84,30 @@ class UserSchema(UserDigestSchema):
|
83
|
84
|
|
84
|
85
|
|
85
|
86
|
class UserIdPathSchema(marshmallow.Schema):
|
86
|
|
- user_id = marshmallow.fields.Int(example=3, required=True)
|
|
87
|
+ user_id = marshmallow.fields.Int(
|
|
88
|
+ example=3,
|
|
89
|
+ required=True,
|
|
90
|
+ description='id of a valid user',
|
|
91
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
92
|
+ )
|
87
|
93
|
|
88
|
94
|
|
89
|
95
|
class WorkspaceIdPathSchema(marshmallow.Schema):
|
90
|
|
- workspace_id = marshmallow.fields.Int(example=4, required=True)
|
|
96
|
+ workspace_id = marshmallow.fields.Int(
|
|
97
|
+ example=4,
|
|
98
|
+ required=True,
|
|
99
|
+ description='id of a valid workspace',
|
|
100
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
101
|
+ )
|
91
|
102
|
|
92
|
103
|
|
93
|
104
|
class ContentIdPathSchema(marshmallow.Schema):
|
94
|
|
- content_id = marshmallow.fields.Int(example=6, required=True)
|
|
105
|
+ content_id = marshmallow.fields.Int(
|
|
106
|
+ example=6,
|
|
107
|
+ required=True,
|
|
108
|
+ description='id of a valid content',
|
|
109
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
110
|
+ )
|
95
|
111
|
|
96
|
112
|
|
97
|
113
|
class WorkspaceAndUserIdPathSchema(
|
|
@@ -115,8 +131,9 @@ class WorkspaceAndContentIdPathSchema(
|
115
|
131
|
class CommentsPathSchema(WorkspaceAndContentIdPathSchema):
|
116
|
132
|
comment_id = marshmallow.fields.Int(
|
117
|
133
|
example=6,
|
118
|
|
- description='id of a comment related to content content_id',
|
119
|
|
- required=True
|
|
134
|
+ description='id of a valid comment related to content content_id',
|
|
135
|
+ required=True,
|
|
136
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
120
|
137
|
)
|
121
|
138
|
|
122
|
139
|
@post_load
|
|
@@ -132,19 +149,22 @@ class FilterContentQuerySchema(marshmallow.Schema):
|
132
|
149
|
' If not set, then return all contents.'
|
133
|
150
|
' If set to 0, then return root contents.'
|
134
|
151
|
' If set to another value, return all contents'
|
135
|
|
- ' directly included in the folder parent_id'
|
|
152
|
+ ' directly included in the folder parent_id',
|
|
153
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
136
|
154
|
)
|
137
|
155
|
show_archived = marshmallow.fields.Int(
|
138
|
156
|
example=0,
|
139
|
157
|
default=0,
|
140
|
158
|
description='if set to 1, then show archived contents.'
|
141
|
|
- ' Default is 0 - hide archived content'
|
|
159
|
+ ' Default is 0 - hide archived content',
|
|
160
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
142
|
161
|
)
|
143
|
162
|
show_deleted = marshmallow.fields.Int(
|
144
|
163
|
example=0,
|
145
|
164
|
default=0,
|
146
|
165
|
description='if set to 1, then show deleted contents.'
|
147
|
|
- ' Default is 0 - hide deleted content'
|
|
166
|
+ ' Default is 0 - hide deleted content',
|
|
167
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
148
|
168
|
)
|
149
|
169
|
show_active = marshmallow.fields.Int(
|
150
|
170
|
example=1,
|
|
@@ -154,7 +174,8 @@ class FilterContentQuerySchema(marshmallow.Schema):
|
154
|
174
|
' Note: active content are content '
|
155
|
175
|
'that is neither archived nor deleted. '
|
156
|
176
|
'The reason for this parameter to exist is for example '
|
157
|
|
- 'to allow to show only archived documents'
|
|
177
|
+ 'to allow to show only archived documents',
|
|
178
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
158
|
179
|
)
|
159
|
180
|
|
160
|
181
|
@post_load
|
|
@@ -263,7 +284,10 @@ class WorkspaceMenuEntrySchema(marshmallow.Schema):
|
263
|
284
|
|
264
|
285
|
|
265
|
286
|
class WorkspaceDigestSchema(marshmallow.Schema):
|
266
|
|
- workspace_id = marshmallow.fields.Int(example=4)
|
|
287
|
+ workspace_id = marshmallow.fields.Int(
|
|
288
|
+ example=4,
|
|
289
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
290
|
+ )
|
267
|
291
|
slug = marshmallow.fields.String(example='intranet')
|
268
|
292
|
label = marshmallow.fields.String(example='Intranet')
|
269
|
293
|
sidebar_entries = marshmallow.fields.Nested(
|
|
@@ -287,8 +311,14 @@ class WorkspaceMemberSchema(marshmallow.Schema):
|
287
|
311
|
example='contributor',
|
288
|
312
|
validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
|
289
|
313
|
)
|
290
|
|
- user_id = marshmallow.fields.Int(example=3)
|
291
|
|
- workspace_id = marshmallow.fields.Int(example=4)
|
|
314
|
+ user_id = marshmallow.fields.Int(
|
|
315
|
+ example=3,
|
|
316
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
317
|
+ )
|
|
318
|
+ workspace_id = marshmallow.fields.Int(
|
|
319
|
+ example=4,
|
|
320
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
321
|
+ )
|
292
|
322
|
user = marshmallow.fields.Nested(
|
293
|
323
|
UserDigestSchema()
|
294
|
324
|
)
|
|
@@ -395,11 +425,13 @@ class ContentMoveSchema(marshmallow.Schema):
|
395
|
425
|
description='id of the new parent content id.',
|
396
|
426
|
allow_none=True,
|
397
|
427
|
required=True,
|
|
428
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
398
|
429
|
)
|
399
|
430
|
new_workspace_id = marshmallow.fields.Int(
|
400
|
431
|
example=2,
|
401
|
432
|
description='id of the new workspace id.',
|
402
|
|
- required=True
|
|
433
|
+ required=True,
|
|
434
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
403
|
435
|
)
|
404
|
436
|
|
405
|
437
|
@post_load
|
|
@@ -423,15 +455,20 @@ class ContentCreationSchema(marshmallow.Schema):
|
423
|
455
|
|
424
|
456
|
|
425
|
457
|
class ContentDigestSchema(marshmallow.Schema):
|
426
|
|
- content_id = marshmallow.fields.Int(example=6)
|
|
458
|
+ content_id = marshmallow.fields.Int(
|
|
459
|
+ example=6,
|
|
460
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
461
|
+ )
|
427
|
462
|
slug = marshmallow.fields.Str(example='intervention-report-12')
|
428
|
463
|
parent_id = marshmallow.fields.Int(
|
429
|
464
|
example=34,
|
430
|
465
|
allow_none=True,
|
431
|
|
- default=None
|
|
466
|
+ default=None,
|
|
467
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
432
|
468
|
)
|
433
|
469
|
workspace_id = marshmallow.fields.Int(
|
434
|
470
|
example=19,
|
|
471
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
435
|
472
|
)
|
436
|
473
|
label = marshmallow.fields.Str(example='Intervention Report 12')
|
437
|
474
|
content_type = marshmallow.fields.Str(
|
|
@@ -498,8 +535,16 @@ class TextBasedContentSchema(ContentSchema, TextBasedDataAbstractSchema):
|
498
|
535
|
|
499
|
536
|
|
500
|
537
|
class RevisionSchema(ContentDigestSchema):
|
501
|
|
- comment_ids = marshmallow.fields.List(marshmallow.fields.Int(example=4))
|
502
|
|
- revision_id = marshmallow.fields.Int(example=12)
|
|
538
|
+ comment_ids = marshmallow.fields.List(
|
|
539
|
+ marshmallow.fields.Int(
|
|
540
|
+ example=4,
|
|
541
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
542
|
+ )
|
|
543
|
+ )
|
|
544
|
+ revision_id = marshmallow.fields.Int(
|
|
545
|
+ example=12,
|
|
546
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
547
|
+ )
|
503
|
548
|
created = marshmallow.fields.DateTime(
|
504
|
549
|
format=DATETIME_FORMAT,
|
505
|
550
|
description='Content creation date',
|
|
@@ -512,8 +557,14 @@ class TextBasedRevisionSchema(RevisionSchema, TextBasedDataAbstractSchema):
|
512
|
557
|
|
513
|
558
|
|
514
|
559
|
class CommentSchema(marshmallow.Schema):
|
515
|
|
- content_id = marshmallow.fields.Int(example=6)
|
516
|
|
- parent_id = marshmallow.fields.Int(example=34)
|
|
560
|
+ content_id = marshmallow.fields.Int(
|
|
561
|
+ example=6,
|
|
562
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
563
|
+ )
|
|
564
|
+ parent_id = marshmallow.fields.Int(
|
|
565
|
+ example=34,
|
|
566
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
|
567
|
+ )
|
517
|
568
|
raw_content = marshmallow.fields.String(
|
518
|
569
|
example='<p>This is just an html comment !</p>'
|
519
|
570
|
)
|