Browse Source

refactor content type

Guénaël Muller 6 years ago
parent
commit
8626defced
29 changed files with 530 additions and 563 deletions
  1. 7 6
      backend/tracim_backend/config.py
  2. 18 18
      backend/tracim_backend/fixtures/content.py
  3. 65 59
      backend/tracim_backend/lib/core/content.py
  4. 10 10
      backend/tracim_backend/lib/mail_notifier/notifier.py
  5. 6 6
      backend/tracim_backend/lib/utils/authorization.py
  6. 3 3
      backend/tracim_backend/lib/utils/request.py
  7. 7 5
      backend/tracim_backend/lib/webdav/dav_provider.py
  8. 3 2
      backend/tracim_backend/lib/webdav/design.py
  9. 37 34
      backend/tracim_backend/lib/webdav/resources.py
  10. 5 3
      backend/tracim_backend/lib/webdav/utils.py
  11. 57 101
      backend/tracim_backend/models/contents.py
  12. 3 7
      backend/tracim_backend/models/context_models.py
  13. 21 22
      backend/tracim_backend/models/data.py
  14. 3 3
      backend/tracim_backend/tests/__init__.py
  15. 37 38
      backend/tracim_backend/tests/functional/test_contents.py
  16. 5 5
      backend/tracim_backend/tests/functional/test_mail_notification.py
  17. 4 4
      backend/tracim_backend/tests/functional/test_system.py
  18. 47 47
      backend/tracim_backend/tests/functional/test_user.py
  19. 14 14
      backend/tracim_backend/tests/functional/test_workspaces.py
  20. 115 115
      backend/tracim_backend/tests/library/test_content_api.py
  21. 6 6
      backend/tracim_backend/tests/models/test_content.py
  22. 4 3
      backend/tracim_backend/tests/models/test_content_revision.py
  23. 5 5
      backend/tracim_backend/views/contents_api/comment_controller.py
  24. 14 14
      backend/tracim_backend/views/contents_api/file_controller.py
  25. 5 5
      backend/tracim_backend/views/contents_api/html_document_controller.py
  26. 5 5
      backend/tracim_backend/views/contents_api/threads_controller.py
  27. 10 9
      backend/tracim_backend/views/core_api/schemas.py
  28. 3 3
      backend/tracim_backend/views/core_api/system_controller.py
  29. 11 11
      backend/tracim_backend/views/core_api/workspace_controller.py

+ 7 - 6
backend/tracim_backend/config.py View File

3
 from paste.deploy.converters import asbool
3
 from paste.deploy.converters import asbool
4
 from tracim_backend.lib.utils.logger import logger
4
 from tracim_backend.lib.utils.logger import logger
5
 from depot.manager import DepotManager
5
 from depot.manager import DepotManager
6
+from tracim_backend.models.contents import CONTENT_TYPES
7
+from tracim_backend.models.data import ActionDescription
6
 
8
 
7
-from tracim_backend.models.data import ActionDescription, ContentType
8
 
9
 
9
 
10
 
10
 class CFG(object):
11
 class CFG(object):
145
         ]
146
         ]
146
 
147
 
147
         self.EMAIL_NOTIFICATION_NOTIFIED_CONTENTS = [
148
         self.EMAIL_NOTIFICATION_NOTIFIED_CONTENTS = [
148
-            ContentType.Page,
149
-            ContentType.Thread,
150
-            ContentType.File,
151
-            ContentType.Comment,
152
-            # ContentType.Folder -- Folder is skipped
149
+            CONTENT_TYPES.Page.slug,
150
+            CONTENT_TYPES.Thread.slug,
151
+            CONTENT_TYPES.File.slug,
152
+            CONTENT_TYPES.Comment.slug,
153
+            # CONTENT_TYPES.Folder.slug -- Folder is skipped
153
         ]
154
         ]
154
         if settings.get('email.notification.from'):
155
         if settings.get('email.notification.from'):
