|
|
@@ -1,7 +1,8 @@
|
|
1
|
1
|
# coding=utf-8
|
|
2
|
2
|
import marshmallow
|
|
3
|
3
|
from marshmallow import post_load
|
|
4
|
|
-from marshmallow.validate import OneOf, Range
|
|
|
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 RevisionIdPathSchema(marshmallow.Schema):
|
|
|
@@ -156,8 +172,9 @@ class RevisionPreviewSizedPathSchema(
|
|
156
|
172
|
class CommentsPathSchema(WorkspaceAndContentIdPathSchema):
|
|
157
|
173
|
comment_id = marshmallow.fields.Int(
|
|
158
|
174
|
example=6,
|
|
159
|
|
- description='id of a comment related to content content_id',
|
|
160
|
|
- required=True
|
|
|
175
|
+ description='id of a valid comment related to content content_id',
|
|
|
176
|
+ required=True,
|
|
|
177
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
161
|
178
|
)
|
|
162
|
179
|
@post_load
|
|
163
|
180
|
def make_path_object(self, data):
|
|
|
@@ -185,19 +202,22 @@ class FilterContentQuerySchema(marshmallow.Schema):
|
|
185
|
202
|
' If not set, then return all contents.'
|
|
186
|
203
|
' If set to 0, then return root contents.'
|
|
187
|
204
|
' If set to another value, return all contents'
|
|
188
|
|
- ' directly included in the folder parent_id'
|
|
|
205
|
+ ' directly included in the folder parent_id',
|
|
|
206
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
|
189
|
207
|
)
|
|
190
|
208
|
show_archived = marshmallow.fields.Int(
|
|
191
|
209
|
example=0,
|
|
192
|
210
|
default=0,
|
|
193
|
211
|
description='if set to 1, then show archived contents.'
|
|
194
|
|
- ' Default is 0 - hide archived content'
|
|
|
212
|
+ ' Default is 0 - hide archived content',
|
|
|
213
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
|
195
|
214
|
)
|
|
196
|
215
|
show_deleted = marshmallow.fields.Int(
|
|
197
|
216
|
example=0,
|
|
198
|
217
|
default=0,
|
|
199
|
218
|
description='if set to 1, then show deleted contents.'
|
|
200
|
|
- ' Default is 0 - hide deleted content'
|
|
|
219
|
+ ' Default is 0 - hide deleted content',
|
|
|
220
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
|
201
|
221
|
)
|
|
202
|
222
|
show_active = marshmallow.fields.Int(
|
|
203
|
223
|
example=1,
|
|
|
@@ -207,7 +227,8 @@ class FilterContentQuerySchema(marshmallow.Schema):
|
|
207
|
227
|
' Note: active content are content '
|
|
208
|
228
|
'that is neither archived nor deleted. '
|
|
209
|
229
|
'The reason for this parameter to exist is for example '
|
|
210
|
|
- 'to allow to show only archived documents'
|
|
|
230
|
+ 'to allow to show only archived documents',
|
|
|
231
|
+ validate=Range(min=0, max=1, error="Value must be 0 or 1"),
|
|
211
|
232
|
)
|
|
212
|
233
|
|
|
213
|
234
|
@post_load
|
|
|
@@ -271,7 +292,10 @@ class WorkspaceMenuEntrySchema(marshmallow.Schema):
|
|
271
|
292
|
|
|
272
|
293
|
|
|
273
|
294
|
class WorkspaceDigestSchema(marshmallow.Schema):
|
|
274
|
|
- workspace_id = marshmallow.fields.Int(example=4)
|
|
|
295
|
+ workspace_id = marshmallow.fields.Int(
|
|
|
296
|
+ example=4,
|
|
|
297
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
298
|
+ )
|
|
275
|
299
|
slug = marshmallow.fields.String(example='intranet')
|
|
276
|
300
|
label = marshmallow.fields.String(example='Intranet')
|
|
277
|
301
|
sidebar_entries = marshmallow.fields.Nested(
|
|
|
@@ -295,8 +319,14 @@ class WorkspaceMemberSchema(marshmallow.Schema):
|
|
295
|
319
|
example='contributor',
|
|
296
|
320
|
validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
|
|
297
|
321
|
)
|
|
298
|
|
- user_id = marshmallow.fields.Int(example=3)
|
|
299
|
|
- workspace_id = marshmallow.fields.Int(example=4)
|
|
|
322
|
+ user_id = marshmallow.fields.Int(
|
|
|
323
|
+ example=3,
|
|
|
324
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
325
|
+ )
|
|
|
326
|
+ workspace_id = marshmallow.fields.Int(
|
|
|
327
|
+ example=4,
|
|
|
328
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
329
|
+ )
|
|
300
|
330
|
user = marshmallow.fields.Nested(
|
|
301
|
331
|
UserSchema(only=('public_name', 'avatar_url'))
|
|
302
|
332
|
)
|
|
|
@@ -385,11 +415,13 @@ class ContentMoveSchema(marshmallow.Schema):
|
|
385
|
415
|
description='id of the new parent content id.',
|
|
386
|
416
|
allow_none=True,
|
|
387
|
417
|
required=True,
|
|
|
418
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
|
388
|
419
|
)
|
|
389
|
420
|
new_workspace_id = marshmallow.fields.Int(
|
|
390
|
421
|
example=2,
|
|
391
|
422
|
description='id of the new workspace id.',
|
|
392
|
|
- required=True
|
|
|
423
|
+ required=True,
|
|
|
424
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
393
|
425
|
)
|
|
394
|
426
|
|
|
395
|
427
|
@post_load
|
|
|
@@ -406,6 +438,11 @@ class ContentCreationSchema(marshmallow.Schema):
|
|
406
|
438
|
example='html-documents',
|
|
407
|
439
|
validate=OneOf(ContentType.allowed_types_for_folding()), # nopep8
|
|
408
|
440
|
)
|
|
|
441
|
+ parent_id = marshmallow.fields.Integer(
|
|
|
442
|
+ example=35,
|
|
|
443
|
+ description='content_id of parent content, if content should be placed in a folder, this should be folder content_id.'
|
|
|
444
|
+ )
|
|
|
445
|
+
|
|
409
|
446
|
|
|
410
|
447
|
@post_load
|
|
411
|
448
|
def make_content_filter(self, data):
|
|
|
@@ -413,15 +450,20 @@ class ContentCreationSchema(marshmallow.Schema):
|
|
413
|
450
|
|
|
414
|
451
|
|
|
415
|
452
|
class ContentDigestSchema(marshmallow.Schema):
|
|
416
|
|
- content_id = marshmallow.fields.Int(example=6)
|
|
|
453
|
+ content_id = marshmallow.fields.Int(
|
|
|
454
|
+ example=6,
|
|
|
455
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
456
|
+ )
|
|
417
|
457
|
slug = marshmallow.fields.Str(example='intervention-report-12')
|
|
418
|
458
|
parent_id = marshmallow.fields.Int(
|
|
419
|
459
|
example=34,
|
|
420
|
460
|
allow_none=True,
|
|
421
|
|
- default=None
|
|
|
461
|
+ default=None,
|
|
|
462
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
|
422
|
463
|
)
|
|
423
|
464
|
workspace_id = marshmallow.fields.Int(
|
|
424
|
465
|
example=19,
|
|
|
466
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
425
|
467
|
)
|
|
426
|
468
|
label = marshmallow.fields.Str(example='Intervention Report 12')
|
|
427
|
469
|
content_type = marshmallow.fields.Str(
|
|
|
@@ -497,8 +539,16 @@ class FileContentSchema(ContentSchema, FileInfoAbstractSchema):
|
|
497
|
539
|
|
|
498
|
540
|
|
|
499
|
541
|
class RevisionSchema(ContentDigestSchema):
|
|
500
|
|
- comment_ids = marshmallow.fields.List(marshmallow.fields.Int(example=4))
|
|
501
|
|
- revision_id = marshmallow.fields.Int(example=12)
|
|
|
542
|
+ comment_ids = marshmallow.fields.List(
|
|
|
543
|
+ marshmallow.fields.Int(
|
|
|
544
|
+ example=4,
|
|
|
545
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
546
|
+ )
|
|
|
547
|
+ )
|
|
|
548
|
+ revision_id = marshmallow.fields.Int(
|
|
|
549
|
+ example=12,
|
|
|
550
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
551
|
+ )
|
|
502
|
552
|
created = marshmallow.fields.DateTime(
|
|
503
|
553
|
format=DATETIME_FORMAT,
|
|
504
|
554
|
description='Content creation date',
|
|
|
@@ -515,8 +565,14 @@ class FileRevisionSchema(RevisionSchema, FileInfoAbstractSchema):
|
|
515
|
565
|
|
|
516
|
566
|
|
|
517
|
567
|
class CommentSchema(marshmallow.Schema):
|
|
518
|
|
- content_id = marshmallow.fields.Int(example=6)
|
|
519
|
|
- parent_id = marshmallow.fields.Int(example=34)
|
|
|
568
|
+ content_id = marshmallow.fields.Int(
|
|
|
569
|
+ example=6,
|
|
|
570
|
+ validate=Range(min=1, error="Value must be greater than 0"),
|
|
|
571
|
+ )
|
|
|
572
|
+ parent_id = marshmallow.fields.Int(
|
|
|
573
|
+ example=34,
|
|
|
574
|
+ validate=Range(min=0, error="Value must be positive or 0"),
|
|
|
575
|
+ )
|
|
520
|
576
|
raw_content = marshmallow.fields.String(
|
|
521
|
577
|
example='<p>This is just an html comment !</p>'
|
|
522
|
578
|
)
|