155
             raise Exception(
156
             raise Exception(

+ 18 - 18
backend/tracim_backend/fixtures/content.py View File

8
 from tracim_backend.lib.core.content import ContentApi
8
 from tracim_backend.lib.core.content import ContentApi
9
 from tracim_backend.lib.core.userworkspace import RoleApi
9
 from tracim_backend.lib.core.userworkspace import RoleApi
10
 from tracim_backend.lib.core.workspace import WorkspaceApi
10
 from tracim_backend.lib.core.workspace import WorkspaceApi
11
-from tracim_backend.models.data import ContentType
11
+from tracim_backend.models.contents import CONTENT_TYPES
12
 from tracim_backend.models.data import UserRoleInWorkspace
12
 from tracim_backend.models.data import UserRoleInWorkspace
13
 from tracim_backend.models.revision_protection import new_revision
13
 from tracim_backend.models.revision_protection import new_revision
14
 
14
 
91
         # Folders
91
         # Folders
92
 
92
 
93
         tool_workspace = content_api.create(
93
         tool_workspace = content_api.create(
94
-            content_type=ContentType.Folder,
94
+            content_type_slug=CONTENT_TYPES.Folder.slug,
95
             workspace=business_workspace,
95
             workspace=business_workspace,
96
             label='Tools',
96
             label='Tools',
97
             do_save=True,
97
             do_save=True,
98
             do_notify=False,
98
             do_notify=False,
99
         )
99
         )
100
         menu_workspace = content_api.create(
100
         menu_workspace = content_api.create(
101
-            content_type=ContentType.Folder,
101
+            content_type_slug=CONTENT_TYPES.Folder.slug,
102
             workspace=business_workspace,
102
             workspace=business_workspace,
103
             label='Menus',
103
             label='Menus',
104
             do_save=True,
104
             do_save=True,
106
         )
106
         )
107
 
107
 
108
         dessert_folder = content_api.create(
108
         dessert_folder = content_api.create(
109
-            content_type=ContentType.Folder,
109
+            content_type_slug=CONTENT_TYPES.Folder.slug,
110
             workspace=recipe_workspace,
110
             workspace=recipe_workspace,
111
             label='Desserts',
111
             label='Desserts',
112
             do_save=True,
112
             do_save=True,
113
             do_notify=False,
113
             do_notify=False,
114
         )
114
         )
115
         salads_folder = content_api.create(
115
         salads_folder = content_api.create(
116
-            content_type=ContentType.Folder,
116
+            content_type_slug=CONTENT_TYPES.Folder.slug,
117
             workspace=recipe_workspace,
117
             workspace=recipe_workspace,
118
             label='Salads',
118
             label='Salads',
119
             do_save=True,
119
             do_save=True,
120
             do_notify=False,
120
             do_notify=False,
121
         )
121
         )
122
         other_folder = content_api.create(
122
         other_folder = content_api.create(
123
-            content_type=ContentType.Folder,
123
+            content_type_slug=CONTENT_TYPES.Folder.slug,
124
             workspace=other_workspace,
124
             workspace=other_workspace,
125
             label='Infos',
125
             label='Infos',
126
             do_save=True,
126
             do_save=True,
129
 
129
 
130
         # Pages, threads, ..
130
         # Pages, threads, ..
131
         tiramisu_page = content_api.create(
131
         tiramisu_page = content_api.create(
132
-            content_type=ContentType.Page,
132
+            content_type_slug=CONTENT_TYPES.Page.slug,
133
             workspace=recipe_workspace,
133
             workspace=recipe_workspace,
134
             parent=dessert_folder,
134
             parent=dessert_folder,
135
             label='Tiramisu Recipes!!!',
135
             label='Tiramisu Recipes!!!',
149
             content_api.save(tiramisu_page)
149
             content_api.save(tiramisu_page)
150
 
150
 
151
         best_cake_thread = content_api.create(
151
         best_cake_thread = content_api.create(
152
-            content_type=ContentType.Thread,
152
+            content_type_slug=CONTENT_TYPES.Thread.slug,
153
             workspace=recipe_workspace,
153
             workspace=recipe_workspace,
154
             parent=dessert_folder,
154
             parent=dessert_folder,
155
             label='Best Cake',
155
             label='Best Cake',
159
         best_cake_thread.description = 'Which is the best cake?'
159
         best_cake_thread.description = 'Which is the best cake?'
160
         self._session.add(best_cake_thread)
160
         self._session.add(best_cake_thread)
161
         apple_pie_recipe = content_api.create(
161
         apple_pie_recipe = content_api.create(
162
-            content_type=ContentType.File,
162
+            content_type_slug=CONTENT_TYPES.File.slug,
163
             workspace=recipe_workspace,
163
             workspace=recipe_workspace,
164
             parent=dessert_folder,
164
             parent=dessert_folder,
165
             label='Apple_Pie',
165
             label='Apple_Pie',
174
         )
174
         )
175
         self._session.add(apple_pie_recipe)
175
         self._session.add(apple_pie_recipe)
176
         Brownie_recipe = content_api.create(
176
         Brownie_recipe = content_api.create(
177
-            content_type=ContentType.File,
177
+            content_type_slug=CONTENT_TYPES.File.slug,
178
             workspace=recipe_workspace,
178
             workspace=recipe_workspace,
179
             parent=dessert_folder,
179
             parent=dessert_folder,
180
             label='Brownie Recipe',
180
             label='Brownie Recipe',
189
         )
189
         )
190
         self._session.add(Brownie_recipe)
190
         self._session.add(Brownie_recipe)
191
         fruits_desserts_folder = content_api.create(
191
         fruits_desserts_folder = content_api.create(
192
-            content_type=ContentType.Folder,
192
+            content_type_slug=CONTENT_TYPES.Folder.slug,
193
             workspace=recipe_workspace,
193
             workspace=recipe_workspace,
194
             label='Fruits Desserts',
194
             label='Fruits Desserts',
195
             parent=dessert_folder,
195
             parent=dessert_folder,
197
         )
197
         )
198
 
198
 
199
         menu_page = content_api.create(
199
         menu_page = content_api.create(
200
-            content_type=ContentType.Page,
200
+            content_type_slug=CONTENT_TYPES.Page.slug,
201
             workspace=business_workspace,
201
             workspace=business_workspace,
202
             parent=menu_workspace,
202
             parent=menu_workspace,
203
             label='Current Menu',
203
             label='Current Menu',
205
         )
205
         )
206
 
206
 
207
         new_fruit_salad = content_api.create(
207
         new_fruit_salad = content_api.create(
208
-            content_type=ContentType.Page,
208
+            content_type_slug=CONTENT_TYPES.Page.slug,
209
             workspace=recipe_workspace,
209
             workspace=recipe_workspace,
210
             parent=fruits_desserts_folder,
210
             parent=fruits_desserts_folder,
211
             label='New Fruit Salad',
211
             label='New Fruit Salad',
212
             do_save=True,
212
             do_save=True,
213
         )
213
         )
214
         old_fruit_salad = content_api.create(
214
         old_fruit_salad = content_api.create(
215
-            content_type=ContentType.Page,
215
+            content_type_slug=CONTENT_TYPES.Page.slug,
216
             workspace=recipe_workspace,
216
             workspace=recipe_workspace,
217
             parent=fruits_desserts_folder,
217
             parent=fruits_desserts_folder,
218
             label='Fruit Salad',
218
             label='Fruit Salad',
228
         content_api.save(old_fruit_salad)
228
         content_api.save(old_fruit_salad)
229
 
229
 
230
         bad_fruit_salad = content_api.create(
230
         bad_fruit_salad = content_api.create(
231
-            content_type=ContentType.Page,
231
+            content_type_slug=CONTENT_TYPES.Page.slug,
232
             workspace=recipe_workspace,
232
             workspace=recipe_workspace,
233
             parent=fruits_desserts_folder,
233
             parent=fruits_desserts_folder,
234
             label='Bad Fruit Salad',
234
             label='Bad Fruit Salad',
245
 
245
 
246
         # File at the root for test
246
         # File at the root for test
247
         new_fruit_salad = content_api.create(
247
         new_fruit_salad = content_api.create(
248
-            content_type=ContentType.Page,
248
+            content_type_slug=CONTENT_TYPES.Page.slug,
249
             workspace=other_workspace,
249
             workspace=other_workspace,
250
             label='New Fruit Salad',
250
             label='New Fruit Salad',
251
             do_save=True,
251
             do_save=True,
252
         )
252
         )
253
         old_fruit_salad = content_api.create(
253
         old_fruit_salad = content_api.create(
254
-            content_type=ContentType.Page,
254
+            content_type_slug=CONTENT_TYPES.Page.slug,
255
             workspace=other_workspace,
255
             workspace=other_workspace,
256
             label='Fruit Salad',
256
             label='Fruit Salad',
257
             do_save=True,
257
             do_save=True,
265
         content_api.save(old_fruit_salad)
265
         content_api.save(old_fruit_salad)
266
 
266
 
267
         bad_fruit_salad = content_api.create(
267
         bad_fruit_salad = content_api.create(
268
-            content_type=ContentType.Page,
268
+            content_type_slug=CONTENT_TYPES.Page.slug,
269
             workspace=other_workspace,
269
             workspace=other_workspace,
270
             label='Bad Fruit Salad',
270
             label='Bad Fruit Salad',
271
             do_save=True,
271
             do_save=True,

+ 65 - 59
backend/tracim_backend/lib/core/content.py View File

35
 from tracim_backend.exceptions import WorkspacesDoNotMatch
35
 from tracim_backend.exceptions import WorkspacesDoNotMatch
36
 from tracim_backend.lib.utils.utils import current_date_for_filename
36
 from tracim_backend.lib.utils.utils import current_date_for_filename
37
 from tracim_backend.models.contents import CONTENT_STATUS
37
 from tracim_backend.models.contents import CONTENT_STATUS
38
+from tracim_backend.models.contents import ContentType
39
+from tracim_backend.models.contents import CONTENT_TYPES
38
 from tracim_backend.models.revision_protection import new_revision
40
 from tracim_backend.models.revision_protection import new_revision
39
 from tracim_backend.models.auth import User
41
 from tracim_backend.models.auth import User
40
 from tracim_backend.models.data import ActionDescription
42
 from tracim_backend.models.data import ActionDescription
41
 from tracim_backend.models.data import ContentRevisionRO
43
 from tracim_backend.models.data import ContentRevisionRO
42
 from tracim_backend.models.data import Content
44
 from tracim_backend.models.data import Content
43
-from tracim_backend.models.data import ContentType
45
+
44
 from tracim_backend.models.data import NodeTreeItem
46
 from tracim_backend.models.data import NodeTreeItem
45
 from tracim_backend.models.data import RevisionReadStatus
47
 from tracim_backend.models.data import RevisionReadStatus
46
 from tracim_backend.models.data import UserRoleInWorkspace
48
 from tracim_backend.models.data import UserRoleInWorkspace
75
     else:
77
     else:
76
         # TODO - D.A. - 2014-12-02 - Manage Content Types Dynamically
78
         # TODO - D.A. - 2014-12-02 - Manage Content Types Dynamically
77
         content_type_order = [
79
         content_type_order = [
78
-            ContentType.Folder,
79
-            ContentType.Page,
80
-            ContentType.Thread,
81
-            ContentType.File,
80
+            CONTENT_TYPES.Folder.slug,
81
+            CONTENT_TYPES.Page.slug,
82
+            CONTENT_TYPES.Thread.slug,
83
+            CONTENT_TYPES.File.slug,
82
         ]
84
         ]
83
 
85
 
84
         content_1_type_index = content_type_order.index(content1.type)
86
         content_1_type_index = content_type_order.index(content1.type)
105
     SEARCH_SEPARATORS = ',| '
107
     SEARCH_SEPARATORS = ',| '
106
     SEARCH_DEFAULT_RESULT_NB = 50
108
     SEARCH_DEFAULT_RESULT_NB = 50
107
 
109
 
108
-    DISPLAYABLE_CONTENTS = (
109
-        ContentType.Folder,
110
-        ContentType.File,
111
-        ContentType.Comment,
112
-        ContentType.Thread,
113
-        ContentType.Page,
114
-        ContentType.PageLegacy,
115
-        ContentType.MarkdownPage,
116
-    )
110
+    # DISPLAYABLE_CONTENTS = (
111
+    #     CONTENT_TYPES.Folder.slug,
112
+    #     CONTENT_TYPES.File.slug,
113
+    #     CONTENT_TYPES.Comment.slug,
114
+    #     CONTENT_TYPES.Thread.slug,
115
+    #     CONTENT_TYPES.Page.slug,
116
+    #     CONTENT_TYPES.Page.slugLegacy,
117
+    #     ContentType.MarkdownPage,
118
+    # )
117
 
119
 
118
     def __init__(
120
     def __init__(
119
             self,
121
             self,
230
 
232
 
231
         # Exclude non displayable types
233
         # Exclude non displayable types
232
         if not self._force_show_all_types:
234
         if not self._force_show_all_types:
233
-            result = result.filter(Content.type.in_(self.DISPLAYABLE_CONTENTS))
235
+            result = result.filter(Content.type.in_(CONTENT_TYPES.query_allowed_types_slugs()))
234
 
236
 
235
         if workspace:
237
         if workspace:
236
             result = result.filter(Content.workspace_id == workspace.workspace_id)
238
             result = result.filter(Content.workspace_id == workspace.workspace_id)
369
     #     removed_item_ids = removed_item_ids or []  # FDV
371
     #     removed_item_ids = removed_item_ids or []  # FDV
370
     # 
372
     # 
371
     #     if not allowed_node_types:
373
     #     if not allowed_node_types:
372
-    #         allowed_node_types = [ContentType.Folder]
373
-    #     elif allowed_node_types==ContentType.Any:
374
+    #         allowed_node_types = [CONTENT_TYPES.Folder.slug]
375
+    #     elif allowed_node_types==CONTENT_TYPES.Any_SLUG:
374
     #         allowed_node_types = ContentType.all()
376
     #         allowed_node_types = ContentType.all()
375
     # 
377
     # 
376
     #     parent_id = parent.content_id if parent else None
378
     #     parent_id = parent.content_id if parent else None
395
     #     for folder in folders:
397
     #     for folder in folders:
396
     #         for allowed_content_type in filter_by_allowed_content_types:
398
     #         for allowed_content_type in filter_by_allowed_content_types:
397
     # 
399
     # 
398
-    #             is_folder = folder.type == ContentType.Folder
400
+    #             is_folder = folder.type == CONTENT_TYPES.Folder.slug
399
     #             content_type__allowed = folder.properties['allowed_content'][allowed_content_type] == True
401
     #             content_type__allowed = folder.properties['allowed_content'][allowed_content_type] == True
400
     # 
402
     # 
401
     #             if is_folder and content_type__allowed:
403
     #             if is_folder and content_type__allowed:
404
     # 
406
     # 
405
     #     return result
407
     #     return result
406
 
408
 
407
-    def create(self, content_type: str, workspace: Workspace, parent: Content=None, label: str ='', filename: str = '', do_save=False, is_temporary: bool=False, do_notify=True) -> Content:
409
+    def create(self, content_type_slug: str, workspace: Workspace, parent: Content=None, label: str = '', filename: str = '', do_save=False, is_temporary: bool=False, do_notify=True) -> Content:
408
         # TODO - G.M - 2018-07-16 - raise Exception instead of assert
410
         # TODO - G.M - 2018-07-16 - raise Exception instead of assert
409
-        assert content_type in ContentType.allowed_types()
411
+        assert content_type_slug in CONTENT_TYPES.query_allowed_types_slugs()
412
+        assert content_type_slug != CONTENT_TYPES.Any_SLUG
410
         assert not (label and filename)
413
         assert not (label and filename)
411
 
414
 
412
-        if content_type == ContentType.Folder and not label:
415
+        if content_type_slug == CONTENT_TYPES.Folder.slug and not label:
413
             label = self.generate_folder_label(workspace, parent)
416
             label = self.generate_folder_label(workspace, parent)
414
 
417
 
415
         content = Content()
418
         content = Content()
421
         elif label:
424
         elif label:
422
             content.label = label
425
             content.label = label
423
         else:
426
         else:
424
-            if content_type == ContentType.Comment:
427
+            if content_type_slug == CONTENT_TYPES.Comment.slug:
425
                 # INFO - G.M - 2018-07-16 - Default label for comments is
428
                 # INFO - G.M - 2018-07-16 - Default label for comments is
426
                 # empty string.
429
                 # empty string.
427
                 content.label = ''
430
                 content.label = ''
431
         content.owner = self._user
434
         content.owner = self._user
432
         content.parent = parent
435
         content.parent = parent
433
         content.workspace = workspace
436
         content.workspace = workspace
434
-        content.type = content_type
437
+        content.type = content_type_slug
435
         content.is_temporary = is_temporary
438
         content.is_temporary = is_temporary
436
         content.revision_type = ActionDescription.CREATION
439
         content.revision_type = ActionDescription.CREATION
437
 
440
 
438
         if content.type in (
441
         if content.type in (
439
-                ContentType.Page,
440
-                ContentType.Thread,
442
+                CONTENT_TYPES.Page.slug,
443
+                CONTENT_TYPES.Thread.slug,
441
         ):
444
         ):
442
             content.file_extension = '.html'
445
             content.file_extension = '.html'
443
 
446
 
447
         return content
450
         return content
448
 
451
 
449
     def create_comment(self, workspace: Workspace=None, parent: Content=None, content:str ='', do_save=False) -> Content:
452
     def create_comment(self, workspace: Workspace=None, parent: Content=None, content:str ='', do_save=False) -> Content:
450
-        assert parent and parent.type != ContentType.Folder
453
+        assert parent and parent.type != CONTENT_TYPES.Folder.slug
451
         if not content:
454
         if not content:
452
             raise EmptyCommentContentNotAllowed()
455
             raise EmptyCommentContentNotAllowed()
453
         item = Content()
456
         item = Content()
456
         if not workspace:
459
         if not workspace:
457
             workspace = item.parent.workspace
460
             workspace = item.parent.workspace
458
         item.workspace = workspace
461
         item.workspace = workspace
459
-        item.type = ContentType.Comment
462
+        item.type = CONTENT_TYPES.Comment.slug
460
         item.description = content
463
         item.description = content
461
         item.label = ''
464
         item.label = ''
462
         item.revision_type = ActionDescription.COMMENT
465
         item.revision_type = ActionDescription.COMMENT
492
 
495
 
493
         base_request = self._base_query(workspace).filter(Content.content_id==content_id)
496
         base_request = self._base_query(workspace).filter(Content.content_id==content_id)
494
 
497
 
495
-        if content_type!=ContentType.Any:
498
+        if content_type!=CONTENT_TYPES.Any_SLUG:
496
             base_request = base_request.filter(Content.type==content_type)
499
             base_request = base_request.filter(Content.type==content_type)
497
 
500
 
498
         if parent:
501
         if parent:
577
         return query.filter(
580
         return query.filter(
578
             or_(
581
             or_(
579
                 and_(
582
                 and_(
580
-                    Content.type == ContentType.File,
583
+                    Content.type == CONTENT_TYPES.File.slug,
581
                     Content.label == file_name,
584
                     Content.label == file_name,
582
                     Content.file_extension == file_extension,
585
                     Content.file_extension == file_extension,
583
                 ),
586
                 ),
584
                 and_(
587
                 and_(
585
-                    Content.type == ContentType.Thread,
588
+                    Content.type == CONTENT_TYPES.Thread.slug,
586
                     Content.label == file_name,
589
                     Content.label == file_name,
587
                 ),
590
                 ),
588
                 and_(
591
                 and_(
589
-                    Content.type == ContentType.Page,
592
+                    Content.type == CONTENT_TYPES.Page.slug,
590
                     Content.label == file_name,
593
                     Content.label == file_name,
591
                 ),
594
                 ),
592
                 and_(
595
                 and_(
593
-                    Content.type == ContentType.Folder,
596
+                    Content.type == CONTENT_TYPES.Folder.slug,
594
                     Content.label == content_label,
597
                     Content.label == content_label,
595
                 ),
598
                 ),
596
             )
599
             )
671
             # Filter query on label
674
             # Filter query on label
672
             folder_query = query \
675
             folder_query = query \
673
                 .filter(
676
                 .filter(
674
-                    Content.type == ContentType.Folder,
677
+                    Content.type == CONTENT_TYPES.Folder.slug,
675
                     Content.label == label,
678
                     Content.label == label,
676
                     Content.workspace_id == workspace.workspace_id,
679
                     Content.workspace_id == workspace.workspace_id,
677
                 )
680
                 )
723
 
726
 
724
         return query.filter(or_(
727
         return query.filter(or_(
725
             and_(
728
             and_(
726
-                Content.type == ContentType.File,
729
+                Content.type == CONTENT_TYPES.File.slug,
727
                 file_name_filter,
730
                 file_name_filter,
728
                 file_extension_filter,
731
                 file_extension_filter,
729
             ),
732
             ),
730
             and_(
733
             and_(
731
-                Content.type == ContentType.Thread,
734
+                Content.type == CONTENT_TYPES.Thread.slug,
732
                 file_name_filter,
735
                 file_name_filter,
733
                 file_extension_filter,
736
                 file_extension_filter,
734
             ),
737
             ),
735
             and_(
738
             and_(
736
-                Content.type == ContentType.Page,
739
+                Content.type == CONTENT_TYPES.Page.slug,
737
                 file_name_filter,
740
                 file_name_filter,
738
                 file_extension_filter,
741
                 file_extension_filter,
739
             ),
742
             ),
740
             and_(
743
             and_(
741
-                Content.type == ContentType.Folder,
744
+                Content.type == CONTENT_TYPES.Folder.slug,
742
                 label_filter,
745
                 label_filter,
743
             ),
746
             ),
744
         ))
747
         ))
844
     def _get_all_query(
847
     def _get_all_query(
845
         self,
848
         self,
846
         parent_id: int = None,
849
         parent_id: int = None,
847
-        content_type: str = ContentType.Any,
850
+        content_type_slug: str = CONTENT_TYPES.Any_SLUG,
848
         workspace: Workspace = None
851
         workspace: Workspace = None
849
     ) -> Query:
852
     ) -> Query:
850
         """
853
         """
851
         Extended filter for better "get all data" query
854
         Extended filter for better "get all data" query
852
         :param parent_id: filter by parent_id
855
         :param parent_id: filter by parent_id
853
-        :param content_type: filter by content_type slug
856
+        :param content_type_slug: filter by content_type slug
854
         :param workspace: filter by workspace
857
         :param workspace: filter by workspace
855
         :return:
858
         :return:
856
         """
859
         """
857
         assert parent_id is None or isinstance(parent_id, int)
860
         assert parent_id is None or isinstance(parent_id, int)
858
-        assert content_type is not None
861
+        assert content_type_slug is not None
859
         resultset = self._base_query(workspace)
862
         resultset = self._base_query(workspace)
860
 
863
 
861
-        if content_type!=ContentType.Any:
864
+        if content_type_slug != CONTENT_TYPES.Any_SLUG:
862
             # INFO - G.M - 2018-07-05 - convert with
865
             # INFO - G.M - 2018-07-05 - convert with
863
             #  content type object to support legacy slug
866
             #  content type object to support legacy slug
864
-            content_type_object = ContentType(content_type)
865
-            resultset = resultset.filter(Content.type.in_(content_type_object.get_slug_aliases()))
867
+            content_type_object = CONTENT_TYPES.get_one_by_slug(content_type_slug)
868
+            all_slug_alias = [content_type_object.slug]
869
+            if content_type_object.slug_alias:
870
+                all_slug_alias.extend(content_type_object.slug_alias)
871
+            resultset = resultset.filter(Content.type.in_(all_slug_alias))
866
 
872
 
867
         if parent_id:
873
         if parent_id:
868
             resultset = resultset.filter(Content.parent_id==parent_id)
874
             resultset = resultset.filter(Content.parent_id==parent_id)
871
 
877
 
872
         return resultset
878
         return resultset
873
 
879
 
874
-    def get_all(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> typing.List[Content]:
880
+    def get_all(self, parent_id: int=None, content_type: str=CONTENT_TYPES.Any_SLUG, workspace: Workspace=None) -> typing.List[Content]:
875
         return self._get_all_query(parent_id, content_type, workspace).all()
881
         return self._get_all_query(parent_id, content_type, workspace).all()
876
 
882
 
877
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
883
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
895
 
901
 
896
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
902
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
897
     # TODO find an other name to filter on is_deleted / is_archived
903
     # TODO find an other name to filter on is_deleted / is_archived
898
-    def get_all_with_filter(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> typing.List[Content]:
904
+    def get_all_with_filter(self, parent_id: int=None, content_type: str=CONTENT_TYPES.Any_SLUG, workspace: Workspace=None) -> typing.List[Content]:
899
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
905
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
900
         assert content_type is not None# DYN_REMOVE
906
         assert content_type is not None# DYN_REMOVE
901
         assert isinstance(content_type, str) # DYN_REMOVE
907
         assert isinstance(content_type, str) # DYN_REMOVE
902
 
908
 
903
         resultset = self._base_query(workspace)
909
         resultset = self._base_query(workspace)
904
 
910
 
905
-        if content_type != ContentType.Any:
911
+        if content_type != CONTENT_TYPES.Any_SLUG:
906
             resultset = resultset.filter(Content.type==content_type)
912
             resultset = resultset.filter(Content.type==content_type)
907
 
913
 
908
         resultset = resultset.filter(Content.is_deleted == self._show_deleted)
914
         resultset = resultset.filter(Content.is_deleted == self._show_deleted)
919
 
925
 
920
         resultset = self._base_query(workspace)
926
         resultset = self._base_query(workspace)
921
 
927
 
922
-        if content_type != ContentType.Any:
928
+        if content_type != CONTENT_TYPES.Any_SLUG:
923
             resultset = resultset.filter(Content.type==content_type)
929
             resultset = resultset.filter(Content.type==content_type)
924
 
930
 
925
         return resultset.all()
931
         return resultset.all()
934
             .filter(Workspace.is_deleted.is_(False)) \
940
             .filter(Workspace.is_deleted.is_(False)) \
935
             .order_by(desc(Content.updated))
941
             .order_by(desc(Content.updated))
936
 
942
 
937
-        if content_type!=ContentType.Any:
943
+        if content_type!=CONTENT_TYPES.Any_SLUG:
938
             resultset = resultset.filter(Content.type==content_type)
944
             resultset = resultset.filter(Content.type==content_type)
939
 
945
 
940
         if parent_id:
946
         if parent_id:
943
         result = []
949
         result = []
944
         for item in resultset:
950
         for item in resultset:
945
             new_item = None
951
             new_item = None
946
-            if ContentType.Comment == item.type:
952
+            if CONTENT_TYPES.Comment.slug == item.type:
947
                 new_item = item.parent
953
                 new_item = item.parent
948
             else:
954
             else:
949
                 new_item = item
955
                 new_item = item
980
     #
986
     #
981
     #     resultset = self._base_query(workspace)
987
     #     resultset = self._base_query(workspace)
982
     #
988
     #
983
-    #     if content_type != ContentType.Any:
989
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
984
     #         resultset = resultset.filter(Content.type==content_type)
990
     #         resultset = resultset.filter(Content.type==content_type)
985
     #
991
     #
986
     #     return resultset.all()
992
     #     return resultset.all()
1012
                     Content.content_id.in_(content_ids),
1018
                     Content.content_id.in_(content_ids),
1013
                     and_(
1019
                     and_(
1014
                         Content.parent_id.in_(content_ids),
1020
                         Content.parent_id.in_(content_ids),
1015
-                        Content.type == ContentType.Comment
1021
+                        Content.type == CONTENT_TYPES.Comment.slug
1016
                     )
1022
                     )
1017
                 )
1023
                 )
1018
             )
1024
             )
1023
         too_recent_content = []
1029
         too_recent_content = []
1024
         for content in resultset:
1030
         for content in resultset:
1025
             related_active_content = None
1031
             related_active_content = None
1026
-            if ContentType.Comment == content.type:
1032
+            if CONTENT_TYPES.Comment.slug == content.type:
1027
                 related_active_content = content.parent
1033
                 related_active_content = content.parent
1028
             else:
1034
             else:
1029
                 related_active_content = content
1035
                 related_active_content = content
1075
     #         .filter(Content.content_id.in_(not_read_content_ids)) \
1081
     #         .filter(Content.content_id.in_(not_read_content_ids)) \
1076
     #         .order_by(desc(Content.updated))
1082
     #         .order_by(desc(Content.updated))
1077
     #
1083
     #
1078
-    #     if content_type != ContentType.Any:
1084
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
1079
     #         not_read_contents = not_read_contents.filter(
1085
     #         not_read_contents = not_read_contents.filter(
1080
     #             Content.type==content_type)
1086
     #             Content.type==content_type)
1081
     #     else:
1087
     #     else:
1082
     #         not_read_contents = not_read_contents.filter(
1088
     #         not_read_contents = not_read_contents.filter(
1083
-    #             Content.type!=ContentType.Folder)
1089
+    #             Content.type!=CONTENT_TYPES.Folder.slug)
1084
     #
1090
     #
1085
     #     if parent_id:
1091
     #     if parent_id:
1086
     #         not_read_contents = not_read_contents.filter(
1092
     #         not_read_contents = not_read_contents.filter(
1089
     #     result = []
1095
     #     result = []
1090
     #     for item in not_read_contents:
1096
     #     for item in not_read_contents:
1091
     #         new_item = None
1097
     #         new_item = None
1092
-    #         if ContentType.Comment == item.type:
1098
+    #         if CONTENT_TYPES.Comment.slug == item.type:
1093
     #             new_item = item.parent
1099
     #             new_item = item.parent
1094
     #         else:
1100
     #         else:
1095
     #             new_item = item
1101
     #             new_item = item
1331
                 self.mark_read(child, read_datetime=read_datetime,
1337
                 self.mark_read(child, read_datetime=read_datetime,
1332
                                do_flush=False)
1338
                                do_flush=False)
1333
 
1339
 
1334
-            if ContentType.Comment == content.type:
1340
+            if CONTENT_TYPES.Comment.slug == content.type:
1335
                 self.mark_read(content.parent, read_datetime=read_datetime,
1341
                 self.mark_read(content.parent, read_datetime=read_datetime,
1336
                                do_flush=False, recursive=False)
1342
                                do_flush=False, recursive=False)
1337
                 for comment in content.parent.get_comments():
1343
                 for comment in content.parent.get_comments():
1451
         return title_keyworded_items
1457
         return title_keyworded_items
1452
 
1458
 
1453
     def get_all_types(self) -> typing.List[ContentType]:
1459
     def get_all_types(self) -> typing.List[ContentType]:
1454
-        labels = ContentType.all()
1460
+        labels = CONTENT_TYPES.endpoint_allowed_types_slug()
1455
         content_types = []
1461
         content_types = []
1456
         for label in labels:
1462
         for label in labels:
1457
-            content_types.append(ContentType(label))
1463
+            content_types.append(CONTENT_TYPES.get_one_by_slug(label))
1458
 
1464
 
1459
-        return ContentType.sorted(content_types)
1465
+        return content_types
1460
 
1466
 
1461
     # TODO - G.M - 2018-07-24 - [Cleanup] Is this method already needed ?
1467
     # TODO - G.M - 2018-07-24 - [Cleanup] Is this method already needed ?
1462
     def exclude_unavailable(
1468
     def exclude_unavailable(

+ 10 - 10
backend/tracim_backend/lib/mail_notifier/notifier.py View File

19
 from tracim_backend.lib.utils.logger import logger
19
 from tracim_backend.lib.utils.logger import logger
20
 from tracim_backend.models import User
20
 from tracim_backend.models import User
21
 from tracim_backend.models.auth import User
21
 from tracim_backend.models.auth import User
22
+from tracim_backend.models.contents import CONTENT_TYPES
22
 from tracim_backend.models.data import ActionDescription
23
 from tracim_backend.models.data import ActionDescription
23
 from tracim_backend.models.data import Content
24
 from tracim_backend.models.data import Content
24
-from tracim_backend.models.data import ContentType
25
 from tracim_backend.models.data import UserRoleInWorkspace
25
 from tracim_backend.models.data import UserRoleInWorkspace
26
 from tracim_backend.lib.utils.translation import fake_translator as l_, \
26
 from tracim_backend.lib.utils.translation import fake_translator as l_, \
27
     fake_translator as _
27
     fake_translator as _
233
             config=self.config,
233
             config=self.config,
234
             show_archived=True,
234
             show_archived=True,
235
             show_deleted=True,
235
             show_deleted=True,
236
-        ).get_one(event_content_id, ContentType.Any)
237
-        main_content = content.parent if content.type == ContentType.Comment else content
236
+        ).get_one(event_content_id, CONTENT_TYPES.Any_SLUG)
237
+        main_content = content.parent if content.type == CONTENT_TYPES.Comment.slug else content
238
         notifiable_roles = WorkspaceApi(
238
         notifiable_roles = WorkspaceApi(
239
             current_user=user,
239
             current_user=user,
240
             session=self.session,
240
             session=self.session,
455
             content_text = content.description
455
             content_text = content.description
456
             call_to_action_text = l_('View online')
456
             call_to_action_text = l_('View online')
457
 
457
 
458
-            if ContentType.Thread == content.type:
458
+            if CONTENT_TYPES.Thread.slug == content.type:
459
                 call_to_action_text = l_('Answer')
459
                 call_to_action_text = l_('Answer')
460
                 content_intro = l_('<span id="content-intro-username">{}</span> started a thread entitled:').format(actor.display_name)
460
                 content_intro = l_('<span id="content-intro-username">{}</span> started a thread entitled:').format(actor.display_name)
461
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.label) + \
461
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.label) + \
462
                                content.get_last_comment_from(actor).description
462
                                content.get_last_comment_from(actor).description
463
 
463
 
464
-            elif ContentType.File == content.type:
464
+            elif CONTENT_TYPES.File.slug == content.type:
465
                 content_intro = l_('<span id="content-intro-username">{}</span> added a file entitled:').format(actor.display_name)
465
                 content_intro = l_('<span id="content-intro-username">{}</span> added a file entitled:').format(actor.display_name)
466
                 if content.description:
466
                 if content.description:
467
                     content_text = content.description
467
                     content_text = content.description
468
                 else:
468
                 else:
469
                     content_text = '<span id="content-body-only-title">{}</span>'.format(content.label)
469
                     content_text = '<span id="content-body-only-title">{}</span>'.format(content.label)
470
 
470
 
471
-            elif ContentType.Page == content.type:
471
+            elif CONTENT_TYPES.Page.slug == content.type:
472
                 content_intro = l_('<span id="content-intro-username">{}</span> added a page entitled:').format(actor.display_name)
472
                 content_intro = l_('<span id="content-intro-username">{}</span> added a page entitled:').format(actor.display_name)
473
                 content_text = '<span id="content-body-only-title">{}</span>'.format(content.label)
473
                 content_text = '<span id="content-body-only-title">{}</span>'.format(content.label)
474
 
474
 
476
             content_text = content.description
476
             content_text = content.description
477
             call_to_action_text = l_('View online')
477
             call_to_action_text = l_('View online')
478
 
478
 
479
-            if ContentType.File == content.type:
479
+            if CONTENT_TYPES.File.slug == content.type:
480
                 content_intro = l_('<span id="content-intro-username">{}</span> uploaded a new revision.').format(actor.display_name)
480
                 content_intro = l_('<span id="content-intro-username">{}</span> uploaded a new revision.').format(actor.display_name)
481
                 content_text = ''
481
                 content_text = ''
482
 
482
 
483
-            elif ContentType.Page == content.type:
483
+            elif CONTENT_TYPES.Page.slug == content.type:
484
                 content_intro = l_('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
484
                 content_intro = l_('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
485
                 previous_revision = content.get_previous_revision()
485
                 previous_revision = content.get_previous_revision()
486
                 title_diff = ''
486
                 title_diff = ''
490
                     title_diff + \
490
                     title_diff + \
491
                     htmldiff(previous_revision.description, content.description)
491
                     htmldiff(previous_revision.description, content.description)
492
 
492
 
493
-            elif ContentType.Thread == content.type:
493
+            elif CONTENT_TYPES.Thread.slug == content.type:
494
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name)
494
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name)
495
                 previous_revision = content.get_previous_revision()
495
                 previous_revision = content.get_previous_revision()
496
                 title_diff = ''
496
                 title_diff = ''
503
         elif ActionDescription.EDITION == action:
503
         elif ActionDescription.EDITION == action:
504
             call_to_action_text = l_('View online')
504
             call_to_action_text = l_('View online')
505
 
505
 
506
-            if ContentType.File == content.type:
506
+            if CONTENT_TYPES.File.slug == content.type:
507
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the file description.').format(actor.display_name)
507
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the file description.').format(actor.display_name)
508
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.get_label()) + \
508
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.get_label()) + \
509
                     content.description
509
                     content.description

+ 6 - 6
backend/tracim_backend/lib/utils/authorization.py View File

5
 from pyramid.interfaces import IAuthorizationPolicy
5
 from pyramid.interfaces import IAuthorizationPolicy
6
 from zope.interface import implementer
6
 from zope.interface import implementer
7
 
7
 
8
-from tracim_backend.models.contents import NewContentType
9
-from tracim_backend.models.context_models import ContentInContext
8
+from tracim_backend.models.contents import ContentType
9
+from tracim_backend.models.contents import CONTENT_TYPES
10
 
10
 
11
 try:
11
 try:
12
     from json.decoder import JSONDecodeError
12
     from json.decoder import JSONDecodeError
13
 except ImportError:  # python3.4
13
 except ImportError:  # python3.4
14
     JSONDecodeError = ValueError
14
     JSONDecodeError = ValueError
15
 
15
 
16
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
16
+from tracim_backend.models.contents import ContentType
17
 from tracim_backend.exceptions import InsufficientUserRoleInWorkspace
17
 from tracim_backend.exceptions import InsufficientUserRoleInWorkspace
18
 from tracim_backend.exceptions import ContentTypeNotAllowed
18
 from tracim_backend.exceptions import ContentTypeNotAllowed
19
 from tracim_backend.exceptions import InsufficientUserProfile
19
 from tracim_backend.exceptions import InsufficientUserProfile
133
     return decorator
133
     return decorator
134
 
134
 
135
 
135
 
136
-def require_content_types(content_types: typing.List['NewContentType']) -> typing.Callable:  # nopep8
136
+def require_content_types(content_types: typing.List['ContentType']) -> typing.Callable:  # nopep8
137
     """
137
     """
138
     Restricts access to specific file type or raise an exception.
138
     Restricts access to specific file type or raise an exception.
139
     Check role for candidate_workspace.
139
     Check role for candidate_workspace.
140
-    :param content_types: list of NewContentType object
140
+    :param content_types: list of ContentType object
141
     :return: decorator
141
     :return: decorator
142
     """
142
     """
143
     def decorator(func: typing.Callable) -> typing.Callable:
143
     def decorator(func: typing.Callable) -> typing.Callable:
144
         @functools.wraps(func)
144
         @functools.wraps(func)
145
         def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
145
         def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
146
             content = request.current_content
146
             content = request.current_content
147
-            current_content_type_slug = ContentType(content.type).slug
147
+            current_content_type_slug = CONTENT_TYPES.get_one_by_slug(content.type).slug
148
             content_types_slug = [content_type.slug for content_type in content_types]  # nopep8
148
             content_types_slug = [content_type.slug for content_type in content_types]  # nopep8
149
             if current_content_type_slug in content_types_slug:
149
             if current_content_type_slug in content_types_slug:
150
                 return func(self, context, request)
150
                 return func(self, context, request)

+ 3 - 3
backend/tracim_backend/lib/utils/request.py View File

15
 from tracim_backend.exceptions import UserDoesNotExist
15
 from tracim_backend.exceptions import UserDoesNotExist
16
 from tracim_backend.exceptions import WorkspaceNotFound
16
 from tracim_backend.exceptions import WorkspaceNotFound
17
 from tracim_backend.exceptions import ImmutableAttribute
17
 from tracim_backend.exceptions import ImmutableAttribute
18
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
18
+from tracim_backend.models.contents import CONTENT_TYPES
19
 from tracim_backend.lib.core.content import ContentApi
19
 from tracim_backend.lib.core.content import ContentApi
20
 from tracim_backend.lib.core.user import UserApi
20
 from tracim_backend.lib.core.user import UserApi
21
 from tracim_backend.lib.core.workspace import WorkspaceApi
21
 from tracim_backend.lib.core.workspace import WorkspaceApi
233
             )
233
             )
234
             comment = api.get_one(
234
             comment = api.get_one(
235
                 comment_id,
235
                 comment_id,
236
-                content_type=ContentType.Comment,
236
+                content_type=CONTENT_TYPES.Comment.slug,
237
                 workspace=workspace,
237
                 workspace=workspace,
238
                 parent=content,
238
                 parent=content,
239
             )
239
             )
271
                 session=request.dbsession,
271
                 session=request.dbsession,
272
                 config=request.registry.settings['CFG']
272
                 config=request.registry.settings['CFG']
273
             )
273
             )
274
-            content = api.get_one(content_id=content_id, workspace=workspace, content_type=ContentType.Any)  # nopep8
274
+            content = api.get_one(content_id=content_id, workspace=workspace, content_type=CONTENT_TYPES.Any_SLUG)  # nopep8
275
         except NoResultFound as exc:
275
         except NoResultFound as exc:
276
             raise ContentNotFound(
276
             raise ContentNotFound(
277
                 'Content {} does not exist '
277
                 'Content {} does not exist '

+ 7 - 5
backend/tracim_backend/lib/webdav/dav_provider.py View File

8
 from tracim_backend import CFG
8
 from tracim_backend import CFG
9
 from tracim_backend.lib.webdav.utils import transform_to_bdd, HistoryType, \
9
 from tracim_backend.lib.webdav.utils import transform_to_bdd, HistoryType, \
10
     SpecialFolderExtension
10
     SpecialFolderExtension
11
+from tracim_backend.models.contents import CONTENT_TYPES
11
 
12
 
12
 from wsgidav.dav_provider import DAVProvider
13
 from wsgidav.dav_provider import DAVProvider
13
 from wsgidav.lock_manager import LockManager
14
 from wsgidav.lock_manager import LockManager
19
 from tracim_backend.lib.core.workspace import WorkspaceApi
20
 from tracim_backend.lib.core.workspace import WorkspaceApi
20
 from tracim_backend.lib.webdav import resources
21
 from tracim_backend.lib.webdav import resources
21
 from tracim_backend.lib.webdav.utils import normpath
22
 from tracim_backend.lib.webdav.utils import normpath
22
-from tracim_backend.models.data import ContentType, Content, Workspace
23
+from tracim_backend.models.data import Content
24
+from tracim_backend.models.data import Workspace
23
 
25
 
24
 
26
 
25
 class Provider(DAVProvider):
27
 class Provider(DAVProvider):
174
             content_revision = content_api.get_one_revision(revision_id)
176
             content_revision = content_api.get_one_revision(revision_id)
175
             content = self.get_content_from_revision(content_revision, content_api)
177
             content = self.get_content_from_revision(content_revision, content_api)
176
 
178
 
177
-            if content.type == ContentType.File:
179
+            if content.type == CONTENT_TYPES.File.slug:
178
                 return resources.HistoryFileResource(
180
                 return resources.HistoryFileResource(
179
                     path=path,
181
                     path=path,
180
                     environ=environ,
182
                     environ=environ,
198
 
200
 
199
         if content is None:
201
         if content is None:
200
             return None
202
             return None
201
-        if content.type == ContentType.Folder:
203
+        if content.type == CONTENT_TYPES.Folder.slug:
202
             return resources.FolderResource(
204
             return resources.FolderResource(
203
                 path=path,
205
                 path=path,
204
                 environ=environ,
206
                 environ=environ,
207
                 session=session,
209
                 session=session,
208
                 user=user,
210
                 user=user,
209
             )
211
             )
210
-        elif content.type == ContentType.File:
212
+        elif content.type == CONTENT_TYPES.File.slug:
211
             return resources.FileResource(
213
             return resources.FileResource(
212
                 path=path,
214
                 path=path,
213
                 environ=environ,
215
                 environ=environ,
356
 
358
 
357
     def get_content_from_revision(self, revision: ContentRevisionRO, api: ContentApi) -> Content:
359
     def get_content_from_revision(self, revision: ContentRevisionRO, api: ContentApi) -> Content:
358
         try:
360
         try:
359
-            return api.get_one(revision.content_id, ContentType.Any)
361
+            return api.get_one(revision.content_id, CONTENT_TYPES.Any_SLUG)
360
         except NoResultFound:
362
         except NoResultFound:
361
             return None
363
             return None
362
 
364
 

+ 3 - 2
backend/tracim_backend/lib/webdav/design.py View File

1
 #coding: utf8
1
 #coding: utf8
2
 from datetime import datetime
2
 from datetime import datetime
3
 
3
 
4
+from tracim_backend.models.contents import CONTENT_TYPES
4
 from tracim_backend.models.data import VirtualEvent
5
 from tracim_backend.models.data import VirtualEvent
5
-from tracim_backend.models.data import ContentType
6
 from tracim_backend.models import data
6
 from tracim_backend.models import data
7
 
7
 
8
 # FIXME: fix temporaire ...
8
 # FIXME: fix temporaire ...
237
 
237
 
238
     return page
238
     return page
239
 
239
 
240
+
240
 def designThread(content: data.Content, content_revision: data.ContentRevisionRO, comments) -> str:
241
 def designThread(content: data.Content, content_revision: data.ContentRevisionRO, comments) -> str:
241
         hist = content.get_history(drop_empty_revision=False)
242
         hist = content.get_history(drop_empty_revision=False)
242
 
243
 
248
         disc = ''
249
         disc = ''
249
         participants = {}
250
         participants = {}
250
         for t in allT:
251
         for t in allT:
251
-            if t.type == ContentType.Comment:
252
+            if t.type == CONTENT_TYPES.Comment.slug:
252
                 disc += '''
253
                 disc += '''
253
                     <div class="row comment comment-row">
254
                     <div class="row comment comment-row">
254
                         <i class="fa fa-comment-o comment-icon"></i>
255
                         <i class="fa fa-comment-o comment-icon"></i>

+ 37 - 34
backend/tracim_backend/lib/webdav/resources.py View File

19
     FakeFileStream
19
     FakeFileStream
20
 from tracim_backend.lib.webdav.utils import transform_to_bdd
20
 from tracim_backend.lib.webdav.utils import transform_to_bdd
21
 from tracim_backend.lib.core.workspace import WorkspaceApi
21
 from tracim_backend.lib.core.workspace import WorkspaceApi
22
+from tracim_backend.models.contents import CONTENT_TYPES
22
 from tracim_backend.models.data import User, ContentRevisionRO
23
 from tracim_backend.models.data import User, ContentRevisionRO
23
 from tracim_backend.models.data import Workspace
24
 from tracim_backend.models.data import Workspace
24
-from tracim_backend.models.data import Content, ActionDescription
25
-from tracim_backend.models.data import ContentType
25
+from tracim_backend.models.data import Content
26
+from tracim_backend.models.data import ActionDescription
26
 from tracim_backend.lib.webdav.design import designThread, designPage
27
 from tracim_backend.lib.webdav.design import designThread, designPage
27
 
28
 
28
 from wsgidav import compat
29
 from wsgidav import compat
236
 
237
 
237
         for content in children:
238
         for content in children:
238
             # the purpose is to display .history only if there's at least one content's type that has a history
239
             # the purpose is to display .history only if there's at least one content's type that has a history
239
-            if content.type != ContentType.Folder:
240
+            if content.type != CONTENT_TYPES.Folder.slug:
240
                 self._file_count += 1
241
                 self._file_count += 1
241
             retlist.append(content.get_label_as_file())
242
             retlist.append(content.get_label_as_file())
242
 
243
 
288
             raise DAVError(HTTP_FORBIDDEN)
289
             raise DAVError(HTTP_FORBIDDEN)
289
 
290
 
290
         folder = self.content_api.create(
291
         folder = self.content_api.create(
291
-            content_type=ContentType.Folder,
292
+            content_type_slug=CONTENT_TYPES.Folder.slug,
292
             workspace=self.workspace,
293
             workspace=self.workspace,
293
             label=label,
294
             label=label,
294
             parent=self.content
295
             parent=self.content
331
     def getMemberList(self) -> [_DAVResource]:
332
     def getMemberList(self) -> [_DAVResource]:
332
         members = []
333
         members = []
333
 
334
 
334
-        children = self.content_api.get_all(False, ContentType.Any, self.workspace)
335
+        children = self.content_api.get_all(False, CONTENT_TYPES.Any_SLUG, self.workspace)
335
 
336
 
336
         for content in children:
337
         for content in children:
337
             content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
338
             content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
338
 
339
 
339
-            if content.type == ContentType.Folder:
340
+            if content.type == CONTENT_TYPES.Folder.slug:
340
                 members.append(
341
                 members.append(
341
                     FolderResource(
342
                     FolderResource(
342
                         path=content_path,
343
                         path=content_path,
347
                         session=self.session,
348
                         session=self.session,
348
                     )
349
                     )
349
                 )
350
                 )
350
-            elif content.type == ContentType.File:
351
+            elif content.type == CONTENT_TYPES.File.slug:
351
                 self._file_count += 1
352
                 self._file_count += 1
352
                 members.append(
353
                 members.append(
353
                     FileResource(
354
                     FileResource(
553
         )
554
         )
554
         visible_children = content_api.get_all(
555
         visible_children = content_api.get_all(
555
             self.content.content_id,
556
             self.content.content_id,
556
-            ContentType.Any,
557
+            CONTENT_TYPES.Any_SLUG,
557
             self.workspace,
558
             self.workspace,
558
         )
559
         )
559
 
560
 
561
             content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
562
             content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
562
 
563
 
563
             try:
564
             try:
564
-                if content.type == ContentType.Folder:
565
+                if content.type == CONTENT_TYPES.Folder.slug:
565
                     members.append(
566
                     members.append(
566
                         FolderResource(
567
                         FolderResource(
567
                             path=content_path,
568
                             path=content_path,
572
                             session=self.session,
573
                             session=self.session,
573
                         )
574
                         )
574
                     )
575
                     )
575
-                elif content.type == ContentType.File:
576
+                elif content.type == CONTENT_TYPES.File.slug:
576
                     self._file_count += 1
577
                     self._file_count += 1
577
                     members.append(
578
                     members.append(
578
                         FileResource(
579
                         FileResource(
592
                             user=self.user,
593
                             user=self.user,
593
                             session=self.session,
594
                             session=self.session,
594
                         ))
595
                         ))
595
-            except Exception as exc:
596
-                logger.exception(
597
-                    'Unable to construct member {}'.format(
598
-                        content_path,
599
-                    ),
600
-                    exc_info=True,
601
-                )
596
+            except NotImplementedError as exc:
597
+                pass
598
+            # except Exception as exc:
599
+            #     logger.exception(
600
+            #         'Unable to construct member {}'.format(
601
+            #             content_path,
602
+            #         ),
603
+            #         exc_info=True,
604
+            #     )
602
 
605
 
603
         if self._file_count > 0 and self.provider.show_history():
606
         if self._file_count > 0 and self.provider.show_history():
604
             members.append(
607
             members.append(
708
         ret = []
711
         ret = []
709
 
712
 
710
         content_id = None if self.content is None else self.content.id
713
         content_id = None if self.content is None else self.content.id
711
-        for content in self.content_api.get_all(content_id, ContentType.Any, self.workspace):
714
+        for content in self.content_api.get_all(content_id, CONTENT_TYPES.Any_SLUG, self.workspace):
712
             if (self._is_archived and content.is_archived or
715
             if (self._is_archived and content.is_archived or
713
                 self._is_deleted and content.is_deleted or
716
                 self._is_deleted and content.is_deleted or
714
                 not (content.is_archived or self._is_archived or content.is_deleted or self._is_deleted))\
717
                 not (content.is_archived or self._is_archived or content.is_deleted or self._is_deleted))\
715
-                    and content.type != ContentType.Folder:
718
+                    and content.type != CONTENT_TYPES.Folder.slug:
716
                 ret.append(content.get_label_as_file())
719
                 ret.append(content.get_label_as_file())
717
 
720
 
718
         return ret
721
         return ret
741
         if self.content:
744
         if self.content:
742
             children = self.content.children
745
             children = self.content.children
743
         else:
746
         else:
744
-            children = self.content_api.get_all(False, ContentType.Any, self.workspace)
747
+            children = self.content_api.get_all(False, CONTENT_TYPES.Any_SLUG, self.workspace)
745
         
748
         
746
         for content in children:
749
         for content in children:
747
             if content.is_archived == self._is_archived and content.is_deleted == self._is_deleted:
750
             if content.is_archived == self._is_archived and content.is_deleted == self._is_deleted:
812
         if self.content:
815
         if self.content:
813
             children = self.content.children
816
             children = self.content.children
814
         else:
817
         else:
815
-            children = self.content_api.get_all(False, ContentType.Any, self.workspace)
818
+            children = self.content_api.get_all(False, CONTENT_TYPES.Any_SLUG, self.workspace)
816
 
819
 
817
         for content in children:
820
         for content in children:
818
             if content.is_deleted:
821
             if content.is_deleted:
819
                 retlist.append(content.get_label_as_file())
822
                 retlist.append(content.get_label_as_file())
820
 
823
 
821
-                if content.type != ContentType.Folder:
824
+                if content.type != CONTENT_TYPES.Folder.slug:
822
                     self._file_count += 1
825
                     self._file_count += 1
823
 
826
 
824
         return retlist
827
         return retlist
829
         if self.content:
832
         if self.content:
830
             children = self.content.children
833
             children = self.content.children
831
         else:
834
         else:
832
-            children = self.content_api.get_all(False, ContentType.Any, self.workspace)
835
+            children = self.content_api.get_all(False, CONTENT_TYPES.Any_SLUG, self.workspace)
833
 
836
 
834
         for content in children:
837
         for content in children:
835
             if content.is_deleted:
838
             if content.is_deleted:
836
                 content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
839
                 content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
837
 
840
 
838
-                if content.type == ContentType.Folder:
841
+                if content.type == CONTENT_TYPES.Folder.slug:
839
                     members.append(
842
                     members.append(
840
                         FolderResource(
843
                         FolderResource(
841
                             content_path,
844
                             content_path,
845
                             user=self.user,
848
                             user=self.user,
846
                             session=self.session,
849
                             session=self.session,
847
                         ))
850
                         ))
848
-                elif content.type == ContentType.File:
851
+                elif content.type == CONTENT_TYPES.File.slug:
849
                     self._file_count += 1
852
                     self._file_count += 1
850
                     members.append(
853
                     members.append(
851
                         FileResource(
854
                         FileResource(
936
         retlist = []
939
         retlist = []
937
 
940
 
938
         for content in self.content_api.get_all_with_filter(
941
         for content in self.content_api.get_all_with_filter(
939
-                self.content if self.content is None else self.content.id, ContentType.Any):
942
+                self.content if self.content is None else self.content.id, CONTENT_TYPES.Any_SLUG):
940
             retlist.append(content.get_label_as_file())
943
             retlist.append(content.get_label_as_file())
941
 
944
 
942
-            if content.type != ContentType.Folder:
945
+            if content.type != CONTENT_TYPES.Folder.slug:
943
                 self._file_count += 1
946
                 self._file_count += 1
944
 
947
 
945
         return retlist
948
         return retlist
950
         if self.content:
953
         if self.content:
951
             children = self.content.children
954
             children = self.content.children
952
         else:
955
         else:
953
-            children = self.content_api.get_all(False, ContentType.Any, self.workspace)
956
+            children = self.content_api.get_all(False, CONTENT_TYPES.Any_SLUG, self.workspace)
954
 
957
 
955
         for content in children:
958
         for content in children:
956
             if content.is_archived:
959
             if content.is_archived:
957
                 content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
960
                 content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
958
 
961
 
959
-                if content.type == ContentType.Folder:
962
+                if content.type == CONTENT_TYPES.Folder.slug:
960
                     members.append(
963
                     members.append(
961
                         FolderResource(
964
                         FolderResource(
962
                             content_path,
965
                             content_path,
966
                             user=self.user,
969
                             user=self.user,
967
                             session=self.session,
970
                             session=self.session,
968
                         ))
971
                         ))
969
-                elif content.type == ContentType.File:
972
+                elif content.type == CONTENT_TYPES.File.slug:
970
                     self._file_count += 1
973
                     self._file_count += 1
971
                     members.append(
974
                     members.append(
972
                         FileResource(
975
                         FileResource(
1053
 
1056
 
1054
         left_side = '%s/(%d - %s) ' % (self.path, revision.revision_id, revision.revision_type)
1057
         left_side = '%s/(%d - %s) ' % (self.path, revision.revision_id, revision.revision_type)
1055
 
1058
 
1056
-        if self.content.type == ContentType.File:
1059
+        if self.content.type == CONTENT_TYPES.File.slug:
1057
             return HistoryFileResource(
1060
             return HistoryFileResource(
1058
                 path='%s%s' % (left_side, transform_to_display(revision.file_name)),
1061
                 path='%s%s' % (left_side, transform_to_display(revision.file_name)),
1059
                 environ=self.environ,
1062
                 environ=self.environ,
1079
 
1082
 
1080
             left_side = '%s/(%d - %s) ' % (self.path, content.revision_id, content.revision_type)
1083
             left_side = '%s/(%d - %s) ' % (self.path, content.revision_id, content.revision_type)
1081
 
1084
 
1082
-            if self.content.type == ContentType.File:
1085
+            if self.content.type == CONTENT_TYPES.File.slug:
1083
                 members.append(HistoryFileResource(
1086
                 members.append(HistoryFileResource(
1084
                     path='%s%s' % (left_side, transform_to_display(content.file_name)),
1087
                     path='%s%s' % (left_side, transform_to_display(content.file_name)),
1085
                     environ=self.environ,
1088
                     environ=self.environ,
1425
         return filestream
1428
         return filestream
1426
 
1429
 
1427
     def design(self):
1430
     def design(self):
1428
-        if self.content.type == ContentType.Page:
1431
+        if self.content.type == CONTENT_TYPES.Page.slug:
1429
             return designPage(self.content, self.content_revision)
1432
             return designPage(self.content, self.content_revision)
1430
         else:
1433
         else:
1431
             return designThread(
1434
             return designThread(
1432
                 self.content,
1435
                 self.content,
1433
                 self.content_revision,
1436
                 self.content_revision,
1434
-                self.content_api.get_all(self.content.content_id, ContentType.Comment)
1437
+                self.content_api.get_all(self.content.content_id, CONTENT_TYPES.Comment.slug)
1435
             )
1438
             )
1436
 
1439
 
1437
 
1440
 

+ 5 - 3
backend/tracim_backend/lib/webdav/utils.py View File

4
 from os.path import normpath as base_normpath
4
 from os.path import normpath as base_normpath
5
 
5
 
6
 from sqlalchemy.orm import Session
6
 from sqlalchemy.orm import Session
7
+from tracim_backend.models.contents import CONTENT_TYPES
7
 from wsgidav import util
8
 from wsgidav import util
8
 from wsgidav import compat
9
 from wsgidav import compat
9
 
10
 
10
 from tracim_backend.lib.core.content import ContentApi
11
 from tracim_backend.lib.core.content import ContentApi
11
-from tracim_backend.models.data import Workspace, Content, ContentType, \
12
-    ActionDescription
12
+from tracim_backend.models.data import Workspace
13
+from tracim_backend.models.data import Content
14
+from tracim_backend.models.data import ActionDescription
13
 from tracim_backend.models.revision_protection import new_revision
15
 from tracim_backend.models.revision_protection import new_revision
14
 
16
 
15
 
17
 
177
 
179
 
178
         file = self._api.create(
180
         file = self._api.create(
179
             filename=self._file_name,
181
             filename=self._file_name,
180
-            content_type=ContentType.File,
182
+            content_type_slug=CONTENT_TYPES.File.slug,
181
             workspace=self._workspace,
183
             workspace=self._workspace,
182
             parent=self._parent,
184
             parent=self._parent,
183
             is_temporary=is_temporary
185
             is_temporary=is_temporary

+ 57 - 101
backend/tracim_backend/models/contents.py View File

106
 # ContentType
106
 # ContentType
107
 
107
 
108
 
108
 
109
-class NewContentType(object):
109
+class ContentType(object):
110
     """
110
     """
111
     Future ContentType object class
111
     Future ContentType object class
112
     """
112
     """
118
             label: str,
118
             label: str,
119
             creation_label: str,
119
             creation_label: str,
120
             available_statuses: typing.List[ContentStatus],
120
             available_statuses: typing.List[ContentStatus],
121
-
121
+            slug_alias: typing.List[str] = None,
122
     ):
122
     ):
123
         self.slug = slug
123
         self.slug = slug
124
         self.fa_icon = fa_icon
124
         self.fa_icon = fa_icon
126
         self.label = label
126
         self.label = label
127
         self.creation_label = creation_label
127
         self.creation_label = creation_label
128
         self.available_statuses = available_statuses
128
         self.available_statuses = available_statuses
129
+        self.slug_alias = slug_alias
129
 
130
 
130
 
131
 
131
-thread_type = NewContentType(
132
+thread_type = ContentType(
132
     slug='thread',
133
     slug='thread',
133
     fa_icon=thread.fa_icon,
134
     fa_icon=thread.fa_icon,
134
     hexcolor=thread.hexcolor,
135
     hexcolor=thread.hexcolor,
137
     available_statuses=CONTENT_STATUS.allowed(),
138
     available_statuses=CONTENT_STATUS.allowed(),
138
 )
139
 )
139
 
140
 
140
-file_type = NewContentType(
141
+file_type = ContentType(
141
     slug='file',
142
     slug='file',
142
     fa_icon=_file.fa_icon,
143
     fa_icon=_file.fa_icon,
143
     hexcolor=_file.hexcolor,
144
     hexcolor=_file.hexcolor,
146
     available_statuses=CONTENT_STATUS.allowed(),
147
     available_statuses=CONTENT_STATUS.allowed(),
147
 )
148
 )
148
 
149
 
149
-markdownpluspage_type = NewContentType(
150
+markdownpluspage_type = ContentType(
150
     slug='markdownpage',
151
     slug='markdownpage',
151
     fa_icon=markdownpluspage.fa_icon,
152
     fa_icon=markdownpluspage.fa_icon,
152
     hexcolor=markdownpluspage.hexcolor,
153
     hexcolor=markdownpluspage.hexcolor,
155
     available_statuses=CONTENT_STATUS.allowed(),
156
     available_statuses=CONTENT_STATUS.allowed(),
156
 )
157
 )
157
 
158
 
158
-html_documents_type = NewContentType(
159
+html_documents_type = ContentType(
159
     slug='html-documents',
160
     slug='html-documents',
160
     fa_icon=html_documents.fa_icon,
161
     fa_icon=html_documents.fa_icon,
161
     hexcolor=html_documents.hexcolor,
162
     hexcolor=html_documents.hexcolor,
162
     label='Text Document',
163
     label='Text Document',
163
     creation_label='Write a document',
164
     creation_label='Write a document',
164
     available_statuses=CONTENT_STATUS.allowed(),
165
     available_statuses=CONTENT_STATUS.allowed(),
166
+    slug_alias=['page']
165
 )
167
 )
166
 
168
 
167
 # TODO - G.M - 31-05-2018 - Set Better folder params
169
 # TODO - G.M - 31-05-2018 - Set Better folder params
168
-folder_type = NewContentType(
170
+folder_type = ContentType(
169
     slug='folder',
171
     slug='folder',
170
     fa_icon=thread.fa_icon,
172
     fa_icon=thread.fa_icon,
171
     hexcolor=thread.hexcolor,
173
     hexcolor=thread.hexcolor,
174
     available_statuses=CONTENT_STATUS.allowed(),
176
     available_statuses=CONTENT_STATUS.allowed(),
175
 )
177
 )
176
 
178
 
177
-CONTENT_DEFAULT_TYPE = [
178
-    thread_type,
179
-    file_type,
180
-    markdownpluspage_type,
181
-    html_documents_type,
182
-    folder_type,
183
-]
184
 
179
 
185
 # TODO - G.M - 31-05-2018 - Set Better Event params
180
 # TODO - G.M - 31-05-2018 - Set Better Event params
186
-event_type = NewContentType(
181
+event_type = ContentType(
187
     slug='event',
182
     slug='event',
188
     fa_icon=thread.fa_icon,
183
     fa_icon=thread.fa_icon,
189
     hexcolor=thread.hexcolor,
184
     hexcolor=thread.hexcolor,
193
 )
188
 )
194
 
189
 
195
 # TODO - G.M - 31-05-2018 - Set Better Event params
190
 # TODO - G.M - 31-05-2018 - Set Better Event params
196
-comment_type = NewContentType(
191
+comment_type = ContentType(
197
     slug='comment',
192
     slug='comment',
198
     fa_icon=thread.fa_icon,
193
     fa_icon=thread.fa_icon,
199
     hexcolor=thread.hexcolor,
194
     hexcolor=thread.hexcolor,
202
     available_statuses=CONTENT_STATUS.allowed(),
197
     available_statuses=CONTENT_STATUS.allowed(),
203
 )
198
 )
204
 
199
 
205
-CONTENT_DEFAULT_TYPE_SPECIAL = [
206
-    event_type,
207
-    comment_type,
208
-]
209
-
210
-ALL_CONTENTS_DEFAULT_TYPES = CONTENT_DEFAULT_TYPE + CONTENT_DEFAULT_TYPE_SPECIAL
211
-
212
 
200
 
213
-class ContentTypeLegacy(NewContentType):
201
+class ContentTypeList(object):
214
     """
202
     """
215
-    Temporary remplacement object for Legacy ContentType Object
203
+    ContentType List
216
     """
204
     """
217
-
218
-    # special type
219
-    Any = 'any'
220
-    Folder = 'folder'
221
-    Event = 'event'
222
-    Comment = 'comment'
223
-
224
-    File = file_type.slug
225
-    Thread = thread_type.slug
226
-    Page = html_documents_type.slug
227
-    PageLegacy = 'page'
228
-    MarkdownPage = markdownpluspage_type.slug
229
-
230
-    def __init__(self, slug: str):
231
-        if slug == 'page':
232
-            slug = ContentTypeLegacy.Page
233
-        for content_type in ALL_CONTENTS_DEFAULT_TYPES:
234
-            if slug == content_type.slug:
235
-                super(ContentTypeLegacy, self).__init__(
236
-                    slug=content_type.slug,
237
-                    fa_icon=content_type.fa_icon,
238
-                    hexcolor=content_type.hexcolor,
239
-                    label=content_type.label,
240
-                    creation_label=content_type.creation_label,
241
-                    available_statuses=content_type.available_statuses
242
-                )
243
-                return
205
+    Any_SLUG = 'any'
206
+    Folder = folder_type
207
+    Comment = comment_type
208
+    Event = event_type
209
+    File = file_type
210
+    Page = html_documents_type
211
+    Thread = thread_type
212
+
213
+    def __init__(self, extend_content_status: typing.List[ContentType]):
214
+        self._content_types = [self.Folder]
215
+        self._content_types.extend(extend_content_status)
216
+        self._special_contents_types = [self.Comment]
217
+        self._extra_slugs = [self.Any_SLUG]
218
+
219
+    def get_one_by_slug(self, slug: str):
220
+        content_types = self._content_types.copy()
221
+        content_types.extend(self._special_contents_types)
222
+        for item in content_types:
223
+            if item.slug == slug or (item.slug_alias and slug in item.slug_alias):  # nopep8
224
+                return item
244
         raise ContentTypeNotExist()
225
         raise ContentTypeNotExist()
245
 
226
 
246
-    def get_slug_aliases(self) -> typing.List[str]:
247
-        """
248
-        Get all slug aliases of a content,
249
-        useful for legacy code convertion
250
-        """
251
-        # TODO - G.M - 2018-07-05 - Remove this legacy compat code
252
-        # when possible.
253
-        page_alias = [self.Page, self.PageLegacy]
254
-        if self.slug in page_alias:
255
-            return page_alias
256
-        else:
257
-            return [self.slug]
258
-
259
-    @classmethod
260
-    def all(cls) -> typing.List[str]:
261
-        return cls.allowed_types()
262
-
263
-    @classmethod
264
-    def allowed_types(cls) -> typing.List[str]:
265
-        contents_types = [status.slug for status in ALL_CONTENTS_DEFAULT_TYPES]
266
-        return contents_types
267
-
268
-    @classmethod
269
-    def allowed_type_values(cls) -> typing.List[str]:
270
-        """
271
-        All content type slug + special values like any
272
-        """
273
-        content_types = cls.allowed_types()
274
-        content_types.append(ContentTypeLegacy.Any)
275
-        return content_types
276
-
277
-    @classmethod
278
-    def allowed_types_for_folding(cls):
279
-        # This method is used for showing only "main"
280
-        # types in the left-side treeview
281
-        contents_types = [status.slug for status in CONTENT_DEFAULT_TYPE]
282
-        return contents_types
283
-
284
-    # TODO - G.M - 30-05-2018 - This method don't do anything.
285
-    @classmethod
286
-    def sorted(cls, types: ['ContentType']) -> ['ContentType']:
287
-        return types
288
-
289
-    @property
290
-    def id(self):
291
-        return self.slug
292
-
293
-    def toDict(self):
294
-        raise NotImplementedError()
227
+    def endpoint_allowed_types_slug(self) -> typing.List[str]:
228
+        allowed_type_slug = [contents_type.slug for contents_type in self._content_types]  # nopep8
229
+        return allowed_type_slug
230
+
231
+    def query_allowed_types_slugs(self) -> typing.List[str]:
232
+        allowed_types_slug = []
233
+        for content_type in self._content_types:
234
+            allowed_types_slug.append(content_type.slug)
235
+            if content_type.slug_alias:
236
+                allowed_types_slug.extend(content_type.slug_alias)
237
+        for content_type in self._special_contents_types:
238
+            allowed_types_slug.append(content_type.slug)
239
+        allowed_types_slug.extend(self._extra_slugs)
240
+        return allowed_types_slug
241
+
242
+
243
+CONTENT_TYPES = ContentTypeList(
244
+    [
245
+        thread_type,
246
+        file_type,
247
+        markdownpluspage_type,
248
+        html_documents_type,
249
+    ]
250
+)

+ 3 - 7
backend/tracim_backend/models/context_models.py View File

16
 from tracim_backend.models.roles import WorkspaceRoles
16
 from tracim_backend.models.roles import WorkspaceRoles
17
 from tracim_backend.models.workspace_menu_entries import default_workspace_menu_entry
17
 from tracim_backend.models.workspace_menu_entries import default_workspace_menu_entry
18
 from tracim_backend.models.workspace_menu_entries import WorkspaceMenuEntry
18
 from tracim_backend.models.workspace_menu_entries import WorkspaceMenuEntry
19
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
19
+from tracim_backend.models.contents import CONTENT_TYPES
20
 
20
 
21
 
21
 
22
 class PreviewAllowedDim(object):
22
 class PreviewAllowedDim(object):
578
 
578
 
579
     @property
579
     @property
580
     def content_type(self) -> str:
580
     def content_type(self) -> str:
581
-        content_type = ContentType(self.content.type)
581
+        content_type = CONTENT_TYPES.get_one_by_slug(self.content.type)
582
         return content_type.slug
582
         return content_type.slug
583
 
583
 
584
     @property
584
     @property
690
 
690
 
691
     @property
691
     @property
692
     def content_type(self) -> str:
692
     def content_type(self) -> str:
693
-        content_type = ContentType(self.revision.type)
694
-        if content_type:
695
-            return content_type.slug
696
-        else:
697
-            return None
693
+        return CONTENT_TYPES.get_one_by_slug(self.revision.type).slug
698
 
694
 
699
     @property
695
     @property
700
     def sub_content_types(self) -> typing.List[str]:
696
     def sub_content_types(self) -> typing.List[str]:

+ 21 - 22
backend/tracim_backend/models/data.py View File

96
 
96
 
97
     def get_allowed_content_types(self):
97
     def get_allowed_content_types(self):
98
         # @see Content.get_allowed_content_types()
98
         # @see Content.get_allowed_content_types()
99
-        return [ContentType('folder')]
99
+        return CONTENT_TYPES.endpoint_allowed_types_slug()
100
 
100
 
101
     def get_valid_children(
101
     def get_valid_children(
102
             self,
102
             self,
293
 
293
 
294
 from tracim_backend.models.contents import CONTENT_STATUS
294
 from tracim_backend.models.contents import CONTENT_STATUS
295
 from tracim_backend.models.contents import ContentStatus
295
 from tracim_backend.models.contents import ContentStatus
296
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
296
+from tracim_backend.models.contents import CONTENT_TYPES
297
 # TODO - G.M - 30-05-2018 - Drop this old code when whe are sure nothing
297
 # TODO - G.M - 30-05-2018 - Drop this old code when whe are sure nothing
298
 # is lost .
298
 # is lost .
299
 
299
 
352
 #         # self.icon = ContentStatus._ICONS[id]
352
 #         # self.icon = ContentStatus._ICONS[id]
353
 #         # self.css = ContentStatus._CSS[id]
353
 #         # self.css = ContentStatus._CSS[id]
354
 #         #
354
 #         #
355
-#         # if type==ContentType.Thread:
355
+#         # if type==CONTENT_TYPES.Thread.slug:
356
 #         #     self.label = ContentStatus._LABELS_THREAD[id]
356
 #         #     self.label = ContentStatus._LABELS_THREAD[id]
357
-#         # elif type==ContentType.File:
357
+#         # elif type==CONTENT_TYPES.File.slug:
358
 #         #     self.label = ContentStatus._LABELS_FILE[id]
358
 #         #     self.label = ContentStatus._LABELS_FILE[id]
359
 #         # else:
359
 #         # else:
360
 #         #     self.label = ContentStatus._LABELS[id]
360
 #         #     self.label = ContentStatus._LABELS[id]
500
 #     #     # TODO - DYNDATATYPE - D.A. - 2014-12-02
500
 #     #     # TODO - DYNDATATYPE - D.A. - 2014-12-02
501
 #     #     # Make this code dynamic loading data types
501
 #     #     # Make this code dynamic loading data types
502
 #     #
502
 #     #
503
-#     #     if content.type==ContentType.Folder:
503
+#     #     if content.type==CONTENT_TYPES.Folder.slug:
504
 #     #         return '/workspaces/{}/folders/{}'.format(content.workspace_id, content.content_id)
504
 #     #         return '/workspaces/{}/folders/{}'.format(content.workspace_id, content.content_id)
505
-#     #     elif content.type==ContentType.File:
505
+#     #     elif content.type==CONTENT_TYPES.File.slug:
506
 #     #         return '/workspaces/{}/folders/{}/files/{}'.format(content.workspace_id, content.parent_id, content.content_id)
506
 #     #         return '/workspaces/{}/folders/{}/files/{}'.format(content.workspace_id, content.parent_id, content.content_id)
507
-#     #     elif content.type==ContentType.Thread:
507
+#     #     elif content.type==CONTENT_TYPES.Thread.slug:
508
 #     #         return '/workspaces/{}/folders/{}/threads/{}'.format(content.workspace_id, content.parent_id, content.content_id)
508
 #     #         return '/workspaces/{}/folders/{}/threads/{}'.format(content.workspace_id, content.parent_id, content.content_id)
509
-#     #     elif content.type==ContentType.Page:
509
+#     #     elif content.type==CONTENT_TYPES.Page.slug:
510
 #     #         return '/workspaces/{}/folders/{}/pages/{}'.format(content.workspace_id, content.parent_id, content.content_id)
510
 #     #         return '/workspaces/{}/folders/{}/pages/{}'.format(content.workspace_id, content.parent_id, content.content_id)
511
 #     #
511
 #     #
512
 #     # @classmethod
512
 #     # @classmethod
545
 
545
 
546
     @classmethod
546
     @classmethod
547
     def check_properties(cls, item):
547
     def check_properties(cls, item):
548
-        if item.type == ContentType.Folder:
548
+        if item.type == CONTENT_TYPES.Folder.slug:
549
             properties = item.properties
549
             properties = item.properties
550
             if 'allowed_content' not in properties.keys():
550
             if 'allowed_content' not in properties.keys():
551
                 return False
551
                 return False
559
                 return False
559
                 return False
560
             return True
560
             return True
561
 
561
 
562
-        if item.type == ContentType.Event:
562
+        if item.type == CONTENT_TYPES.Event.slug:
563
             properties = item.properties
563
             properties = item.properties
564
             if 'name' not in properties.keys():
564
             if 'name' not in properties.keys():
565
                 return False
565
                 return False
573
 
573
 
574
         # TODO - G.M - 15-03-2018 - Choose only correct Content-type for origin
574
         # TODO - G.M - 15-03-2018 - Choose only correct Content-type for origin
575
         # Only content who can be copied need this
575
         # Only content who can be copied need this
576
-        if item.type == ContentType.Any:
576
+        if item.type == CONTENT_TYPES.Any_SLUG:
577
             properties = item.properties
577
             properties = item.properties
578
             if 'origin' in properties.keys():
578
             if 'origin' in properties.keys():
579
                 return True
579
                 return True
581
 
581
 
582
     @classmethod
582
     @classmethod
583
     def reset_properties(cls, item):
583
     def reset_properties(cls, item):
584
-        if item.type == ContentType.Folder:
584
+        if item.type == CONTENT_TYPES.Folder.slug:
585
             item.properties = DEFAULT_PROPERTIES
585
             item.properties = DEFAULT_PROPERTIES
586
             return
586
             return
587
 
587
 
780
     def get_label_as_file(self):
780
     def get_label_as_file(self):
781
         file_extension = self.file_extension or ''
781
         file_extension = self.file_extension or ''
782
 
782
 
783
-        if self.type == ContentType.Thread:
783
+        if self.type == CONTENT_TYPES.Thread.slug:
784
             file_extension = '.html'
784
             file_extension = '.html'
785
-        elif self.type == ContentType.Page:
785
+        elif self.type == CONTENT_TYPES.Page.slug:
786
             file_extension = '.html'
786
             file_extension = '.html'
787
 
787
 
788
         return '{0}{1}'.format(
788
         return '{0}{1}'.format(
1228
         return format_timedelta(delta_from_datetime - datetime_object,
1228
         return format_timedelta(delta_from_datetime - datetime_object,
1229
                                 locale=get_locale())
1229
                                 locale=get_locale())
1230
 
1230
 
1231
-    def get_child_nb(self, content_type: ContentType, content_status = ''):
1231
+    def get_child_nb(self, content_type: str, content_status = ''):
1232
         child_nb = 0
1232
         child_nb = 0
1233
         for child in self.get_valid_children():
1233
         for child in self.get_valid_children():
1234
-            if child.type == content_type or content_type == ContentType.Any:
1234
+            if child.type == content_type or content_type.slug == CONTENT_TYPES.Any_SLUG:
1235
                 if not content_status:
1235
                 if not content_status:
1236
                     child_nb = child_nb+1
1236
                     child_nb = child_nb+1
1237
                 elif content_status==child.status:
1237
                 elif content_status==child.status:
1306
     def get_comments(self):
1306
     def get_comments(self):
1307
         children = []
1307
         children = []
1308
         for child in self.children:
1308
         for child in self.children:
1309
-            if ContentType.Comment==child.type and not child.is_deleted and not child.is_archived:
1309
+            if CONTENT_TYPES.Comment.slug == child.type and not child.is_deleted and not child.is_archived:
1310
                 children.append(child.node)
1310
                 children.append(child.node)
1311
         return children
1311
         return children
1312
 
1312
 
1347
             allowed_types = self.properties['allowed_content']
1347
             allowed_types = self.properties['allowed_content']
1348
             for type_label, is_allowed in allowed_types.items():
1348
             for type_label, is_allowed in allowed_types.items():
1349
                 if is_allowed:
1349
                 if is_allowed:
1350
-                    types.append(ContentType(type_label))
1350
+                    types.append(CONTENT_TYPES.get_one_by_slug(type_label))
1351
         except Exception as e:
1351
         except Exception as e:
1352
             print(e.__str__())
1352
             print(e.__str__())
1353
             print('----- /*\ *****')
1353
             print('----- /*\ *****')
1354
             raise ValueError('Not allowed content property')
1354
             raise ValueError('Not allowed content property')
1355
 
1355
 
1356
-        return ContentType.sorted(types)
1356
+        return types
1357
 
1357
 
1358
     def get_history(self, drop_empty_revision=False) -> '[VirtualEvent]':
1358
     def get_history(self, drop_empty_revision=False) -> '[VirtualEvent]':
1359
         events = []
1359
         events = []
1446
 
1446
 
1447
     @classmethod
1447
     @classmethod
1448
     def create_from_content(cls, content: Content):
1448
     def create_from_content(cls, content: Content):
1449
-        content_type = ContentType(content.type)
1450
 
1449
 
1451
         label = content.get_label()
1450
         label = content.get_label()
1452
-        if content.type == ContentType.Comment:
1451
+        if content.type == CONTENT_TYPES.Comment.slug:
1453
             # TODO - G.M  - 10-04-2018 - [Cleanup] Remove label param
1452
             # TODO - G.M  - 10-04-2018 - [Cleanup] Remove label param
1454
             # from this object ?
1453
             # from this object ?
1455
             label = l_('<strong>{}</strong> wrote:').format(content.owner.get_display_name())
1454
             label = l_('<strong>{}</strong> wrote:').format(content.owner.get_display_name())
1457
         return VirtualEvent(id=content.content_id,
1456
         return VirtualEvent(id=content.content_id,
1458
                             created=content.created,
1457
                             created=content.created,
1459
                             owner=content.owner,
1458
                             owner=content.owner,
1460
-                            type=content_type,
1459
+                            type=ActionDescription(content.revision_type),
1461
                             label=label,
1460
                             label=label,
1462
                             content=content.description,
1461
                             content=content.description,
1463
                             ref_object=content)
1462
                             ref_object=content)

+ 3 - 3
backend/tracim_backend/tests/__init__.py View File

14
 from tracim_backend.models import DeclarativeBase
14
 from tracim_backend.models import DeclarativeBase
15
 from tracim_backend.models import get_session_factory
15
 from tracim_backend.models import get_session_factory
16
 from tracim_backend.models import get_tm_session
16
 from tracim_backend.models import get_tm_session
17
+from tracim_backend.models.contents import CONTENT_TYPES
17
 from tracim_backend.models.data import Workspace
18
 from tracim_backend.models.data import Workspace
18
-from tracim_backend.models.data import ContentType
19
 from tracim_backend.models.data import ContentRevisionRO
19
 from tracim_backend.models.data import ContentRevisionRO
20
 from tracim_backend.models.data import Content
20
 from tracim_backend.models.data import Content
21
 from tracim_backend.lib.utils.logger import logger
21
 from tracim_backend.lib.utils.logger import logger
268
         workspace = self._create_workspace_and_test(workspace_name, user)
268
         workspace = self._create_workspace_and_test(workspace_name, user)
269
         folder = self._create_content_and_test(
269
         folder = self._create_content_and_test(
270
             folder_name, workspace,
270
             folder_name, workspace,
271
-            type=ContentType.Folder,
271
+            type=CONTENT_TYPES.Folder.slug,
272
             owner=user
272
             owner=user
273
         )
273
         )
274
         thread = self._create_content_and_test(
274
         thread = self._create_content_and_test(
275
             thread_name,
275
             thread_name,
276
             workspace,
276
             workspace,
277
-            type=ContentType.Thread,
277
+            type=CONTENT_TYPES.Thread.slug,
278
             parent=folder,
278
             parent=folder,
279
             owner=user
279
             owner=user
280
         )
280
         )

+ 37 - 38
backend/tracim_backend/tests/functional/test_contents.py View File

5
 from tracim_backend.lib.core.content import ContentApi
5
 from tracim_backend.lib.core.content import ContentApi
6
 from tracim_backend.lib.core.workspace import WorkspaceApi
6
 from tracim_backend.lib.core.workspace import WorkspaceApi
7
 from tracim_backend.models import get_tm_session
7
 from tracim_backend.models import get_tm_session
8
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
8
+from tracim_backend.models.contents import CONTENT_TYPES
9
 from tracim_backend.models.revision_protection import new_revision
9
 from tracim_backend.models.revision_protection import new_revision
10
 import io
10
 import io
11
 
11
 
16
 from tracim_backend import models
16
 from tracim_backend import models
17
 from tracim_backend.lib.core.content import ContentApi
17
 from tracim_backend.lib.core.content import ContentApi
18
 from tracim_backend.lib.core.workspace import WorkspaceApi
18
 from tracim_backend.lib.core.workspace import WorkspaceApi
19
-from tracim_backend.models.data import ContentType
20
 from tracim_backend.models import get_tm_session
19
 from tracim_backend.models import get_tm_session
21
 from tracim_backend.models.revision_protection import new_revision
20
 from tracim_backend.models.revision_protection import new_revision
22
 from tracim_backend.tests import FunctionalTest
21
 from tracim_backend.tests import FunctionalTest
480
             config=self.app_config
479
             config=self.app_config
481
         )
480
         )
482
         business_workspace = workspace_api.get_one(1)
481
         business_workspace = workspace_api.get_one(1)
483
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
482
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
484
         test_file = content_api.create(
483
         test_file = content_api.create(
485
-            content_type=ContentType.File,
484
+            content_type_slug=CONTENT_TYPES.File.slug,
486
             workspace=business_workspace,
485
             workspace=business_workspace,
487
             parent=tool_folder,
486
             parent=tool_folder,
488
             label='Test file',
487
             label='Test file',
648
             config=self.app_config
647
             config=self.app_config
649
         )
648
         )
650
         business_workspace = workspace_api.get_one(1)
649
         business_workspace = workspace_api.get_one(1)
651
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
650
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
652
         test_file = content_api.create(
651
         test_file = content_api.create(
653
-            content_type=ContentType.File,
652
+            content_type_slug=CONTENT_TYPES.File.slug,
654
             workspace=business_workspace,
653
             workspace=business_workspace,
655
             parent=tool_folder,
654
             parent=tool_folder,
656
             label='Test file',
655
             label='Test file',
703
             config=self.app_config
702
             config=self.app_config
704
         )
703
         )
705
         business_workspace = workspace_api.get_one(1)
704
         business_workspace = workspace_api.get_one(1)
706
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
705
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
707
         test_file = content_api.create(
706
         test_file = content_api.create(
708
-            content_type=ContentType.File,
707
+            content_type_slug=CONTENT_TYPES.File.slug,
709
             workspace=business_workspace,
708
             workspace=business_workspace,
710
             parent=tool_folder,
709
             parent=tool_folder,
711
             label='Test file',
710
             label='Test file',
809
             config=self.app_config
808
             config=self.app_config
810
         )
809
         )
811
         business_workspace = workspace_api.get_one(1)
810
         business_workspace = workspace_api.get_one(1)
812
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
811
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
813
         test_file = content_api.create(
812
         test_file = content_api.create(
814
-            content_type=ContentType.File,
813
+            content_type_slug=CONTENT_TYPES.File.slug,
815
             workspace=business_workspace,
814
             workspace=business_workspace,
816
             parent=tool_folder,
815
             parent=tool_folder,
817
             label='Test file',
816
             label='Test file',
882
             config=self.app_config
881
             config=self.app_config
883
         )
882
         )
884
         business_workspace = workspace_api.get_one(1)
883
         business_workspace = workspace_api.get_one(1)
885
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
884
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
886
         test_file = content_api.create(
885
         test_file = content_api.create(
887
-            content_type=ContentType.File,
886
+            content_type_slug=CONTENT_TYPES.File.slug,
888
             workspace=business_workspace,
887
             workspace=business_workspace,
889
             parent=tool_folder,
888
             parent=tool_folder,
890
             label='Test file',
889
             label='Test file',
978
             config=self.app_config
977
             config=self.app_config
979
         )
978
         )
980
         business_workspace = workspace_api.get_one(1)
979
         business_workspace = workspace_api.get_one(1)
981
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
980
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
982
         test_file = content_api.create(
981
         test_file = content_api.create(
983
-            content_type=ContentType.File,
982
+            content_type_slug=CONTENT_TYPES.File.slug,
984
             workspace=business_workspace,
983
             workspace=business_workspace,
985
             parent=tool_folder,
984
             parent=tool_folder,
986
             label='Test file',
985
             label='Test file',
1031
             config=self.app_config
1030
             config=self.app_config
1032
         )
1031
         )
1033
         business_workspace = workspace_api.get_one(1)
1032
         business_workspace = workspace_api.get_one(1)
1034
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1033
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1035
         test_file = content_api.create(
1034
         test_file = content_api.create(
1036
-            content_type=ContentType.File,
1035
+            content_type_slug=CONTENT_TYPES.File.slug,
1037
             workspace=business_workspace,
1036
             workspace=business_workspace,
1038
             parent=tool_folder,
1037
             parent=tool_folder,
1039
             label='Test file',
1038
             label='Test file',
1082
             config=self.app_config
1081
             config=self.app_config
1083
         )
1082
         )
1084
         business_workspace = workspace_api.get_one(1)
1083
         business_workspace = workspace_api.get_one(1)
1085
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1084
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1086
         test_file = content_api.create(
1085
         test_file = content_api.create(
1087
-            content_type=ContentType.File,
1086
+            content_type_slug=CONTENT_TYPES.File.slug,
1088
             workspace=business_workspace,
1087
             workspace=business_workspace,
1089
             parent=tool_folder,
1088
             parent=tool_folder,
1090
             label='Test file',
1089
             label='Test file',
1137
             config=self.app_config
1136
             config=self.app_config
1138
         )
1137
         )
1139
         business_workspace = workspace_api.get_one(1)
1138
         business_workspace = workspace_api.get_one(1)
1140
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1139
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1141
         test_file = content_api.create(
1140
         test_file = content_api.create(
1142
-            content_type=ContentType.File,
1141
+            content_type_slug=CONTENT_TYPES.File.slug,
1143
             workspace=business_workspace,
1142
             workspace=business_workspace,
1144
             parent=tool_folder,
1143
             parent=tool_folder,
1145
             label='Test file',
1144
             label='Test file',
1196
             config=self.app_config
1195
             config=self.app_config
1197
         )
1196
         )
1198
         business_workspace = workspace_api.get_one(1)
1197
         business_workspace = workspace_api.get_one(1)
1199
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1198
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1200
         test_file = content_api.create(
1199
         test_file = content_api.create(
1201
-            content_type=ContentType.File,
1200
+            content_type_slug=CONTENT_TYPES.File.slug,
1202
             workspace=business_workspace,
1201
             workspace=business_workspace,
1203
             parent=tool_folder,
1202
             parent=tool_folder,
1204
             label='Test file',
1203
             label='Test file',
1251
             config=self.app_config
1250
             config=self.app_config
1252
         )
1251
         )
1253
         business_workspace = workspace_api.get_one(1)
1252
         business_workspace = workspace_api.get_one(1)
1254
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1253
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1255
         test_file = content_api.create(
1254
         test_file = content_api.create(
1256
-            content_type=ContentType.File,
1255
+            content_type_slug=CONTENT_TYPES.File.slug,
1257
             workspace=business_workspace,
1256
             workspace=business_workspace,
1258
             parent=tool_folder,
1257
             parent=tool_folder,
1259
             label='Test file',
1258
             label='Test file',
1302
             config=self.app_config
1301
             config=self.app_config
1303
         )
1302
         )
1304
         business_workspace = workspace_api.get_one(1)
1303
         business_workspace = workspace_api.get_one(1)
1305
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1304
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1306
         test_file = content_api.create(
1305
         test_file = content_api.create(
1307
-            content_type=ContentType.File,
1306
+            content_type_slug=CONTENT_TYPES.File.slug,
1308
             workspace=business_workspace,
1307
             workspace=business_workspace,
1309
             parent=tool_folder,
1308
             parent=tool_folder,
1310
             label='Test file',
1309
             label='Test file',
1375
             config=self.app_config
1374
             config=self.app_config
1376
         )
1375
         )
1377
         business_workspace = workspace_api.get_one(1)
1376
         business_workspace = workspace_api.get_one(1)
1378
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1377
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1379
         test_file = content_api.create(
1378
         test_file = content_api.create(
1380
-            content_type=ContentType.File,
1379
+            content_type_slug=CONTENT_TYPES.File.slug,
1381
             workspace=business_workspace,
1380
             workspace=business_workspace,
1382
             parent=tool_folder,
1381
             parent=tool_folder,
1383
             label='Test file',
1382
             label='Test file',
1438
             config=self.app_config
1437
             config=self.app_config
1439
         )
1438
         )
1440
         business_workspace = workspace_api.get_one(1)
1439
         business_workspace = workspace_api.get_one(1)
1441
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1440
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1442
         test_file = content_api.create(
1441
         test_file = content_api.create(
1443
-            content_type=ContentType.File,
1442
+            content_type_slug=CONTENT_TYPES.File.slug,
1444
             workspace=business_workspace,
1443
             workspace=business_workspace,
1445
             parent=tool_folder,
1444
             parent=tool_folder,
1446
             label='Test file',
1445
             label='Test file',
1489
             config=self.app_config
1488
             config=self.app_config
1490
         )
1489
         )
1491
         business_workspace = workspace_api.get_one(1)
1490
         business_workspace = workspace_api.get_one(1)
1492
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1491
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1493
         test_file = content_api.create(
1492
         test_file = content_api.create(
1494
-            content_type=ContentType.File,
1493
+            content_type_slug=CONTENT_TYPES.File.slug,
1495
             workspace=business_workspace,
1494
             workspace=business_workspace,
1496
             parent=tool_folder,
1495
             parent=tool_folder,
1497
             label='Test file',
1496
             label='Test file',
1554
             config=self.app_config
1553
             config=self.app_config
1555
         )
1554
         )
1556
         business_workspace = workspace_api.get_one(1)
1555
         business_workspace = workspace_api.get_one(1)
1557
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1556
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1558
         test_file = content_api.create(
1557
         test_file = content_api.create(
1559
-            content_type=ContentType.File,
1558
+            content_type_slug=CONTENT_TYPES.File.slug,
1560
             workspace=business_workspace,
1559
             workspace=business_workspace,
1561
             parent=tool_folder,
1560
             parent=tool_folder,
1562
             label='Test file',
1561
             label='Test file',
1618
             config=self.app_config
1617
             config=self.app_config
1619
         )
1618
         )
1620
         business_workspace = workspace_api.get_one(1)
1619
         business_workspace = workspace_api.get_one(1)
1621
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1620
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1622
         test_file = content_api.create(
1621
         test_file = content_api.create(
1623
-            content_type=ContentType.File,
1622
+            content_type_slug=CONTENT_TYPES.File.slug,
1624
             workspace=business_workspace,
1623
             workspace=business_workspace,
1625
             parent=tool_folder,
1624
             parent=tool_folder,
1626
             label='Test file',
1625
             label='Test file',
1989
             session=dbsession,
1988
             session=dbsession,
1990
             config=self.app_config
1989
             config=self.app_config
1991
         )
1990
         )
1992
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1991
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1993
         test_thread = content_api.create(
1992
         test_thread = content_api.create(
1994
-            content_type=ContentType.Thread,
1993
+            content_type_slug=CONTENT_TYPES.Thread.slug,
1995
             workspace=business_workspace,
1994
             workspace=business_workspace,
1996
             parent=tool_folder,
1995
             parent=tool_folder,
1997
             label='Test Thread',
1996
             label='Test Thread',

+ 5 - 5
backend/tracim_backend/tests/functional/test_mail_notification.py View File

11
 from tracim_backend.fixtures.content import Content as ContentFixture
11
 from tracim_backend.fixtures.content import Content as ContentFixture
12
 from tracim_backend.lib.utils.utils import get_redis_connection
12
 from tracim_backend.lib.utils.utils import get_redis_connection
13
 from tracim_backend.lib.utils.utils import get_rq_queue
13
 from tracim_backend.lib.utils.utils import get_rq_queue
14
-from tracim_backend.models.data import ContentType
14
+from tracim_backend.models.contents import CONTENT_TYPES
15
 
15
 
16
 from tracim_backend.lib.core.content import ContentApi
16
 from tracim_backend.lib.core.content import ContentApi
17
 from tracim_backend.lib.core.user import UserApi
17
 from tracim_backend.lib.core.user import UserApi
139
             config=self.app_config,
139
             config=self.app_config,
140
         )
140
         )
141
         item = api.create(
141
         item = api.create(
142
-            ContentType.Folder,
142
+            CONTENT_TYPES.Folder.slug,
143
             workspace,
143
             workspace,
144
             None,
144
             None,
145
             'parent',
145
             'parent',
147
             do_notify=False,
147
             do_notify=False,
148
         )
148
         )
149
         item2 = api.create(
149
         item2 = api.create(
150
-            ContentType.File,
150
+            CONTENT_TYPES.File.slug,
151
             workspace,
151
             workspace,
152
             item,
152
             item,
153
             'file1',
153
             'file1',
231
             config=self.app_config,
231
             config=self.app_config,
232
         )
232
         )
233
         item = api.create(
233
         item = api.create(
234
-            ContentType.Folder,
234
+            CONTENT_TYPES.Folder.slug,
235
             workspace,
235
             workspace,
236
             None,
236
             None,
237
             'parent',
237
             'parent',
239
             do_notify=False,
239
             do_notify=False,
240
         )
240
         )
241
         item2 = api.create(
241
         item2 = api.create(
242
-            ContentType.File,
242
+            CONTENT_TYPES.File.slug,
243
             workspace,
243
             workspace,
244
             item,
244
             item,
245
             'file1',
245
             'file1',

+ 4 - 4
backend/tracim_backend/tests/functional/test_system.py View File

96
         res = self.testapp.get('/api/v2/system/content_types', status=200)
96
         res = self.testapp.get('/api/v2/system/content_types', status=200)
97
         res = res.json_body
97
         res = res.json_body
98
 
98
 
99
-        content_type = res[0]
99
+        content_type = res[1]
100
         assert content_type['slug'] == 'thread'
100
         assert content_type['slug'] == 'thread'
101
         assert content_type['fa_icon'] == 'comments-o'
101
         assert content_type['fa_icon'] == 'comments-o'
102
         assert content_type['hexcolor'] == '#ad4cf9'
102
         assert content_type['hexcolor'] == '#ad4cf9'
105
         assert 'available_statuses' in content_type
105
         assert 'available_statuses' in content_type
106
         assert len(content_type['available_statuses']) == 4
106
         assert len(content_type['available_statuses']) == 4
107
 
107
 
108
-        content_type = res[1]
108
+        content_type = res[2]
109
         assert content_type['slug'] == 'file'
109
         assert content_type['slug'] == 'file'
110
         assert content_type['fa_icon'] == 'paperclip'
110
         assert content_type['fa_icon'] == 'paperclip'
111
         assert content_type['hexcolor'] == '#FF9900'
111
         assert content_type['hexcolor'] == '#FF9900'
114
         assert 'available_statuses' in content_type
114
         assert 'available_statuses' in content_type
115
         assert len(content_type['available_statuses']) == 4
115
         assert len(content_type['available_statuses']) == 4
116
 
116
 
117
-        content_type = res[2]
117
+        content_type = res[3]
118
         assert content_type['slug'] == 'markdownpage'
118
         assert content_type['slug'] == 'markdownpage'
119
         assert content_type['fa_icon'] == 'file-code-o'
119
         assert content_type['fa_icon'] == 'file-code-o'
120
         assert content_type['hexcolor'] == '#f12d2d'
120
         assert content_type['hexcolor'] == '#f12d2d'
123
         assert 'available_statuses' in content_type
123
         assert 'available_statuses' in content_type
124
         assert len(content_type['available_statuses']) == 4
124
         assert len(content_type['available_statuses']) == 4
125
 
125
 
126
-        content_type = res[3]
126
+        content_type = res[4]
127
         assert content_type['slug'] == 'html-documents'
127
         assert content_type['slug'] == 'html-documents'
128
         assert content_type['fa_icon'] == 'file-text-o'
128
         assert content_type['fa_icon'] == 'file-text-o'
129
         assert content_type['hexcolor'] == '#3f52e3'
129
         assert content_type['hexcolor'] == '#3f52e3'

+ 47 - 47
backend/tracim_backend/tests/functional/test_user.py View File

12
 from tracim_backend.lib.core.group import GroupApi
12
 from tracim_backend.lib.core.group import GroupApi
13
 from tracim_backend.lib.core.workspace import WorkspaceApi
13
 from tracim_backend.lib.core.workspace import WorkspaceApi
14
 from tracim_backend.models import get_tm_session
14
 from tracim_backend.models import get_tm_session
15
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
15
+from tracim_backend.models.contents import CONTENT_TYPES
16
 from tracim_backend.models.revision_protection import new_revision
16
 from tracim_backend.models.revision_protection import new_revision
17
 from tracim_backend.tests import FunctionalTest
17
 from tracim_backend.tests import FunctionalTest
18
 from tracim_backend.fixtures.content import Content as ContentFixtures
18
 from tracim_backend.fixtures.content import Content as ContentFixtures
60
             session=dbsession,
60
             session=dbsession,
61
             config=self.app_config,
61
             config=self.app_config,
62
         )
62
         )
63
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
64
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
63
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
64
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
65
         # creation order test
65
         # creation order test
66
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
67
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
66
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
67
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
68
         # update order test
68
         # update order test
69
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
70
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
69
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
70
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
71
         with new_revision(
71
         with new_revision(
72
             session=dbsession,
72
             session=dbsession,
73
             tm=transaction.manager,
73
             tm=transaction.manager,
76
             firstly_created_but_recently_updated.description = 'Just an update'
76
             firstly_created_but_recently_updated.description = 'Just an update'
77
         api.save(firstly_created_but_recently_updated)
77
         api.save(firstly_created_but_recently_updated)
78
         # comment change order
78
         # comment change order
79
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
80
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
79
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
80
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
81
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
81
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
82
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
82
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
83
         dbsession.flush()
83
         dbsession.flush()
84
         transaction.commit()
84
         transaction.commit()
85
 
85
 
159
             session=dbsession,
159
             session=dbsession,
160
             config=self.app_config,
160
             config=self.app_config,
161
         )
161
         )
162
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
162
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
163
         sleep(1)
163
         sleep(1)
164
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
164
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
165
         # creation order test
165
         # creation order test
166
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
166
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
167
         sleep(1)
167
         sleep(1)
168
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
168
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
169
         # update order test
169
         # update order test
170
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
170
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
171
         sleep(1)
171
         sleep(1)
172
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
172
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
173
         sleep(1)
173
         sleep(1)
174
         with new_revision(
174
         with new_revision(
175
             session=dbsession,
175
             session=dbsession,
179
             firstly_created_but_recently_updated.description = 'Just an update'
179
             firstly_created_but_recently_updated.description = 'Just an update'
180
         api.save(firstly_created_but_recently_updated)
180
         api.save(firstly_created_but_recently_updated)
181
         # comment change order
181
         # comment change order
182
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
182
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
183
         sleep(1)
183
         sleep(1)
184
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
184
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
185
         sleep(1)
185
         sleep(1)
186
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
186
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
187
         sleep(1)
187
         sleep(1)
188
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
188
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
189
         dbsession.flush()
189
         dbsession.flush()
190
         transaction.commit()
190
         transaction.commit()
191
 
191
 
281
             session=dbsession,
281
             session=dbsession,
282
             config=self.app_config,
282
             config=self.app_config,
283
         )
283
         )
284
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
285
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
284
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
285
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
286
         # creation order test
286
         # creation order test
287
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
288
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
287
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
288
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
289
         # update order test
289
         # update order test
290
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
291
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
290
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
291
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
292
         with new_revision(
292
         with new_revision(
293
             session=dbsession,
293
             session=dbsession,
294
             tm=transaction.manager,
294
             tm=transaction.manager,
297
             firstly_created_but_recently_updated.description = 'Just an update'
297
             firstly_created_but_recently_updated.description = 'Just an update'
298
         api.save(firstly_created_but_recently_updated)
298
         api.save(firstly_created_but_recently_updated)
299
         # comment change order
299
         # comment change order
300
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
301
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
300
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
301
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
302
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
302
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
303
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
303
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
304
         dbsession.flush()
304
         dbsession.flush()
305
         transaction.commit()
305
         transaction.commit()
306
 
306
 
365
             session=dbsession,
365
             session=dbsession,
366
             config=self.app_config,
366
             config=self.app_config,
367
         )
367
         )
368
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
369
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
368
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
369
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
370
         # creation order test
370
         # creation order test
371
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
372
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
371
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
372
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
373
         # update order test
373
         # update order test
374
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
375
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
374
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
375
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
376
         with new_revision(
376
         with new_revision(
377
             session=dbsession,
377
             session=dbsession,
378
             tm=transaction.manager,
378
             tm=transaction.manager,
381
             firstly_created_but_recently_updated.description = 'Just an update'
381
             firstly_created_but_recently_updated.description = 'Just an update'
382
         api.save(firstly_created_but_recently_updated)
382
         api.save(firstly_created_but_recently_updated)
383
         # comment change order
383
         # comment change order
384
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
385
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
384
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
385
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
386
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
386
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
387
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
387
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
388
         dbsession.flush()
388
         dbsession.flush()
389
         transaction.commit()
389
         transaction.commit()
390
 
390
 
457
             session=dbsession,
457
             session=dbsession,
458
             config=self.app_config,
458
             config=self.app_config,
459
         )
459
         )
460
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
460
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
461
         # creation order test
461
         # creation order test
462
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
462
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
463
         api.mark_unread(firstly_created)
463
         api.mark_unread(firstly_created)
464
         dbsession.flush()
464
         dbsession.flush()
465
         transaction.commit()
465
         transaction.commit()
510
             session=dbsession,
510
             session=dbsession,
511
             config=self.app_config,
511
             config=self.app_config,
512
         )
512
         )
513
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
513
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
514
         # creation order test
514
         # creation order test
515
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
515
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
516
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
516
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
517
         api.mark_unread(firstly_created)
517
         api.mark_unread(firstly_created)
518
         api.mark_unread(comments)
518
         api.mark_unread(comments)
573
             session=dbsession,
573
             session=dbsession,
574
             config=self.app_config,
574
             config=self.app_config,
575
         )
575
         )
576
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
576
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
577
         # creation order test
577
         # creation order test
578
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
578
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
579
         api.mark_read(firstly_created)
579
         api.mark_read(firstly_created)
580
         dbsession.flush()
580
         dbsession.flush()
581
         transaction.commit()
581
         transaction.commit()
626
             session=dbsession,
626
             session=dbsession,
627
             config=self.app_config,
627
             config=self.app_config,
628
         )
628
         )
629
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
629
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
630
         # creation order test
630
         # creation order test
631
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
631
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
632
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
632
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
633
         api.mark_read(firstly_created)
633
         api.mark_read(firstly_created)
634
         api.mark_read(comments)
634
         api.mark_read(comments)
688
             session=dbsession,
688
             session=dbsession,
689
             config=self.app_config,
689
             config=self.app_config,
690
         )
690
         )
691
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
691
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
692
         # creation order test
692
         # creation order test
693
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
693
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
694
         api.mark_unread(main_folder)
694
         api.mark_unread(main_folder)
695
         api.mark_unread(firstly_created)
695
         api.mark_unread(firstly_created)
696
         dbsession.flush()
696
         dbsession.flush()

+ 14 - 14
backend/tracim_backend/tests/functional/test_workspaces.py View File

10
 from tracim_backend.lib.core.content import ContentApi
10
 from tracim_backend.lib.core.content import ContentApi
11
 from tracim_backend.lib.core.workspace import WorkspaceApi
11
 from tracim_backend.lib.core.workspace import WorkspaceApi
12
 from tracim_backend.models import get_tm_session
12
 from tracim_backend.models import get_tm_session
13
-from tracim_backend.models.data import ContentType
13
+from tracim_backend.models.contents import CONTENT_TYPES
14
 from tracim_backend.tests import FunctionalTest
14
 from tracim_backend.tests import FunctionalTest
15
 from tracim_backend.tests import set_html_document_slug_to_legacy
15
 from tracim_backend.tests import set_html_document_slug_to_legacy
16
 from tracim_backend.fixtures.content import Content as ContentFixtures
16
 from tracim_backend.fixtures.content import Content as ContentFixtures
983
             session=dbsession,
983
             session=dbsession,
984
             config=self.app_config
984
             config=self.app_config
985
         )
985
         )
986
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
986
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
987
         test_thread = content_api.create(
987
         test_thread = content_api.create(
988
-            content_type=ContentType.Thread,
988
+            content_type_slug=CONTENT_TYPES.Thread.slug,
989
             workspace=business_workspace,
989
             workspace=business_workspace,
990
             parent=tool_folder,
990
             parent=tool_folder,
991
             label='Test Thread',
991
             label='Test Thread',
995
         test_thread.description = 'Thread description'
995
         test_thread.description = 'Thread description'
996
         dbsession.add(test_thread)
996
         dbsession.add(test_thread)
997
         test_file = content_api.create(
997
         test_file = content_api.create(
998
-            content_type=ContentType.File,
998
+            content_type_slug=CONTENT_TYPES.File.slug,
999
             workspace=business_workspace,
999
             workspace=business_workspace,
1000
             parent=tool_folder,
1000
             parent=tool_folder,
1001
             label='Test file',
1001
             label='Test file',
1009
             'text/plain',
1009
             'text/plain',
1010
         )
1010
         )
1011
         test_page_legacy = content_api.create(
1011
         test_page_legacy = content_api.create(
1012
-            content_type=ContentType.Page,
1012
+            content_type_slug=CONTENT_TYPES.Page.slug,
1013
             workspace=business_workspace,
1013
             workspace=business_workspace,
1014
             label='test_page',
1014
             label='test_page',
1015
             do_save=False,
1015
             do_save=False,
1016
             do_notify=False,
1016
             do_notify=False,
1017
         )
1017
         )
1018
-        test_page_legacy.type = ContentType.PageLegacy
1018
+        test_page_legacy.type = 'page'
1019
         content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
1019
         content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
1020
         test_html_document = content_api.create(
1020
         test_html_document = content_api.create(
1021
-            content_type=ContentType.Page,
1021
+            content_type_slug=CONTENT_TYPES.Page.slug,
1022
             workspace=business_workspace,
1022
             workspace=business_workspace,
1023
             label='test_html_page',
1023
             label='test_html_page',
1024
             do_save=False,
1024
             do_save=False,
1078
             session=dbsession,
1078
             session=dbsession,
1079
             config=self.app_config
1079
             config=self.app_config
1080
         )
1080
         )
1081
-        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1081
+        tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG)
1082
         test_thread = content_api.create(
1082
         test_thread = content_api.create(
1083
-            content_type=ContentType.Thread,
1083
+            content_type_slug=CONTENT_TYPES.Thread.slug,
1084
             workspace=business_workspace,
1084
             workspace=business_workspace,
1085
             parent=tool_folder,
1085
             parent=tool_folder,
1086
             label='Test Thread',
1086
             label='Test Thread',
1090
         test_thread.description = 'Thread description'
1090
         test_thread.description = 'Thread description'
1091
         dbsession.add(test_thread)
1091
         dbsession.add(test_thread)
1092
         test_file = content_api.create(
1092
         test_file = content_api.create(
1093
-            content_type=ContentType.File,
1093
+            content_type_slug=CONTENT_TYPES.File.slug,
1094
             workspace=business_workspace,
1094
             workspace=business_workspace,
1095
             parent=tool_folder,
1095
             parent=tool_folder,
1096
             label='Test file',
1096
             label='Test file',
1104
             'text/plain',
1104
             'text/plain',
1105
         )
1105
         )
1106
         test_page_legacy = content_api.create(
1106
         test_page_legacy = content_api.create(
1107
-            content_type=ContentType.Page,
1107
+            content_type_slug=CONTENT_TYPES.Page.slug,
1108
             workspace=business_workspace,
1108
             workspace=business_workspace,
1109
             parent=tool_folder,
1109
             parent=tool_folder,
1110
             label='test_page',
1110
             label='test_page',
1111
             do_save=False,
1111
             do_save=False,
1112
             do_notify=False,
1112
             do_notify=False,
1113
         )
1113
         )
1114
-        test_page_legacy.type = ContentType.PageLegacy
1114
+        test_page_legacy.type = 'page'
1115
         content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
1115
         content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>')
1116
         test_html_document = content_api.create(
1116
         test_html_document = content_api.create(
1117
-            content_type=ContentType.Page,
1117
+            content_type_slug=CONTENT_TYPES.Page.slug,
1118
             workspace=business_workspace,
1118
             workspace=business_workspace,
1119
             parent=tool_folder,
1119
             parent=tool_folder,
1120
             label='test_html_page',
1120
             label='test_html_page',
1180
             'show_archived': 1,
1180
             'show_archived': 1,
1181
             'show_deleted': 1,
1181
             'show_deleted': 1,
1182
             'show_active': 1,
1182
             'show_active': 1,
1183
-            'content_type': 'any'
1183
+         #   'content_type': 'any'
1184
         }
1184
         }
1185
         self.testapp.authorization = (
1185
         self.testapp.authorization = (
1186
             'Basic',
1186
             'Basic',

+ 115 - 115
backend/tracim_backend/tests/library/test_content_api.py View File

14
 from tracim_backend.lib.core.workspace import RoleApi
14
 from tracim_backend.lib.core.workspace import RoleApi
15
 # TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi
15
 # TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi
16
 from tracim_backend.lib.core.workspace import WorkspaceApi
16
 from tracim_backend.lib.core.workspace import WorkspaceApi
17
+from tracim_backend.models.contents import CONTENT_TYPES
17
 from tracim_backend.models.revision_protection import new_revision
18
 from tracim_backend.models.revision_protection import new_revision
18
 from tracim_backend.models.auth import User
19
 from tracim_backend.models.auth import User
19
 from tracim_backend.models.auth import Group
20
 from tracim_backend.models.auth import Group
22
 from tracim_backend.models.data import ContentRevisionRO
23
 from tracim_backend.models.data import ContentRevisionRO
23
 from tracim_backend.models.data import Workspace
24
 from tracim_backend.models.data import Workspace
24
 from tracim_backend.models.data import Content
25
 from tracim_backend.models.data import Content
25
-from tracim_backend.models.data import ContentType
26
 from tracim_backend.models.data import UserRoleInWorkspace
26
 from tracim_backend.models.data import UserRoleInWorkspace
27
 from tracim_backend.fixtures.users_and_groups import Test as FixtureTest
27
 from tracim_backend.fixtures.users_and_groups import Test as FixtureTest
28
 from tracim_backend.tests import DefaultTest
28
 from tracim_backend.tests import DefaultTest
129
             config=self.app_config,
129
             config=self.app_config,
130
         )
130
         )
131
         item = api.create(
131
         item = api.create(
132
-            content_type=ContentType.Folder,
132
+            content_type_slug=CONTENT_TYPES.Folder.slug,
133
             workspace=workspace,
133
             workspace=workspace,
134
             parent=None,
134
             parent=None,
135
             label='not_deleted',
135
             label='not_deleted',
136
             do_save=True
136
             do_save=True
137
         )
137
         )
138
         item2 = api.create(
138
         item2 = api.create(
139
-            content_type=ContentType.Folder,
139
+            content_type_slug=CONTENT_TYPES.Folder.slug,
140
             workspace=workspace,
140
             workspace=workspace,
141
             parent=None,
141
             parent=None,
142
             label='to_delete',
142
             label='to_delete',
159
             session=self.session,
159
             session=self.session,
160
             config=self.app_config,
160
             config=self.app_config,
161
         )
161
         )
162
-        items = api.get_all(None, ContentType.Any, workspace)
162
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
163
         eq_(2, len(items))
163
         eq_(2, len(items))
164
 
164
 
165
-        items = api.get_all(None, ContentType.Any, workspace)
165
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
166
         with new_revision(
166
         with new_revision(
167
                 session=self.session,
167
                 session=self.session,
168
                 tm=transaction.manager,
168
                 tm=transaction.manager,
184
             session=self.session,
184
             session=self.session,
185
             config=self.app_config,
185
             config=self.app_config,
186
         )
186
         )
187
-        items = api.get_all(None, ContentType.Any, workspace)
187
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
188
         eq_(1, len(items))
188
         eq_(1, len(items))
189
         transaction.commit()
189
         transaction.commit()
190
 
190
 
202
             config=self.app_config,
202
             config=self.app_config,
203
             show_deleted=True,
203
             show_deleted=True,
204
         )
204
         )
205
-        items = api.get_all(None, ContentType.Any, workspace)
205
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
206
         eq_(2, len(items))
206
         eq_(2, len(items))
207
 
207
 
208
     def test_archive(self):
208
     def test_archive(self):
240
             config=self.app_config,
240
             config=self.app_config,
241
         )
241
         )
242
         item = api.create(
242
         item = api.create(
243
-            content_type=ContentType.Folder,
243
+            content_type_slug=CONTENT_TYPES.Folder.slug,
244
             workspace=workspace,
244
             workspace=workspace,
245
             parent=None,
245
             parent=None,
246
             label='not_archived',
246
             label='not_archived',
247
             do_save=True
247
             do_save=True
248
         )
248
         )
249
         item2 = api.create(
249
         item2 = api.create(
250
-            content_type=ContentType.Folder,
250
+            content_type_slug=CONTENT_TYPES.Folder.slug,
251
             workspace=workspace,
251
             workspace=workspace,
252
             parent=None,
252
             parent=None,
253
             label='to_archive',
253
             label='to_archive',
269
             config=self.app_config,
269
             config=self.app_config,
270
         )
270
         )
271
 
271
 
272
-        items = api.get_all(None, ContentType.Any, workspace)
272
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
273
         eq_(2, len(items))
273
         eq_(2, len(items))
274
 
274
 
275
-        items = api.get_all(None, ContentType.Any, workspace)
275
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
276
         with new_revision(
276
         with new_revision(
277
                 session=self.session,
277
                 session=self.session,
278
                 tm=transaction.manager,
278
                 tm=transaction.manager,
295
             config=self.app_config,
295
             config=self.app_config,
296
         )
296
         )
297
 
297
 
298
-        items = api.get_all(None, ContentType.Any, workspace)
298
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
299
         eq_(1, len(items))
299
         eq_(1, len(items))
300
         transaction.commit()
300
         transaction.commit()
301
 
301
 
320
             config=self.app_config,
320
             config=self.app_config,
321
             show_archived=True,
321
             show_archived=True,
322
         )
322
         )
323
-        items = api.get_all(None, ContentType.Any, workspace)
323
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
324
         eq_(2, len(items))
324
         eq_(2, len(items))
325
 
325
 
326
     def test_get_all_with_filter(self):
326
     def test_get_all_with_filter(self):
358
             config=self.app_config,
358
             config=self.app_config,
359
         )
359
         )
360
         item = api.create(
360
         item = api.create(
361
-            content_type=ContentType.Folder,
361
+            content_type_slug=CONTENT_TYPES.Folder.slug,
362
             workspace=workspace,
362
             workspace=workspace,
363
             parent=None,
363
             parent=None,
364
             label='thefolder',
364
             label='thefolder',
365
             do_save=True
365
             do_save=True
366
         )
366
         )
367
         item2 = api.create(
367
         item2 = api.create(
368
-            content_type=ContentType.File,
368
+            content_type_slug=CONTENT_TYPES.File.slug,
369
             workspace=workspace,
369
             workspace=workspace,
370
             parent=None,
370
             parent=None,
371
             label='thefile',
371
             label='thefile',
389
             config=self.app_config,
389
             config=self.app_config,
390
         )
390
         )
391
 
391
 
392
-        items = api.get_all(None, ContentType.Any, workspace)
392
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
393
         eq_(2, len(items))
393
         eq_(2, len(items))
394
 
394
 
395
-        items2 = api.get_all(None, ContentType.File, workspace)
395
+        items2 = api.get_all(None, CONTENT_TYPES.File.slug, workspace)
396
         eq_(1, len(items2))
396
         eq_(1, len(items2))
397
         eq_('thefile', items2[0].label)
397
         eq_('thefile', items2[0].label)
398
 
398
 
399
-        items3 = api.get_all(None, ContentType.Folder, workspace)
399
+        items3 = api.get_all(None, CONTENT_TYPES.Folder.slug, workspace)
400
         eq_(1, len(items3))
400
         eq_(1, len(items3))
401
         eq_('thefolder', items3[0].label)
401
         eq_('thefolder', items3[0].label)
402
 
402
 
428
             config=self.app_config,
428
             config=self.app_config,
429
         )
429
         )
430
         item = api.create(
430
         item = api.create(
431
-            ContentType.Folder,
431
+            CONTENT_TYPES.Folder.slug,
432
             workspace,
432
             workspace,
433
             None,
433
             None,
434
             'parent',
434
             'parent',
435
             do_save=True,
435
             do_save=True,
436
         )
436
         )
437
         item2 = api.create(
437
         item2 = api.create(
438
-            ContentType.File,
438
+            CONTENT_TYPES.File.slug,
439
             workspace,
439
             workspace,
440
             item,
440
             item,
441
             'file1',
441
             'file1',
442
             do_save=True,
442
             do_save=True,
443
         )
443
         )
444
         item3 = api.create(
444
         item3 = api.create(
445
-            ContentType.File,
445
+            CONTENT_TYPES.File.slug,
446
             workspace,
446
             workspace,
447
             None,
447
             None,
448
             'file2',
448
             'file2',
468
             config=self.app_config,
468
             config=self.app_config,
469
         )
469
         )
470
 
470
 
471
-        items = api.get_all(None, ContentType.Any, workspace)
471
+        items = api.get_all(None, CONTENT_TYPES.Any_SLUG, workspace)
472
         eq_(3, len(items))
472
         eq_(3, len(items))
473
 
473
 
474
-        items2 = api.get_all(parent_id, ContentType.File, workspace)
474
+        items2 = api.get_all(parent_id, CONTENT_TYPES.File.slug, workspace)
475
         eq_(1, len(items2))
475
         eq_(1, len(items2))
476
         eq_(child_id, items2[0].content_id)
476
         eq_(child_id, items2[0].content_id)
477
 
477
 
506
             session=self.session,
506
             session=self.session,
507
             config=self.app_config,
507
             config=self.app_config,
508
         )
508
         )
509
-        c = api.create(ContentType.Folder, workspace, None, 'parent', '', True)
509
+        c = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'parent', '', True)
510
         with new_revision(
510
         with new_revision(
511
             session=self.session,
511
             session=self.session,
512
             tm=transaction.manager,
512
             tm=transaction.manager,
546
             session=self.session,
546
             session=self.session,
547
             config=self.app_config,
547
             config=self.app_config,
548
         )
548
         )
549
-        c = api.create(ContentType.Folder, workspace, None, 'parent', '', True)
549
+        c = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'parent', '', True)
550
         with new_revision(
550
         with new_revision(
551
             session=self.session,
551
             session=self.session,
552
             tm=transaction.manager,
552
             tm=transaction.manager,
591
             session=self.session,
591
             session=self.session,
592
             config=self.app_config,
592
             config=self.app_config,
593
         )
593
         )
594
-        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
594
+        p = api.create(CONTENT_TYPES.Page.slug, workspace, None, 'this_is_a_page')
595
         c = api.create_comment(workspace, p, 'this is the comment', True)
595
         c = api.create_comment(workspace, p, 'this is the comment', True)
596
 
596
 
597
         eq_(Content, c.__class__)
597
         eq_(Content, c.__class__)
598
         eq_(p.content_id, c.parent_id)
598
         eq_(p.content_id, c.parent_id)
599
         eq_(user, c.owner)
599
         eq_(user, c.owner)
600
         eq_(workspace, c.workspace)
600
         eq_(workspace, c.workspace)
601
-        eq_(ContentType.Comment, c.type)
601
+        eq_(CONTENT_TYPES.Comment.slug, c.type)
602
         eq_('this is the comment', c.description)
602
         eq_('this is the comment', c.description)
603
         eq_('', c.label)
603
         eq_('', c.label)
604
         eq_(ActionDescription.COMMENT, c.revision_type)
604
         eq_(ActionDescription.COMMENT, c.revision_type)
652
             config=self.app_config,
652
             config=self.app_config,
653
         )
653
         )
654
         foldera = api.create(
654
         foldera = api.create(
655
-            ContentType.Folder,
655
+            CONTENT_TYPES.Folder.slug,
656
             workspace,
656
             workspace,
657
             None,
657
             None,
658
             'folder a',
658
             'folder a',
661
         )
661
         )
662
         with self.session.no_autoflush:
662
         with self.session.no_autoflush:
663
             text_file = api.create(
663
             text_file = api.create(
664
-                content_type=ContentType.File,
664
+                content_type_slug=CONTENT_TYPES.File.slug,
665
                 workspace=workspace,
665
                 workspace=workspace,
666
                 parent=foldera,
666
                 parent=foldera,
667
                 label='test_file',
667
                 label='test_file',
689
             save_now=True
689
             save_now=True
690
         )
690
         )
691
         folderb = api2.create(
691
         folderb = api2.create(
692
-            ContentType.Folder,
692
+            CONTENT_TYPES.Folder.slug,
693
             workspace2,
693
             workspace2,
694
             None,
694
             None,
695
             'folder b',
695
             'folder b',
773
             config=self.app_config,
773
             config=self.app_config,
774
         )
774
         )
775
         foldera = api.create(
775
         foldera = api.create(
776
-            ContentType.Folder,
776
+            CONTENT_TYPES.Folder.slug,
777
             workspace,
777
             workspace,
778
             None,
778
             None,
779
             'folder a',
779
             'folder a',
782
         )
782
         )
783
         with self.session.no_autoflush:
783
         with self.session.no_autoflush:
784
             text_file = api.create(
784
             text_file = api.create(
785
-                content_type=ContentType.File,
785
+                content_type_slug=CONTENT_TYPES.File.slug,
786
                 workspace=workspace,
786
                 workspace=workspace,
787
                 parent=foldera,
787
                 parent=foldera,
788
                 label='test_file',
788
                 label='test_file',
810
             save_now=True
810
             save_now=True
811
         )
811
         )
812
         folderb = api2.create(
812
         folderb = api2.create(
813
-            ContentType.Folder,
813
+            CONTENT_TYPES.Folder.slug,
814
             workspace2,
814
             workspace2,
815
             None,
815
             None,
816
             'folder b',
816
             'folder b',
891
             config=self.app_config,
891
             config=self.app_config,
892
         )
892
         )
893
         foldera = api.create(
893
         foldera = api.create(
894
-            ContentType.Folder,
894
+            CONTENT_TYPES.Folder.slug,
895
             workspace,
895
             workspace,
896
             None,
896
             None,
897
             'folder a',
897
             'folder a',
900
         )
900
         )
901
         with self.session.no_autoflush:
901
         with self.session.no_autoflush:
902
             text_file = api.create(
902
             text_file = api.create(
903
-                content_type=ContentType.File,
903
+                content_type_slug=CONTENT_TYPES.File.slug,
904
                 workspace=workspace,
904
                 workspace=workspace,
905
                 parent=foldera,
905
                 parent=foldera,
906
                 label='test_file',
906
                 label='test_file',
1014
 
1014
 
1015
         # Creates page_1 & page_2 in workspace 1
1015
         # Creates page_1 & page_2 in workspace 1
1016
         #     and page_3 & page_4 in workspace 2
1016
         #     and page_3 & page_4 in workspace 2
1017
-        page_1 = cont_api_a.create(ContentType.Page, workspace1, None,
1017
+        page_1 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace1, None,
1018
                                    'this is a page', do_save=True)
1018
                                    'this is a page', do_save=True)
1019
-        page_2 = cont_api_a.create(ContentType.Page, workspace1, None,
1019
+        page_2 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace1, None,
1020
                                    'this is page1', do_save=True)
1020
                                    'this is page1', do_save=True)
1021
-        page_3 = cont_api_a.create(ContentType.Thread, workspace2, None,
1021
+        page_3 = cont_api_a.create(CONTENT_TYPES.Thread.slug, workspace2, None,
1022
                                    'this is page2', do_save=True)
1022
                                    'this is page2', do_save=True)
1023
-        page_4 = cont_api_a.create(ContentType.File, workspace2, None,
1023
+        page_4 = cont_api_a.create(CONTENT_TYPES.File.slug, workspace2, None,
1024
                                    'this is page3', do_save=True)
1024
                                    'this is page3', do_save=True)
1025
 
1025
 
1026
         for rev in page_1.revisions:
1026
         for rev in page_1.revisions:
1118
             config=self.app_config,
1118
             config=self.app_config,
1119
         )
1119
         )
1120
 
1120
 
1121
-        page_1 = cont_api_a.create(ContentType.Page, workspace, None,
1121
+        page_1 = cont_api_a.create(CONTENT_TYPES.Page.slug, workspace, None,
1122
                                    'this is a page', do_save=True)
1122
                                    'this is a page', do_save=True)
1123
 
1123
 
1124
         for rev in page_1.revisions:
1124
         for rev in page_1.revisions:
1187
         )
1187
         )
1188
 
1188
 
1189
         page_2 = cont_api_a.create(
1189
         page_2 = cont_api_a.create(
1190
-            ContentType.Page,
1190
+            CONTENT_TYPES.Page.slug,
1191
             workspace,
1191
             workspace,
1192
             None,
1192
             None,
1193
             'this is page1',
1193
             'this is page1',
1194
             do_save=True
1194
             do_save=True
1195
         )
1195
         )
1196
         page_3 = cont_api_a.create(
1196
         page_3 = cont_api_a.create(
1197
-            ContentType.Thread,
1197
+            CONTENT_TYPES.Thread.slug,
1198
             workspace,
1198
             workspace,
1199
             None,
1199
             None,
1200
             'this is page2',
1200
             'this is page2',
1201
             do_save=True
1201
             do_save=True
1202
         )
1202
         )
1203
         page_4 = cont_api_a.create(
1203
         page_4 = cont_api_a.create(
1204
-            ContentType.File,
1204
+            CONTENT_TYPES.File.slug,
1205
             workspace,
1205
             workspace,
1206
             None,
1206
             None,
1207
             'this is page3',
1207
             'this is page3',
1285
         )
1285
         )
1286
 
1286
 
1287
         p = api.create(
1287
         p = api.create(
1288
-            content_type=ContentType.Page,
1288
+            content_type_slug=CONTENT_TYPES.Page.slug,
1289
             workspace=workspace,
1289
             workspace=workspace,
1290
             parent=None,
1290
             parent=None,
1291
             label='this_is_a_page',
1291
             label='this_is_a_page',
1312
             config=self.app_config,
1312
             config=self.app_config,
1313
         )
1313
         )
1314
 
1314
 
1315
-        content = api.get_one(pcid, ContentType.Any, workspace)
1315
+        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1316
         eq_(u1id, content.owner_id)
1316
         eq_(u1id, content.owner_id)
1317
         eq_(poid, content.owner_id)
1317
         eq_(poid, content.owner_id)
1318
 
1318
 
1326
             session=self.session,
1326
             session=self.session,
1327
             config=self.app_config,
1327
             config=self.app_config,
1328
         )
1328
         )
1329
-        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1329
+        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1330
         with new_revision(
1330
         with new_revision(
1331
            session=self.session,
1331
            session=self.session,
1332
            tm=transaction.manager,
1332
            tm=transaction.manager,
1353
             config=self.app_config,
1353
             config=self.app_config,
1354
         )
1354
         )
1355
 
1355
 
1356
-        updated = api.get_one(pcid, ContentType.Any, workspace)
1356
+        updated = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1357
         eq_(u2id, updated.owner_id,
1357
         eq_(u2id, updated.owner_id,
1358
             'the owner id should be {} (found {})'.format(u2id,
1358
             'the owner id should be {} (found {})'.format(u2id,
1359
                                                           updated.owner_id))
1359
                                                           updated.owner_id))
1412
         )
1412
         )
1413
         with self.session.no_autoflush:
1413
         with self.session.no_autoflush:
1414
             page = api.create(
1414
             page = api.create(
1415
-                content_type=ContentType.Page,
1415
+                content_type_slug=CONTENT_TYPES.Page.slug,
1416
                 workspace=workspace,
1416
                 workspace=workspace,
1417
                 label="same_content",
1417
                 label="same_content",
1418
                 do_save=False
1418
                 do_save=False
1426
             session=self.session,
1426
             session=self.session,
1427
             config=self.app_config,
1427
             config=self.app_config,
1428
         )
1428
         )
1429
-        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1429
+        content2 = api2.get_one(page.content_id, CONTENT_TYPES.Any_SLUG, workspace)
1430
         with new_revision(
1430
         with new_revision(
1431
            session=self.session,
1431
            session=self.session,
1432
            tm=transaction.manager,
1432
            tm=transaction.manager,
1495
             config=self.app_config,
1495
             config=self.app_config,
1496
         )
1496
         )
1497
         p = api.create(
1497
         p = api.create(
1498
-            content_type=ContentType.File,
1498
+            content_type_slug=CONTENT_TYPES.File.slug,
1499
             workspace=workspace,
1499
             workspace=workspace,
1500
             parent=None,
1500
             parent=None,
1501
             label='this_is_a_page',
1501
             label='this_is_a_page',
1524
             config=self.app_config,
1524
             config=self.app_config,
1525
         )
1525
         )
1526
 
1526
 
1527
-        content = api.get_one(pcid, ContentType.Any, workspace)
1527
+        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1528
         eq_(u1id, content.owner_id)
1528
         eq_(u1id, content.owner_id)
1529
         eq_(poid, content.owner_id)
1529
         eq_(poid, content.owner_id)
1530
 
1530
 
1538
             session=self.session,
1538
             session=self.session,
1539
             config=self.app_config,
1539
             config=self.app_config,
1540
         )
1540
         )
1541
-        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1541
+        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1542
         with new_revision(
1542
         with new_revision(
1543
             session=self.session,
1543
             session=self.session,
1544
             tm=transaction.manager,
1544
             tm=transaction.manager,
1561
             config=self.app_config,
1561
             config=self.app_config,
1562
         ).get_one(wid)
1562
         ).get_one(wid)
1563
 
1563
 
1564
-        updated = api.get_one(pcid, ContentType.Any, workspace)
1564
+        updated = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1565
         eq_(u2id, updated.owner_id,
1565
         eq_(u2id, updated.owner_id,
1566
             'the owner id should be {} (found {})'.format(u2id,
1566
             'the owner id should be {} (found {})'.format(u2id,
1567
                                                           updated.owner_id))
1567
                                                           updated.owner_id))
1622
         )
1622
         )
1623
         with self.session.no_autoflush:
1623
         with self.session.no_autoflush:
1624
             page = api.create(
1624
             page = api.create(
1625
-                content_type=ContentType.Page,
1625
+                content_type_slug=CONTENT_TYPES.Page.slug,
1626
                 workspace=workspace,
1626
                 workspace=workspace,
1627
                 label="same_content",
1627
                 label="same_content",
1628
                 do_save=False
1628
                 do_save=False
1641
             session=self.session,
1641
             session=self.session,
1642
             config=self.app_config,
1642
             config=self.app_config,
1643
         )
1643
         )
1644
-        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1644
+        content2 = api2.get_one(page.content_id, CONTENT_TYPES.Any_SLUG, workspace)
1645
         with new_revision(
1645
         with new_revision(
1646
             session=self.session,
1646
             session=self.session,
1647
             tm=transaction.manager,
1647
             tm=transaction.manager,
1713
             config=self.app_config,
1713
             config=self.app_config,
1714
         )
1714
         )
1715
         p = api.create(
1715
         p = api.create(
1716
-            content_type=ContentType.File,
1716
+            content_type_slug=CONTENT_TYPES.File.slug,
1717
             workspace=workspace,
1717
             workspace=workspace,
1718
             parent=None,
1718
             parent=None,
1719
             label='this_is_a_page',
1719
             label='this_is_a_page',
1741
             config=self.app_config,
1741
             config=self.app_config,
1742
         ).get_one(wid)
1742
         ).get_one(wid)
1743
 
1743
 
1744
-        content = api.get_one(pcid, ContentType.Any, workspace)
1744
+        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1745
         eq_(u1id, content.owner_id)
1745
         eq_(u1id, content.owner_id)
1746
         eq_(poid, content.owner_id)
1746
         eq_(poid, content.owner_id)
1747
 
1747
 
1757
             config=self.app_config,
1757
             config=self.app_config,
1758
             show_archived=True,
1758
             show_archived=True,
1759
         )
1759
         )
1760
-        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1760
+        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1761
         with new_revision(
1761
         with new_revision(
1762
                 session=self.session,
1762
                 session=self.session,
1763
                 tm=transaction.manager,
1763
                 tm=transaction.manager,
1796
             show_archived=True,
1796
             show_archived=True,
1797
         )
1797
         )
1798
 
1798
 
1799
-        updated = api2.get_one(pcid, ContentType.Any, workspace)
1799
+        updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1800
         eq_(u2id, updated.owner_id,
1800
         eq_(u2id, updated.owner_id,
1801
             'the owner id should be {} (found {})'.format(u2id,
1801
             'the owner id should be {} (found {})'.format(u2id,
1802
                                                           updated.owner_id))
1802
                                                           updated.owner_id))
1805
 
1805
 
1806
         ####
1806
         ####
1807
 
1807
 
1808
-        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1808
+        updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1809
         with new_revision(
1809
         with new_revision(
1810
             session=self.session,
1810
             session=self.session,
1811
             tm=transaction.manager,
1811
             tm=transaction.manager,
1874
             show_deleted=True,
1874
             show_deleted=True,
1875
         )
1875
         )
1876
         p = api.create(
1876
         p = api.create(
1877
-            content_type=ContentType.File,
1877
+            content_type_slug=CONTENT_TYPES.File.slug,
1878
             workspace=workspace,
1878
             workspace=workspace,
1879
             parent=None,
1879
             parent=None,
1880
             label='this_is_a_page',
1880
             label='this_is_a_page',
1900
             config=self.app_config,
1900
             config=self.app_config,
1901
         ).get_one(wid)
1901
         ).get_one(wid)
1902
 
1902
 
1903
-        content = api.get_one(pcid, ContentType.Any, workspace)
1903
+        content = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1904
         eq_(u1id, content.owner_id)
1904
         eq_(u1id, content.owner_id)
1905
         eq_(poid, content.owner_id)
1905
         eq_(poid, content.owner_id)
1906
 
1906
 
1915
             config=self.app_config,
1915
             config=self.app_config,
1916
             show_deleted=True,
1916
             show_deleted=True,
1917
         )
1917
         )
1918
-        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1918
+        content2 = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1919
         with new_revision(
1919
         with new_revision(
1920
                 session=self.session,
1920
                 session=self.session,
1921
                 tm=transaction.manager,
1921
                 tm=transaction.manager,
1956
             show_deleted=True
1956
             show_deleted=True
1957
         )
1957
         )
1958
 
1958
 
1959
-        updated = api2.get_one(pcid, ContentType.Any, workspace)
1959
+        updated = api2.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1960
         eq_(u2id, updated.owner_id,
1960
         eq_(u2id, updated.owner_id,
1961
             'the owner id should be {} (found {})'.format(u2id,
1961
             'the owner id should be {} (found {})'.format(u2id,
1962
                                                           updated.owner_id))
1962
                                                           updated.owner_id))
1965
 
1965
 
1966
         ####
1966
         ####
1967
 
1967
 
1968
-        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1968
+        updated2 = api.get_one(pcid, CONTENT_TYPES.Any_SLUG, workspace)
1969
         with new_revision(
1969
         with new_revision(
1970
             tm=transaction.manager,
1970
             tm=transaction.manager,
1971
             session=self.session,
1971
             session=self.session,
2016
             session=self.session,
2016
             session=self.session,
2017
             config=self.app_config,
2017
             config=self.app_config,
2018
         )
2018
         )
2019
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
2020
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2019
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
2020
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2021
         # creation order test
2021
         # creation order test
2022
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2023
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2022
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2023
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2024
         # update order test
2024
         # update order test
2025
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2026
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2025
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2026
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2027
         with new_revision(
2027
         with new_revision(
2028
             session=self.session,
2028
             session=self.session,
2029
             tm=transaction.manager,
2029
             tm=transaction.manager,
2032
             firstly_created_but_recently_updated.description = 'Just an update'
2032
             firstly_created_but_recently_updated.description = 'Just an update'
2033
         api.save(firstly_created_but_recently_updated)
2033
         api.save(firstly_created_but_recently_updated)
2034
         # comment change order
2034
         # comment change order
2035
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2036
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2035
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2036
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2037
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2037
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2038
 
2038
 
2039
-        content_workspace_2 = api.create(ContentType.Page, workspace2 ,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
2039
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2 ,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
2040
         last_actives = api.get_last_active()
2040
         last_actives = api.get_last_active()
2041
         assert len(last_actives) == 9
2041
         assert len(last_actives) == 9
2042
         # workspace_2 content
2042
         # workspace_2 content
2088
             session=self.session,
2088
             session=self.session,
2089
             config=self.app_config,
2089
             config=self.app_config,
2090
         )
2090
         )
2091
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2091
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2092
         # creation order test
2092
         # creation order test
2093
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2094
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2093
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2094
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2095
         # update order test
2095
         # update order test
2096
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2097
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2096
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2097
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2098
         with new_revision(
2098
         with new_revision(
2099
             session=self.session,
2099
             session=self.session,
2100
             tm=transaction.manager,
2100
             tm=transaction.manager,
2103
             firstly_created_but_recently_updated.description = 'Just an update'
2103
             firstly_created_but_recently_updated.description = 'Just an update'
2104
         api.save(firstly_created_but_recently_updated)
2104
         api.save(firstly_created_but_recently_updated)
2105
         # comment change order
2105
         # comment change order
2106
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2107
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2106
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2107
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2108
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2108
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2109
 
2109
 
2110
         last_actives = api.get_last_active(workspace=workspace)
2110
         last_actives = api.get_last_active(workspace=workspace)
2153
             session=self.session,
2153
             session=self.session,
2154
             config=self.app_config,
2154
             config=self.app_config,
2155
         )
2155
         )
2156
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2156
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2157
         # creation order test
2157
         # creation order test
2158
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2159
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2158
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2159
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2160
         # update order test
2160
         # update order test
2161
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2162
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2161
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2162
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2163
         with new_revision(
2163
         with new_revision(
2164
             session=self.session,
2164
             session=self.session,
2165
             tm=transaction.manager,
2165
             tm=transaction.manager,
2168
             firstly_created_but_recently_updated.description = 'Just an update'
2168
             firstly_created_but_recently_updated.description = 'Just an update'
2169
         api.save(firstly_created_but_recently_updated)
2169
         api.save(firstly_created_but_recently_updated)
2170
         # comment change order
2170
         # comment change order
2171
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2172
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2171
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2172
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2173
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2173
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2174
 
2174
 
2175
         selected_contents = [
2175
         selected_contents = [
2228
             session=self.session,
2228
             session=self.session,
2229
             config=self.app_config,
2229
             config=self.app_config,
2230
         )
2230
         )
2231
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2231
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2232
         # creation order test
2232
         # creation order test
2233
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2234
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2233
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2234
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2235
         # update order test
2235
         # update order test
2236
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2237
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2236
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2237
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2238
         with new_revision(
2238
         with new_revision(
2239
             session=self.session,
2239
             session=self.session,
2240
             tm=transaction.manager,
2240
             tm=transaction.manager,
2243
             firstly_created_but_recently_updated.description = 'Just an update'
2243
             firstly_created_but_recently_updated.description = 'Just an update'
2244
         api.save(firstly_created_but_recently_updated)
2244
         api.save(firstly_created_but_recently_updated)
2245
         # comment change order
2245
         # comment change order
2246
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2247
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2246
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2247
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2248
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2248
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2249
 
2249
 
2250
         last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=datetime.datetime.now())  # nopep8
2250
         last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=datetime.datetime.now())  # nopep8
2309
             session=self.session,
2309
             session=self.session,
2310
             config=self.app_config,
2310
             config=self.app_config,
2311
         )
2311
         )
2312
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2312
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2313
         # creation order test
2313
         # creation order test
2314
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2315
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2314
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2315
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
2316
         # update order test
2316
         # update order test
2317
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2318
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2317
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
2318
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
2319
         with new_revision(
2319
         with new_revision(
2320
             session=self.session,
2320
             session=self.session,
2321
             tm=transaction.manager,
2321
             tm=transaction.manager,
2324
             firstly_created_but_recently_updated.description = 'Just an update'
2324
             firstly_created_but_recently_updated.description = 'Just an update'
2325
         api.save(firstly_created_but_recently_updated)
2325
         api.save(firstly_created_but_recently_updated)
2326
         # comment change order
2326
         # comment change order
2327
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2328
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2327
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
2328
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
2329
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2329
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2330
 
2330
 
2331
         last_actives = api.get_last_active(workspace=workspace2)
2331
         last_actives = api.get_last_active(workspace=workspace2)
2366
             session=self.session,
2366
             session=self.session,
2367
             config=self.app_config,
2367
             config=self.app_config,
2368
         )
2368
         )
2369
-        a = api.create(ContentType.Folder, workspace, None,
2369
+        a = api.create(CONTENT_TYPES.Folder.slug, workspace, None,
2370
                        'this is randomized folder', '', True)
2370
                        'this is randomized folder', '', True)
2371
-        p = api.create(ContentType.Page, workspace, a,
2371
+        p = api.create(CONTENT_TYPES.Page.slug, workspace, a,
2372
                        'this is randomized label content', '', True)
2372
                        'this is randomized label content', '', True)
2373
 
2373
 
2374
         with new_revision(
2374
         with new_revision(
2422
             session=self.session,
2422
             session=self.session,
2423
             config=self.app_config,
2423
             config=self.app_config,
2424
         )
2424
         )
2425
-        a = api.create(ContentType.Folder, workspace, None,
2425
+        a = api.create(CONTENT_TYPES.Folder.slug, workspace, None,
2426
                        'this is randomized folder', '', True)
2426
                        'this is randomized folder', '', True)
2427
-        p = api.create(ContentType.Page, workspace, a,
2427
+        p = api.create(CONTENT_TYPES.Page.slug, workspace, a,
2428
                        'this is dummy label content', '', True)
2428
                        'this is dummy label content', '', True)
2429
 
2429
 
2430
         with new_revision(
2430
         with new_revision(
2476
             config=self.app_config,
2476
             config=self.app_config,
2477
         )
2477
         )
2478
         a = api.create(
2478
         a = api.create(
2479
-            content_type=ContentType.Folder,
2479
+            content_type_slug=CONTENT_TYPES.Folder.slug,
2480
             workspace=workspace,
2480
             workspace=workspace,
2481
             parent=None,
2481
             parent=None,
2482
             label='this is randomized folder',
2482
             label='this is randomized folder',
2483
             do_save=True
2483
             do_save=True
2484
         )
2484
         )
2485
         p1 = api.create(
2485
         p1 = api.create(
2486
-            content_type=ContentType.Page,
2486
+            content_type_slug=CONTENT_TYPES.Page.slug,
2487
             workspace=workspace,
2487
             workspace=workspace,
2488
             parent=a,
2488
             parent=a,
2489
             label='this is dummy label content',
2489
             label='this is dummy label content',
2490
             do_save=True
2490
             do_save=True
2491
         )
2491
         )
2492
         p2 = api.create(
2492
         p2 = api.create(
2493
-            content_type=ContentType.Page,
2493
+            content_type_slug=CONTENT_TYPES.Page.slug,
2494
             workspace=workspace,
2494
             workspace=workspace,
2495
             parent=a,
2495
             parent=a,
2496
             label='Hey ! Jon !',
2496
             label='Hey ! Jon !',
2540
         folder_1 = self._create_content_and_test(
2540
         folder_1 = self._create_content_and_test(
2541
             'folder_1',
2541
             'folder_1',
2542
             workspace=workspace,
2542
             workspace=workspace,
2543
-            type=ContentType.Folder
2543
+            type=CONTENT_TYPES.Folder.slug
2544
         )
2544
         )
2545
         folder_2 = self._create_content_and_test(
2545
         folder_2 = self._create_content_and_test(
2546
             'folder_2',
2546
             'folder_2',
2547
             workspace=workspace,
2547
             workspace=workspace,
2548
-            type=ContentType.Folder
2548
+            type=CONTENT_TYPES.Folder.slug
2549
         )
2549
         )
2550
         page_1 = self._create_content_and_test(
2550
         page_1 = self._create_content_and_test(
2551
             'foo', workspace=workspace,
2551
             'foo', workspace=workspace,
2552
-            type=ContentType.Page,
2552
+            type=CONTENT_TYPES.Page.slug,
2553
             parent=folder_1
2553
             parent=folder_1
2554
         )
2554
         )
2555
         page_2 = self._create_content_and_test(
2555
         page_2 = self._create_content_and_test(
2556
             'bar',
2556
             'bar',
2557
             workspace=workspace,
2557
             workspace=workspace,
2558
-            type=ContentType.Page,
2558
+            type=CONTENT_TYPES.Page.slug,
2559
             parent=folder_2
2559
             parent=folder_2
2560
         )
2560
         )
2561
 
2561
 
2636
             session=self.session,
2636
             session=self.session,
2637
             config=self.app_config,
2637
             config=self.app_config,
2638
         ).create(
2638
         ).create(
2639
-            content_type=ContentType.Page,
2639
+            content_type_slug=CONTENT_TYPES.Page.slug,
2640
             workspace=bob_workspace,
2640
             workspace=bob_workspace,
2641
             label='bob_page',
2641
             label='bob_page',
2642
             do_save=True,
2642
             do_save=True,
2647
             session=self.session,
2647
             session=self.session,
2648
             config=self.app_config,
2648
             config=self.app_config,
2649
         ).create(
2649
         ).create(
2650
-            content_type=ContentType.Page,
2650
+            content_type_slug=CONTENT_TYPES.Page.slug,
2651
             workspace=admin_workspace,
2651
             workspace=admin_workspace,
2652
             label='admin_page',
2652
             label='admin_page',
2653
             do_save=True,
2653
             do_save=True,

+ 6 - 6
backend/tracim_backend/tests/models/test_content.py View File

15
 from tracim_backend.models import User
15
 from tracim_backend.models import User
16
 from tracim_backend.models.data import ActionDescription
16
 from tracim_backend.models.data import ActionDescription
17
 from tracim_backend.models.data import ContentRevisionRO
17
 from tracim_backend.models.data import ContentRevisionRO
18
-from tracim_backend.models.data import ContentType
18
+from tracim_backend.models.contents import CONTENT_TYPES
19
 from tracim_backend.models.data import Workspace
19
 from tracim_backend.models.data import Workspace
20
 from tracim_backend.tests import StandardTest
20
 from tracim_backend.tests import StandardTest
21
 
21
 
95
 
95
 
96
         content1_from_api = api.get_one(
96
         content1_from_api = api.get_one(
97
             content1.id,
97
             content1.id,
98
-            ContentType.Page,
98
+            CONTENT_TYPES.Page.slug,
99
             workspace1
99
             workspace1
100
         )
100
         )
101
 
101
 
196
         first_content = self._create_content(
196
         first_content = self._create_content(
197
             owner=user_admin,
197
             owner=user_admin,
198
             workspace=workspace,
198
             workspace=workspace,
199
-            type=ContentType.Page,
199
+            type=CONTENT_TYPES.Page.slug,
200
             label='TEST_CONTENT_1',
200
             label='TEST_CONTENT_1',
201
             description='TEST_CONTENT_DESCRIPTION_1',
201
             description='TEST_CONTENT_DESCRIPTION_1',
202
             revision_type=ActionDescription.CREATION,
202
             revision_type=ActionDescription.CREATION,
221
         second_content = self._create_content(
221
         second_content = self._create_content(
222
             owner=user_admin,
222
             owner=user_admin,
223
             workspace=workspace,
223
             workspace=workspace,
224
-            type=ContentType.Page,
224
+            type=CONTENT_TYPES.Page.slug,
225
             label='TEST_CONTENT_2',
225
             label='TEST_CONTENT_2',
226
             description='TEST_CONTENT_DESCRIPTION_2',
226
             description='TEST_CONTENT_DESCRIPTION_2',
227
             revision_type=ActionDescription.CREATION
227
             revision_type=ActionDescription.CREATION
268
         created_content = self._create_content(
268
         created_content = self._create_content(
269
             owner=user_admin,
269
             owner=user_admin,
270
             workspace=workspace,
270
             workspace=workspace,
271
-            type=ContentType.Page,
271
+            type=CONTENT_TYPES.Page.slug,
272
             label='TEST_CONTENT_%s' % key,
272
             label='TEST_CONTENT_%s' % key,
273
             description='TEST_CONTENT_DESCRIPTION_%s' % key,
273
             description='TEST_CONTENT_DESCRIPTION_%s' % key,
274
             revision_type=ActionDescription.CREATION
274
             revision_type=ActionDescription.CREATION
308
         content = self._create_content(
308
         content = self._create_content(
309
             owner=user_admin,
309
             owner=user_admin,
310
             workspace=workspace,
310
             workspace=workspace,
311
-            type=ContentType.File,
311
+            type=CONTENT_TYPES.File.slug,
312
             label='TEST_CONTENT_1',
312
             label='TEST_CONTENT_1',
313
             description='TEST_CONTENT_DESCRIPTION_1',
313
             description='TEST_CONTENT_DESCRIPTION_1',
314
             revision_type=ActionDescription.CREATION,
314
             revision_type=ActionDescription.CREATION,

+ 4 - 3
backend/tracim_backend/tests/models/test_content_revision.py View File

5
 
5
 
6
 from tracim_backend.models import ContentRevisionRO
6
 from tracim_backend.models import ContentRevisionRO
7
 from tracim_backend.models import User
7
 from tracim_backend.models import User
8
-from tracim_backend.models.data import ContentType
8
+from tracim_backend.models.contents import CONTENT_TYPES
9
 from tracim_backend.tests import DefaultTest
9
 from tracim_backend.tests import DefaultTest
10
 from tracim_backend.tests import eq_
10
 from tracim_backend.tests import eq_
11
 
11
 
12
+
12
 class TestContentRevision(DefaultTest):
13
 class TestContentRevision(DefaultTest):
13
 
14
 
14
     def _new_from(self, revision):
15
     def _new_from(self, revision):
47
         folder = self._create_content_and_test(
48
         folder = self._create_content_and_test(
48
             name='folder_1',
49
             name='folder_1',
49
             workspace=workspace,
50
             workspace=workspace,
50
-            type=ContentType.Folder
51
+            type=CONTENT_TYPES.Folder.slug
51
         )
52
         )
52
         page = self._create_content_and_test(
53
         page = self._create_content_and_test(
53
             workspace=workspace,
54
             workspace=workspace,
54
             parent=folder,
55
             parent=folder,
55
             name='file_1',
56
             name='file_1',
56
             description='content of file_1',
57
             description='content of file_1',
57
-            type=ContentType.Page,
58
+            type=CONTENT_TYPES.Page.slug,
58
             owner=admin
59
             owner=admin
59
         )
60
         )
60
 
61
 

+ 5 - 5
backend/tracim_backend/views/contents_api/comment_controller.py View File

20
 from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
20
 from tracim_backend.views.core_api.schemas import WorkspaceAndContentIdPathSchema
21
 from tracim_backend.views.core_api.schemas import NoContentSchema
21
 from tracim_backend.views.core_api.schemas import NoContentSchema
22
 from tracim_backend.exceptions import EmptyCommentContentNotAllowed
22
 from tracim_backend.exceptions import EmptyCommentContentNotAllowed
23
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
23
+from tracim_backend.models.contents import CONTENT_TYPES
24
 from tracim_backend.models.revision_protection import new_revision
24
 from tracim_backend.models.revision_protection import new_revision
25
 from tracim_backend.models.data import UserRoleInWorkspace
25
 from tracim_backend.models.data import UserRoleInWorkspace
26
 
26
 
47
         )
47
         )
48
         content = api.get_one(
48
         content = api.get_one(
49
             hapic_data.path.content_id,
49
             hapic_data.path.content_id,
50
-            content_type=ContentType.Any
50
+            content_type=CONTENT_TYPES.Any_SLUG
51
         )
51
         )
52
         comments = content.get_comments()
52
         comments = content.get_comments()
53
         comments.sort(key=lambda comment: comment.created)
53
         comments.sort(key=lambda comment: comment.created)
74
         )
74
         )
75
         content = api.get_one(
75
         content = api.get_one(
76
             hapic_data.path.content_id,
76
             hapic_data.path.content_id,
77
-            content_type=ContentType.Any
77
+            content_type=CONTENT_TYPES.Any_SLUG
78
         )
78
         )
79
         comment = api.create_comment(
79
         comment = api.create_comment(
80
             content.workspace,
80
             content.workspace,
109
         workspace = wapi.get_one(hapic_data.path.workspace_id)
109
         workspace = wapi.get_one(hapic_data.path.workspace_id)
110
         parent = api.get_one(
110
         parent = api.get_one(
111
             hapic_data.path.content_id,
111
             hapic_data.path.content_id,
112
-            content_type=ContentType.Any,
112
+            content_type=CONTENT_TYPES.Any_SLUG,
113
             workspace=workspace
113
             workspace=workspace
114
         )
114
         )
115
         comment = api.get_one(
115
         comment = api.get_one(
116
             hapic_data.path.comment_id,
116
             hapic_data.path.comment_id,
117
-            content_type=ContentType.Comment,
117
+            content_type=CONTENT_TYPES.Comment.slug,
118
             workspace=workspace,
118
             workspace=workspace,
119
             parent=parent,
119
             parent=parent,
120
         )
120
         )

+ 14 - 14
backend/tracim_backend/views/contents_api/file_controller.py View File

32
 from tracim_backend.models.data import UserRoleInWorkspace
32
 from tracim_backend.models.data import UserRoleInWorkspace
33
 from tracim_backend.models.context_models import ContentInContext
33
 from tracim_backend.models.context_models import ContentInContext
34
 from tracim_backend.models.context_models import RevisionInContext
34
 from tracim_backend.models.context_models import RevisionInContext
35
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
35
+from tracim_backend.models.contents import CONTENT_TYPES
36
 from tracim_backend.models.contents import file_type
36
 from tracim_backend.models.contents import file_type
37
 from tracim_backend.models.revision_protection import new_revision
37
 from tracim_backend.models.revision_protection import new_revision
38
 from tracim_backend.exceptions import EmptyLabelNotAllowed
38
 from tracim_backend.exceptions import EmptyLabelNotAllowed
67
         )
67
         )
68
         content = api.get_one(
68
         content = api.get_one(
69
             hapic_data.path.content_id,
69
             hapic_data.path.content_id,
70
-            content_type=ContentType.Any
70
+            content_type=CONTENT_TYPES.Any_SLUG
71
         )
71
         )
72
         file = request.POST['files']
72
         file = request.POST['files']
73
         with new_revision(
73
         with new_revision(
101
         )
101
         )
102
         content = api.get_one(
102
         content = api.get_one(
103
             hapic_data.path.content_id,
103
             hapic_data.path.content_id,
104
-            content_type=ContentType.Any
104
+            content_type=CONTENT_TYPES.Any_SLUG
105
         )
105
         )
106
         file = DepotManager.get().get(content.depot_file)
106
         file = DepotManager.get().get(content.depot_file)
107
         response = request.response
107
         response = request.response
126
         )
126
         )
127
         content = api.get_one(
127
         content = api.get_one(
128
             hapic_data.path.content_id,
128
             hapic_data.path.content_id,
129
-            content_type=ContentType.Any
129
+            content_type=CONTENT_TYPES.Any_SLUG
130
         )
130
         )
131
         revision = api.get_one_revision(
131
         revision = api.get_one_revision(
132
             revision_id=hapic_data.path.revision_id,
132
             revision_id=hapic_data.path.revision_id,
160
         )
160
         )
161
         content = api.get_one(
161
         content = api.get_one(
162
             hapic_data.path.content_id,
162
             hapic_data.path.content_id,
163
-            content_type=ContentType.Any
163
+            content_type=CONTENT_TYPES.Any_SLUG
164
         )
164
         )
165
         pdf_preview_path = api.get_pdf_preview_path(
165
         pdf_preview_path = api.get_pdf_preview_path(
166
             content.content_id,
166
             content.content_id,
187
         )
187
         )
188
         content = api.get_one(
188
         content = api.get_one(
189
             hapic_data.path.content_id,
189
             hapic_data.path.content_id,
190
-            content_type=ContentType.Any
190
+            content_type=CONTENT_TYPES.Any_SLUG
191
         )
191
         )
192
         pdf_preview_path = api.get_full_pdf_preview_path(content.revision_id)
192
         pdf_preview_path = api.get_full_pdf_preview_path(content.revision_id)
193
         return FileResponse(pdf_preview_path)
193
         return FileResponse(pdf_preview_path)
211
         )
211
         )
212
         content = api.get_one(
212
         content = api.get_one(
213
             hapic_data.path.content_id,
213
             hapic_data.path.content_id,
214
-            content_type=ContentType.Any
214
+            content_type=CONTENT_TYPES.Any_SLUG
215
         )
215
         )
216
         revision = api.get_one_revision(
216
         revision = api.get_one_revision(
217
             revision_id=hapic_data.path.revision_id,
217
             revision_id=hapic_data.path.revision_id,
244
         )
244
         )
245
         content = api.get_one(
245
         content = api.get_one(
246
             hapic_data.path.content_id,
246
             hapic_data.path.content_id,
247
-            content_type=ContentType.Any
247
+            content_type=CONTENT_TYPES.Any_SLUG
248
         )
248
         )
249
         allowed_dim = api.get_jpg_preview_allowed_dim()
249
         allowed_dim = api.get_jpg_preview_allowed_dim()
250
         jpg_preview_path = api.get_jpg_preview_path(
250
         jpg_preview_path = api.get_jpg_preview_path(
276
         )
276
         )
277
         content = api.get_one(
277
         content = api.get_one(
278
             hapic_data.path.content_id,
278
             hapic_data.path.content_id,
279
-            content_type=ContentType.Any
279
+            content_type=CONTENT_TYPES.Any_SLUG
280
         )
280
         )
281
         jpg_preview_path = api.get_jpg_preview_path(
281
         jpg_preview_path = api.get_jpg_preview_path(
282
             content_id=content.content_id,
282
             content_id=content.content_id,
307
         )
307
         )
308
         content = api.get_one(
308
         content = api.get_one(
309
             hapic_data.path.content_id,
309
             hapic_data.path.content_id,
310
-            content_type=ContentType.Any
310
+            content_type=CONTENT_TYPES.Any_SLUG
311
         )
311
         )
312
         revision = api.get_one_revision(
312
         revision = api.get_one_revision(
313
             revision_id=hapic_data.path.revision_id,
313
             revision_id=hapic_data.path.revision_id,
358
         )
358
         )
359
         content = api.get_one(
359
         content = api.get_one(
360
             hapic_data.path.content_id,
360
             hapic_data.path.content_id,
361
-            content_type=ContentType.Any
361
+            content_type=CONTENT_TYPES.Any_SLUG
362
         )
362
         )
363
         return api.get_content_in_context(content)
363
         return api.get_content_in_context(content)
364
 
364
 
381
         )
381
         )
382
         content = api.get_one(
382
         content = api.get_one(
383
             hapic_data.path.content_id,
383
             hapic_data.path.content_id,
384
-            content_type=ContentType.Any
384
+            content_type=CONTENT_TYPES.Any_SLUG
385
         )
385
         )
386
         with new_revision(
386
         with new_revision(
387
                 session=request.dbsession,
387
                 session=request.dbsession,
419
         )
419
         )
420
         content = api.get_one(
420
         content = api.get_one(
421
             hapic_data.path.content_id,
421
             hapic_data.path.content_id,
422
-            content_type=ContentType.Any
422
+            content_type=CONTENT_TYPES.Any_SLUG
423
         )
423
         )
424
         revisions = content.revisions
424
         revisions = content.revisions
425
         return [
425
         return [
446
         )
446
         )
447
         content = api.get_one(
447
         content = api.get_one(
448
             hapic_data.path.content_id,
448
             hapic_data.path.content_id,
449
-            content_type=ContentType.Any
449
+            content_type=CONTENT_TYPES.Any_SLUG
450
         )
450
         )
451
         with new_revision(
451
         with new_revision(
452
                 session=request.dbsession,
452
                 session=request.dbsession,

+ 5 - 5
backend/tracim_backend/views/contents_api/html_document_controller.py View File

26
 from tracim_backend.exceptions import EmptyLabelNotAllowed
26
 from tracim_backend.exceptions import EmptyLabelNotAllowed
27
 from tracim_backend.models.context_models import ContentInContext
27
 from tracim_backend.models.context_models import ContentInContext
28
 from tracim_backend.models.context_models import RevisionInContext
28
 from tracim_backend.models.context_models import RevisionInContext
29
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
29
+from tracim_backend.models.contents import CONTENT_TYPES
30
 from tracim_backend.models.contents import html_documents_type
30
 from tracim_backend.models.contents import html_documents_type
31
 from tracim_backend.models.revision_protection import new_revision
31
 from tracim_backend.models.revision_protection import new_revision
32
 
32
 
52
         )
52
         )
53
         content = api.get_one(
53
         content = api.get_one(
54
             hapic_data.path.content_id,
54
             hapic_data.path.content_id,
55
-            content_type=ContentType.Any
55
+            content_type=CONTENT_TYPES.Any_SLUG
56
         )
56
         )
57
         return api.get_content_in_context(content)
57
         return api.get_content_in_context(content)
58
 
58
 
75
         )
75
         )
76
         content = api.get_one(
76
         content = api.get_one(
77
             hapic_data.path.content_id,
77
             hapic_data.path.content_id,
78
-            content_type=ContentType.Any
78
+            content_type=CONTENT_TYPES.Any_SLUG
79
         )
79
         )
80
         with new_revision(
80
         with new_revision(
81
                 session=request.dbsession,
81
                 session=request.dbsession,
113
         )
113
         )
114
         content = api.get_one(
114
         content = api.get_one(
115
             hapic_data.path.content_id,
115
             hapic_data.path.content_id,
116
-            content_type=ContentType.Any
116
+            content_type=CONTENT_TYPES.Any_SLUG
117
         )
117
         )
118
         revisions = content.revisions
118
         revisions = content.revisions
119
         return [
119
         return [
144
         )
144
         )
145
         content = api.get_one(
145
         content = api.get_one(
146
             hapic_data.path.content_id,
146
             hapic_data.path.content_id,
147
-            content_type=ContentType.Any
147
+            content_type=CONTENT_TYPES.Any_SLUG
148
         )
148
         )
149
         with new_revision(
149
         with new_revision(
150
                 session=request.dbsession,
150
                 session=request.dbsession,

+ 5 - 5
backend/tracim_backend/views/contents_api/threads_controller.py View File

25
 from tracim_backend.exceptions import EmptyLabelNotAllowed
25
 from tracim_backend.exceptions import EmptyLabelNotAllowed
26
 from tracim_backend.models.context_models import ContentInContext
26
 from tracim_backend.models.context_models import ContentInContext
27
 from tracim_backend.models.context_models import RevisionInContext
27
 from tracim_backend.models.context_models import RevisionInContext
28
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
28
+from tracim_backend.models.contents import CONTENT_TYPES
29
 from tracim_backend.models.contents import thread_type
29
 from tracim_backend.models.contents import thread_type
30
 from tracim_backend.models.revision_protection import new_revision
30
 from tracim_backend.models.revision_protection import new_revision
31
 
31
 
51
         )
51
         )
52
         content = api.get_one(
52
         content = api.get_one(
53
             hapic_data.path.content_id,
53
             hapic_data.path.content_id,
54
-            content_type=ContentType.Any
54
+            content_type=CONTENT_TYPES.Any_SLUG
55
         )
55
         )
56
         return api.get_content_in_context(content)
56
         return api.get_content_in_context(content)
57
 
57
 
74
         )
74
         )
75
         content = api.get_one(
75
         content = api.get_one(
76
             hapic_data.path.content_id,
76
             hapic_data.path.content_id,
77
-            content_type=ContentType.Any
77
+            content_type=CONTENT_TYPES.Any_SLUG
78
         )
78
         )
79
         with new_revision(
79
         with new_revision(
80
                 session=request.dbsession,
80
                 session=request.dbsession,
112
         )
112
         )
113
         content = api.get_one(
113
         content = api.get_one(
114
             hapic_data.path.content_id,
114
             hapic_data.path.content_id,
115
-            content_type=ContentType.Any
115
+            content_type=CONTENT_TYPES.Any_SLUG
116
         )
116
         )
117
         revisions = content.revisions
117
         revisions = content.revisions
118
         return [
118
         return [
138
         )
138
         )
139
         content = api.get_one(
139
         content = api.get_one(
140
             hapic_data.path.content_id,
140
             hapic_data.path.content_id,
141
-            content_type=ContentType.Any
141
+            content_type=CONTENT_TYPES.Any_SLUG
142
         )
142
         )
143
         with new_revision(
143
         with new_revision(
144
                 session=request.dbsession,
144
                 session=request.dbsession,

+ 10 - 9
backend/tracim_backend/views/core_api/schemas.py View File

6
 
6
 
7
 from tracim_backend.lib.utils.utils import DATETIME_FORMAT
7
 from tracim_backend.lib.utils.utils import DATETIME_FORMAT
8
 from tracim_backend.models.auth import Profile
8
 from tracim_backend.models.auth import Profile
9
-from tracim_backend.models.contents import GlobalStatus, CONTENT_STATUS
9
+from tracim_backend.models.contents import GlobalStatus
10
+from tracim_backend.models.contents import CONTENT_STATUS
11
+from tracim_backend.models.contents import CONTENT_TYPES
10
 from tracim_backend.models.contents import open_status
12
 from tracim_backend.models.contents import open_status
11
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
12
 from tracim_backend.models.context_models import ActiveContentFilter
13
 from tracim_backend.models.context_models import ActiveContentFilter
13
 from tracim_backend.models.context_models import ContentIdsQuery
14
 from tracim_backend.models.context_models import ContentIdsQuery
14
 from tracim_backend.models.context_models import UserWorkspaceAndContentPath
15
 from tracim_backend.models.context_models import UserWorkspaceAndContentPath
341
         validate=Range(min=0, max=1, error="Value must be 0 or 1"),
342
         validate=Range(min=0, max=1, error="Value must be 0 or 1"),
342
     )
343
     )
343
     content_type = marshmallow.fields.String(
344
     content_type = marshmallow.fields.String(
344
-        example=ContentType.Any,
345
-        default=ContentType.Any,
346
-        validate=OneOf(ContentType.allowed_type_values())
345
+        example=CONTENT_TYPES.Any_SLUG,
346
+        default=CONTENT_TYPES.Any_SLUG,
347
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug())
347
     )
348
     )
348
 
349
 
349
     @post_load
350
     @post_load
591
 class ContentTypeSchema(marshmallow.Schema):
592
 class ContentTypeSchema(marshmallow.Schema):
592
     slug = marshmallow.fields.String(
593
     slug = marshmallow.fields.String(
593
         example='pagehtml',
594
         example='pagehtml',
594
-        validate=OneOf(ContentType.allowed_types()),
595
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),
595
     )
596
     )
596
     fa_icon = marshmallow.fields.String(
597
     fa_icon = marshmallow.fields.String(
597
         example='fa-file-text-o',
598
         example='fa-file-text-o',
645
     )
646
     )
646
     content_type = marshmallow.fields.String(
647
     content_type = marshmallow.fields.String(
647
         example='html-documents',
648
         example='html-documents',
648
-        validate=OneOf(ContentType.allowed_types_for_folding()),  # nopep8
649
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),  # nopep8
649
     )
650
     )
650
     parent_id = marshmallow.fields.Integer(
651
     parent_id = marshmallow.fields.Integer(
651
         example=35,
652
         example=35,
677
     label = marshmallow.fields.Str(example='Intervention Report 12')
678
     label = marshmallow.fields.Str(example='Intervention Report 12')
678
     content_type = marshmallow.fields.Str(
679
     content_type = marshmallow.fields.Str(
679
         example='html-documents',
680
         example='html-documents',
680
-        validate=OneOf(ContentType.allowed_types()),
681
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),
681
     )
682
     )
682
     sub_content_types = marshmallow.fields.List(
683
     sub_content_types = marshmallow.fields.List(
683
         marshmallow.fields.String(
684
         marshmallow.fields.String(
684
             example='html-content',
685
             example='html-content',
685
-            validate=OneOf(ContentType.allowed_types())
686
+            validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug())
686
         ),
687
         ),
687
         description='list of content types allowed as sub contents. '
688
         description='list of content types allowed as sub contents. '
688
                     'This field is required for folder contents, '
689
                     'This field is required for folder contents, '

+ 3 - 3
backend/tracim_backend/views/core_api/system_controller.py View File

5
 from tracim_backend.lib.utils.authorization import require_profile
5
 from tracim_backend.lib.utils.authorization import require_profile
6
 from tracim_backend.models import Group
6
 from tracim_backend.models import Group
7
 from tracim_backend.models.applications import applications
7
 from tracim_backend.models.applications import applications
8
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
8
+from tracim_backend.models.contents import CONTENT_TYPES
9
 
9
 
10
 try:  # Python 3.5+
10
 try:  # Python 3.5+
11
     from http import HTTPStatus
11
     from http import HTTPStatus
39
         """
39
         """
40
         Get list of alls content types availables in this tracim instance.
40
         Get list of alls content types availables in this tracim instance.
41
         """
41
         """
42
-        content_types_slugs = ContentType.allowed_types_for_folding()
43
-        content_types = [ContentType(slug) for slug in content_types_slugs]
42
+        content_types_slugs = CONTENT_TYPES.endpoint_allowed_types_slug()
43
+        content_types = [CONTENT_TYPES.get_one_by_slug(slug) for slug in content_types_slugs]
44
         return content_types
44
         return content_types
45
 
45
 
46
     def bind(self, configurator: Configurator) -> None:
46
     def bind(self, configurator: Configurator) -> None:

+ 11 - 11
backend/tracim_backend/views/core_api/workspace_controller.py View File

46
 from tracim_backend.views.core_api.schemas import WorkspaceSchema
46
 from tracim_backend.views.core_api.schemas import WorkspaceSchema
47
 from tracim_backend.views.core_api.schemas import WorkspaceIdPathSchema
47
 from tracim_backend.views.core_api.schemas import WorkspaceIdPathSchema
48
 from tracim_backend.views.core_api.schemas import WorkspaceMemberSchema
48
 from tracim_backend.views.core_api.schemas import WorkspaceMemberSchema
49
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
49
+from tracim_backend.models.contents import CONTENT_TYPES
50
 from tracim_backend.models.revision_protection import new_revision
50
 from tracim_backend.models.revision_protection import new_revision
51
 
51
 
52
 SWAGGER_TAG_WORKSPACE_ENDPOINTS = 'Workspaces'
52
 SWAGGER_TAG_WORKSPACE_ENDPOINTS = 'Workspaces'
259
         contents = api.get_all(
259
         contents = api.get_all(
260
             parent_id=content_filter.parent_id,
260
             parent_id=content_filter.parent_id,
261
             workspace=request.current_workspace,
261
             workspace=request.current_workspace,
262
-            content_type=content_filter.content_type or ContentType.Any,
262
+            content_type=content_filter.content_type or CONTENT_TYPES.Any_SLUG,
263
         )
263
         )
264
         contents = [
264
         contents = [
265
             api.get_content_in_context(content) for content in contents
265
             api.get_content_in_context(content) for content in contents
291
         parent = None
291
         parent = None
292
         if creation_data.parent_id:
292
         if creation_data.parent_id:
293
             try:
293
             try:
294
-                parent = api.get_one(content_id=creation_data.parent_id, content_type=ContentType.Any)  # nopep8
294
+                parent = api.get_one(content_id=creation_data.parent_id, content_type=CONTENT_TYPES.Any_SLUG)  # nopep8
295
             except ContentNotFound as exc:
295
             except ContentNotFound as exc:
296
                 raise ParentNotFound(
296
                 raise ParentNotFound(
297
                     'Parent with content_id {} not found'.format(creation_data.parent_id)
297
                     'Parent with content_id {} not found'.format(creation_data.parent_id)
298
                 ) from exc
298
                 ) from exc
299
         content = api.create(
299
         content = api.create(
300
             label=creation_data.label,
300
             label=creation_data.label,
301
-            content_type=creation_data.content_type,
301
+            content_type_slug=creation_data.content_type,
302
             workspace=request.current_workspace,
302
             workspace=request.current_workspace,
303
             parent=parent,
303
             parent=parent,
304
         )
304
         )
333
         )
333
         )
334
         content = api.get_one(
334
         content = api.get_one(
335
             path_data.content_id,
335
             path_data.content_id,
336
-            content_type=ContentType.Any
336
+            content_type=CONTENT_TYPES.Any_SLUG
337
         )
337
         )
338
         new_parent = api.get_one(
338
         new_parent = api.get_one(
339
-            move_data.new_parent_id, content_type=ContentType.Any
339
+            move_data.new_parent_id, content_type=CONTENT_TYPES.Any_SLUG
340
         )
340
         )
341
 
341
 
342
         new_workspace = request.candidate_workspace
342
         new_workspace = request.candidate_workspace
354
             )
354
             )
355
         updated_content = api.get_one(
355
         updated_content = api.get_one(
356
             path_data.content_id,
356
             path_data.content_id,
357
-            content_type=ContentType.Any
357
+            content_type=CONTENT_TYPES.Any_SLUG
358
         )
358
         )
359
         return api.get_content_in_context(updated_content)
359
         return api.get_content_in_context(updated_content)
360
 
360
 
380
         )
380
         )
381
         content = api.get_one(
381
         content = api.get_one(
382
             path_data.content_id,
382
             path_data.content_id,
383
-            content_type=ContentType.Any
383
+            content_type=CONTENT_TYPES.Any_SLUG
384
         )
384
         )
385
         with new_revision(
385
         with new_revision(
386
                 session=request.dbsession,
386
                 session=request.dbsession,
413
         )
413
         )
414
         content = api.get_one(
414
         content = api.get_one(
415
             path_data.content_id,
415
             path_data.content_id,
416
-            content_type=ContentType.Any
416
+            content_type=CONTENT_TYPES.Any_SLUG
417
         )
417
         )
418
         with new_revision(
418
         with new_revision(
419
                 session=request.dbsession,
419
                 session=request.dbsession,
443
             session=request.dbsession,
443
             session=request.dbsession,
444
             config=app_config,
444
             config=app_config,
445
         )
445
         )
446
-        content = api.get_one(path_data.content_id, content_type=ContentType.Any)  # nopep8
446
+        content = api.get_one(path_data.content_id, content_type=CONTENT_TYPES.Any_SLUG)  # nopep8
447
         with new_revision(
447
         with new_revision(
448
                 session=request.dbsession,
448
                 session=request.dbsession,
449
                 tm=transaction.manager,
449
                 tm=transaction.manager,
475
         )
475
         )
476
         content = api.get_one(
476
         content = api.get_one(
477
             path_data.content_id,
477
             path_data.content_id,
478
-            content_type=ContentType.Any
478
+            content_type=CONTENT_TYPES.Any_SLUG
479
         )
479
         )
480
         with new_revision(
480
         with new_revision(
481
                 session=request.dbsession,
481
                 session=request.dbsession,