Browse Source

Merge branch 'develop' of github.com:tracim/tracim_v2 into develop

Skylsmoi 6 years ago
parent
commit
20bca5c7e2
31 changed files with 670 additions and 680 deletions
  1. 12 0
      backend/doc/roles.md
  2. 7 6
      backend/tracim_backend/config.py
  3. 18 18
      backend/tracim_backend/fixtures/content.py
  4. 65 59
      backend/tracim_backend/lib/core/content.py
  5. 10 10
      backend/tracim_backend/lib/mail_notifier/notifier.py
  6. 6 6
      backend/tracim_backend/lib/utils/authorization.py
  7. 3 3
      backend/tracim_backend/lib/utils/request.py
  8. 7 5
      backend/tracim_backend/lib/webdav/dav_provider.py
  9. 3 2
      backend/tracim_backend/lib/webdav/design.py
  10. 37 34
      backend/tracim_backend/lib/webdav/resources.py
  11. 5 3
      backend/tracim_backend/lib/webdav/utils.py
  12. 108 143
      backend/tracim_backend/models/contents.py
  13. 3 7
      backend/tracim_backend/models/context_models.py
  14. 26 28
      backend/tracim_backend/models/data.py
  15. 3 3
      backend/tracim_backend/tests/__init__.py
  16. 37 38
      backend/tracim_backend/tests/functional/test_contents.py
  17. 5 5
      backend/tracim_backend/tests/functional/test_mail_notification.py
  18. 5 4
      backend/tracim_backend/tests/functional/test_system.py
  19. 113 112
      backend/tracim_backend/tests/functional/test_user.py
  20. 14 14
      backend/tracim_backend/tests/functional/test_workspaces.py
  21. 115 115
      backend/tracim_backend/tests/library/test_content_api.py
  22. 6 6
      backend/tracim_backend/tests/models/test_content.py
  23. 4 3
      backend/tracim_backend/tests/models/test_content_revision.py
  24. 5 5
      backend/tracim_backend/views/contents_api/comment_controller.py
  25. 14 14
      backend/tracim_backend/views/contents_api/file_controller.py
  26. 5 5
      backend/tracim_backend/views/contents_api/html_document_controller.py
  27. 5 5
      backend/tracim_backend/views/contents_api/threads_controller.py
  28. 12 11
      backend/tracim_backend/views/core_api/schemas.py
  29. 3 3
      backend/tracim_backend/views/core_api/system_controller.py
  30. 3 2
      backend/tracim_backend/views/core_api/user_controller.py
  31. 11 11
      backend/tracim_backend/views/core_api/workspace_controller.py

+ 12 - 0
backend/doc/roles.md View File

7
 
7
 
8
 ## Global profile
8
 ## Global profile
9
 
9
 
10
+|                               | Normal User | Managers    | Admin          |
11
+|-------------------------------|-------------|-------------|----------------|
12
+| slug                            | users       | managers    | administrators |
13
+|-------------------------------|-------------|-------------|---------|
14
+
10
 
15
 
11
 |                               | Normal User | Managers    | Admin   |
16
 |                               | Normal User | Managers    | Admin   |
12
 |-------------------------------|-------------|-------------|---------|
17
 |-------------------------------|-------------|-------------|---------|
22
 | access to all user data (/users/{user_id} endpoints) |personal-only|personal-only| yes     |
27
 | access to all user data (/users/{user_id} endpoints) |personal-only|personal-only| yes     |
23
 
28
 
24
 
29
 
30
+
31
+
25
 ## Workspace Roles
32
 ## Workspace Roles
26
 
33
 
27
 
34
 
28
 |                              | Reader | Contributor | Content Manager | Workspace Manager |
35
 |                              | Reader | Contributor | Content Manager | Workspace Manager |
29
 |------------------------------|--------|-------------|-----------------|-------------------|
36
 |------------------------------|--------|-------------|-----------------|-------------------|
37
+| slug                         | reader | contributor | content-manager |  workspace-manager|
38
+|------------------------------|--------|-------------|-----------------|-------------------|
39
+
40
+|                              | Reader | Contributor | Content Manager | Workspace Manager |
41
+|------------------------------|--------|-------------|-----------------|-------------------|
30
 | read content                 |  yes   | yes         | yes             | yes               |
42
 | read content                 |  yes   | yes         | yes             | yes               |
31
 |------------------------------|--------|-------------|-----------------|-------------------|
43
 |------------------------------|--------|-------------|-----------------|-------------------|
32
 | create content               |  no    | yes         | yes             | yes               |
44
 | create content               |  no    | yes         | yes             | yes               |

+ 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

34
 from tracim_backend.exceptions import ContentNotFound
34
 from tracim_backend.exceptions import ContentNotFound
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
38
+from tracim_backend.models.contents import ContentType
39
+from tracim_backend.models.contents import CONTENT_TYPES
37
 from tracim_backend.models.revision_protection import new_revision
40
 from tracim_backend.models.revision_protection import new_revision
38
 from tracim_backend.models.auth import User
41
 from tracim_backend.models.auth import User
39
 from tracim_backend.models.data import ActionDescription
42
 from tracim_backend.models.data import ActionDescription
40
-from tracim_backend.models.data import ContentStatus
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()
945
     #
951
     #
946
     #     resultset = self._base_query(workspace)
952
     #     resultset = self._base_query(workspace)
947
     #
953
     #
948
-    #     if content_type != ContentType.Any:
954
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
949
     #         resultset = resultset.filter(Content.type==content_type)
955
     #         resultset = resultset.filter(Content.type==content_type)
950
     #
956
     #
951
     #     return resultset.all()
957
     #     return resultset.all()
978
                     Content.content_id.in_(content_ids),
984
                     Content.content_id.in_(content_ids),
979
                     and_(
985
                     and_(
980
                         Content.parent_id.in_(content_ids),
986
                         Content.parent_id.in_(content_ids),
981
-                        Content.type == ContentType.Comment
987
+                        Content.type == CONTENT_TYPES.Comment.slug
982
                     )
988
                     )
983
                 )
989
                 )
984
             )
990
             )
990
         before_content_find = False
996
         before_content_find = False
991
         for content in resultset:
997
         for content in resultset:
992
             related_active_content = None
998
             related_active_content = None
993
-            if ContentType.Comment == content.type:
999
+            if CONTENT_TYPES.Comment.slug == content.type:
994
                 related_active_content = content.parent
1000
                 related_active_content = content.parent
995
             else:
1001
             else:
996
                 related_active_content = content
1002
                 related_active_content = content
1040
     #         .filter(Content.content_id.in_(not_read_content_ids)) \
1046
     #         .filter(Content.content_id.in_(not_read_content_ids)) \
1041
     #         .order_by(desc(Content.updated))
1047
     #         .order_by(desc(Content.updated))
1042
     #
1048
     #
1043
-    #     if content_type != ContentType.Any:
1049
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
1044
     #         not_read_contents = not_read_contents.filter(
1050
     #         not_read_contents = not_read_contents.filter(
1045
     #             Content.type==content_type)
1051
     #             Content.type==content_type)
1046
     #     else:
1052
     #     else:
1047
     #         not_read_contents = not_read_contents.filter(
1053
     #         not_read_contents = not_read_contents.filter(
1048
-    #             Content.type!=ContentType.Folder)
1054
+    #             Content.type!=CONTENT_TYPES.Folder.slug)
1049
     #
1055
     #
1050
     #     if parent_id:
1056
     #     if parent_id:
1051
     #         not_read_contents = not_read_contents.filter(
1057
     #         not_read_contents = not_read_contents.filter(
1054
     #     result = []
1060
     #     result = []
1055
     #     for item in not_read_contents:
1061
     #     for item in not_read_contents:
1056
     #         new_item = None
1062
     #         new_item = None
1057
-    #         if ContentType.Comment == item.type:
1063
+    #         if CONTENT_TYPES.Comment.slug == item.type:
1058
     #             new_item = item.parent
1064
     #             new_item = item.parent
1059
     #         else:
1065
     #         else:
1060
     #             new_item = item
1066
     #             new_item = item
1086
         folder.properties = properties
1092
         folder.properties = properties
1087
 
1093
 
1088
     def set_status(self, content: Content, new_status: str):
1094
     def set_status(self, content: Content, new_status: str):
1089
-        if new_status in ContentStatus.allowed_values():
1095
+        if new_status in CONTENT_STATUS.get_all_slugs_values():
1090
             content.status = new_status
1096
             content.status = new_status
1091
             content.revision_type = ActionDescription.STATUS_UPDATE
1097
             content.revision_type = ActionDescription.STATUS_UPDATE
1092
         else:
1098
         else:
1296
                 self.mark_read(child, read_datetime=read_datetime,
1302
                 self.mark_read(child, read_datetime=read_datetime,
1297
                                do_flush=False)
1303
                                do_flush=False)
1298
 
1304
 
1299
-            if ContentType.Comment == content.type:
1305
+            if CONTENT_TYPES.Comment.slug == content.type:
1300
                 self.mark_read(content.parent, read_datetime=read_datetime,
1306
                 self.mark_read(content.parent, read_datetime=read_datetime,
1301
                                do_flush=False, recursive=False)
1307
                                do_flush=False, recursive=False)
1302
                 for comment in content.parent.get_comments():
1308
                 for comment in content.parent.get_comments():
1416
         return title_keyworded_items
1422
         return title_keyworded_items
1417
 
1423
 
1418
     def get_all_types(self) -> typing.List[ContentType]:
1424
     def get_all_types(self) -> typing.List[ContentType]:
1419
-        labels = ContentType.all()
1425
+        labels = CONTENT_TYPES.endpoint_allowed_types_slug()
1420
         content_types = []
1426
         content_types = []
1421
         for label in labels:
1427
         for label in labels:
1422
-            content_types.append(ContentType(label))
1428
+            content_types.append(CONTENT_TYPES.get_one_by_slug(label))
1423
 
1429
 
1424
-        return ContentType.sorted(content_types)
1430
+        return content_types
1425
 
1431
 
1426
     # TODO - G.M - 2018-07-24 - [Cleanup] Is this method already needed ?
1432
     # TODO - G.M - 2018-07-24 - [Cleanup] Is this method already needed ?
1427
     def exclude_unavailable(
1433
     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

+ 108 - 143
backend/tracim_backend/models/contents.py View File

19
     CLOSED = 'closed'
19
     CLOSED = 'closed'
20
 
20
 
21
 
21
 
22
-class NewContentStatus(object):
22
+class ContentStatus(object):
23
     """
23
     """
24
-    Future ContentStatus object class
24
+    ContentStatus object class
25
     """
25
     """
26
     def __init__(
26
     def __init__(
27
             self,
27
             self,
38
         self.hexcolor = hexcolor
38
         self.hexcolor = hexcolor
39
 
39
 
40
 
40
 
41
-open_status = NewContentStatus(
41
+open_status = ContentStatus(
42
     slug='open',
42
     slug='open',
43
     global_status=GlobalStatus.OPEN.value,
43
     global_status=GlobalStatus.OPEN.value,
44
     label='Open',
44
     label='Open',
46
     hexcolor='#3f52e3',
46
     hexcolor='#3f52e3',
47
 )
47
 )
48
 
48
 
49
-closed_validated_status = NewContentStatus(
49
+closed_validated_status = ContentStatus(
50
     slug='closed-validated',
50
     slug='closed-validated',
51
     global_status=GlobalStatus.CLOSED.value,
51
     global_status=GlobalStatus.CLOSED.value,
52
     label='Validated',
52
     label='Validated',
54
     hexcolor='#008000',
54
     hexcolor='#008000',
55
 )
55
 )
56
 
56
 
57
-closed_unvalidated_status = NewContentStatus(
57
+closed_unvalidated_status = ContentStatus(
58
     slug='closed-unvalidated',
58
     slug='closed-unvalidated',
59
     global_status=GlobalStatus.CLOSED.value,
59
     global_status=GlobalStatus.CLOSED.value,
60
     label='Cancelled',
60
     label='Cancelled',
62
     hexcolor='#f63434',
62
     hexcolor='#f63434',
63
 )
63
 )
64
 
64
 
65
-closed_deprecated_status = NewContentStatus(
65
+closed_deprecated_status = ContentStatus(
66
     slug='closed-deprecated',
66
     slug='closed-deprecated',
67
     global_status=GlobalStatus.CLOSED.value,
67
     global_status=GlobalStatus.CLOSED.value,
68
     label='Deprecated',
68
     label='Deprecated',
71
 )
71
 )
72
 
72
 
73
 
73
 
74
-CONTENT_DEFAULT_STATUS = [
75
-    open_status,
76
-    closed_validated_status,
77
-    closed_unvalidated_status,
78
-    closed_deprecated_status,
79
-]
74
+class ContentStatusList(object):
80
 
75
 
76
+    OPEN = open_status
81
 
77
 
82
-class ContentStatusLegacy(NewContentStatus):
83
-    """
84
-    Temporary remplacement object for Legacy ContentStatus Object
85
-    """
86
-    OPEN = open_status.slug
87
-    CLOSED_VALIDATED = closed_validated_status.slug
88
-    CLOSED_UNVALIDATED = closed_unvalidated_status.slug
89
-    CLOSED_DEPRECATED = closed_deprecated_status.slug
90
-
91
-    def __init__(self, slug: str):
92
-        for status in CONTENT_DEFAULT_STATUS:
93
-            if slug == status.slug:
94
-                super(ContentStatusLegacy, self).__init__(
95
-                    slug=status.slug,
96
-                    global_status=status.global_status,
97
-                    label=status.label,
98
-                    fa_icon=status.fa_icon,
99
-                    hexcolor=status.hexcolor,
100
-                )
101
-                return
78
+    def __init__(self, extend_content_status: typing.List[ContentStatus]):
79
+        self._content_status = [self.OPEN]
80
+        self._content_status.extend(extend_content_status)
81
+
82
+    def get_one_by_slug(self, slug: str) -> ContentStatus:
83
+        for item in self._content_status:
84
+            if item.slug == slug:
85
+                return item
102
         raise ContentStatusNotExist()
86
         raise ContentStatusNotExist()
103
 
87
 
104
-    @classmethod
105
-    def all(cls, type='') -> ['NewContentStatus']:
106
-        return CONTENT_DEFAULT_STATUS
88
+    def get_all_slugs_values(self) -> typing.List[str]:
89
+        """ Get alls slugs"""
90
+        return [item.slug for item in self._content_status]
91
+
92
+    def get_all(self) -> typing.List[ContentStatus]:
93
+        """ Get all status"""
94
+        return [item for item in self._content_status]
107
 
95
 
108
-    @classmethod
109
-    def allowed_values(cls):
110
-        return [status.slug for status in CONTENT_DEFAULT_STATUS]
96
+    def get_default_status(self) -> ContentStatus:
97
+        return self.OPEN
111
 
98
 
112
 
99
 
100
+CONTENT_STATUS = ContentStatusList(
101
+    [
102
+        closed_validated_status,
103
+        closed_unvalidated_status,
104
+        closed_deprecated_status,
105
+    ]
106
+)
113
 ####
107
 ####
114
 # ContentType
108
 # ContentType
115
 
109
 
116
 
110
 
117
-class NewContentType(object):
111
+class ContentType(object):
118
     """
112
     """
119
     Future ContentType object class
113
     Future ContentType object class
120
     """
114
     """
125
             hexcolor: str,
119
             hexcolor: str,
126
             label: str,
120
             label: str,
127
             creation_label: str,
121
             creation_label: str,
128
-            available_statuses: typing.List[NewContentStatus],
129
-
122
+            available_statuses: typing.List[ContentStatus],
123
+            slug_alias: typing.List[str] = None,
130
     ):
124
     ):
131
         self.slug = slug
125
         self.slug = slug
132
         self.fa_icon = fa_icon
126
         self.fa_icon = fa_icon
134
         self.label = label
128
         self.label = label
135
         self.creation_label = creation_label
129
         self.creation_label = creation_label
136
         self.available_statuses = available_statuses
130
         self.available_statuses = available_statuses
131
+        self.slug_alias = slug_alias
137
 
132
 
138
 
133
 
139
-thread_type = NewContentType(
134
+thread_type = ContentType(
140
     slug='thread',
135
     slug='thread',
141
     fa_icon=thread.fa_icon,
136
     fa_icon=thread.fa_icon,
142
     hexcolor=thread.hexcolor,
137
     hexcolor=thread.hexcolor,
143
     label='Thread',
138
     label='Thread',
144
     creation_label='Discuss about a topic',
139
     creation_label='Discuss about a topic',
145
-    available_statuses=CONTENT_DEFAULT_STATUS,
140
+    available_statuses=CONTENT_STATUS.get_all(),
146
 )
141
 )
147
 
142
 
148
-file_type = NewContentType(
143
+file_type = ContentType(
149
     slug='file',
144
     slug='file',
150
     fa_icon=_file.fa_icon,
145
     fa_icon=_file.fa_icon,
151
     hexcolor=_file.hexcolor,
146
     hexcolor=_file.hexcolor,
152
     label='File',
147
     label='File',
153
     creation_label='Upload a file',
148
     creation_label='Upload a file',
154
-    available_statuses=CONTENT_DEFAULT_STATUS,
149
+    available_statuses=CONTENT_STATUS.get_all(),
155
 )
150
 )
156
 
151
 
157
-markdownpluspage_type = NewContentType(
152
+markdownpluspage_type = ContentType(
158
     slug='markdownpage',
153
     slug='markdownpage',
159
     fa_icon=markdownpluspage.fa_icon,
154
     fa_icon=markdownpluspage.fa_icon,
160
     hexcolor=markdownpluspage.hexcolor,
155
     hexcolor=markdownpluspage.hexcolor,
161
     label='Rich Markdown File',
156
     label='Rich Markdown File',
162
     creation_label='Create a Markdown document',
157
     creation_label='Create a Markdown document',
163
-    available_statuses=CONTENT_DEFAULT_STATUS,
158
+    available_statuses=CONTENT_STATUS.get_all(),
164
 )
159
 )
165
 
160
 
166
-html_documents_type = NewContentType(
161
+html_documents_type = ContentType(
167
     slug='html-document',
162
     slug='html-document',
168
     fa_icon=html_documents.fa_icon,
163
     fa_icon=html_documents.fa_icon,
169
     hexcolor=html_documents.hexcolor,
164
     hexcolor=html_documents.hexcolor,
170
     label='Text Document',
165
     label='Text Document',
171
     creation_label='Write a document',
166
     creation_label='Write a document',
172
-    available_statuses=CONTENT_DEFAULT_STATUS,
167
+    available_statuses=CONTENT_STATUS.get_all(),
168
+    slug_alias=['page']
173
 )
169
 )
174
 
170
 
175
 # TODO - G.M - 31-05-2018 - Set Better folder params
171
 # TODO - G.M - 31-05-2018 - Set Better folder params
176
-folder_type = NewContentType(
172
+folder_type = ContentType(
177
     slug='folder',
173
     slug='folder',
178
     fa_icon=thread.fa_icon,
174
     fa_icon=thread.fa_icon,
179
     hexcolor=thread.hexcolor,
175
     hexcolor=thread.hexcolor,
180
     label='Folder',
176
     label='Folder',
181
     creation_label='Create collection of any documents',
177
     creation_label='Create collection of any documents',
182
-    available_statuses=CONTENT_DEFAULT_STATUS,
178
+    available_statuses=CONTENT_STATUS.get_all(),
183
 )
179
 )
184
 
180
 
185
-CONTENT_DEFAULT_TYPE = [
186
-    thread_type,
187
-    file_type,
188
-    markdownpluspage_type,
189
-    html_documents_type,
190
-    folder_type,
191
-]
192
 
181
 
193
 # TODO - G.M - 31-05-2018 - Set Better Event params
182
 # TODO - G.M - 31-05-2018 - Set Better Event params
194
-event_type = NewContentType(
183
+event_type = ContentType(
195
     slug='event',
184
     slug='event',
196
     fa_icon=thread.fa_icon,
185
     fa_icon=thread.fa_icon,
197
     hexcolor=thread.hexcolor,
186
     hexcolor=thread.hexcolor,
198
     label='Event',
187
     label='Event',
199
     creation_label='Event',
188
     creation_label='Event',
200
-    available_statuses=CONTENT_DEFAULT_STATUS,
189
+    available_statuses=CONTENT_STATUS.get_all(),
201
 )
190
 )
202
 
191
 
203
 # TODO - G.M - 31-05-2018 - Set Better Event params
192
 # TODO - G.M - 31-05-2018 - Set Better Event params
204
-comment_type = NewContentType(
193
+comment_type = ContentType(
205
     slug='comment',
194
     slug='comment',
206
     fa_icon=thread.fa_icon,
195
     fa_icon=thread.fa_icon,
207
     hexcolor=thread.hexcolor,
196
     hexcolor=thread.hexcolor,
208
     label='Comment',
197
     label='Comment',
209
     creation_label='Comment',
198
     creation_label='Comment',
210
-    available_statuses=CONTENT_DEFAULT_STATUS,
199
+    available_statuses=CONTENT_STATUS.get_all(),
211
 )
200
 )
212
 
201
 
213
-CONTENT_DEFAULT_TYPE_SPECIAL = [
214
-    event_type,
215
-    comment_type,
216
-]
217
-
218
-ALL_CONTENTS_DEFAULT_TYPES = CONTENT_DEFAULT_TYPE + CONTENT_DEFAULT_TYPE_SPECIAL
219
 
202
 
220
-
221
-class ContentTypeLegacy(NewContentType):
203
+class ContentTypeList(object):
222
     """
204
     """
223
-    Temporary remplacement object for Legacy ContentType Object
205
+    ContentType List
224
     """
206
     """
225
-
226
-    # special type
227
-    Any = 'any'
228
-    Folder = 'folder'
229
-    Event = 'event'
230
-    Comment = 'comment'
231
-
232
-    File = file_type.slug
233
-    Thread = thread_type.slug
234
-    Page = html_documents_type.slug
235
-    PageLegacy = 'page'
236
-    MarkdownPage = markdownpluspage_type.slug
237
-
238
-    def __init__(self, slug: str):
239
-        if slug == 'page':
240
-            slug = ContentTypeLegacy.Page
241
-        for content_type in ALL_CONTENTS_DEFAULT_TYPES:
242
-            if slug == content_type.slug:
243
-                super(ContentTypeLegacy, self).__init__(
244
-                    slug=content_type.slug,
245
-                    fa_icon=content_type.fa_icon,
246
-                    hexcolor=content_type.hexcolor,
247
-                    label=content_type.label,
248
-                    creation_label=content_type.creation_label,
249
-                    available_statuses=content_type.available_statuses
250
-                )
251
-                return
207
+    Any_SLUG = 'any'
208
+    Folder = folder_type
209
+    Comment = comment_type
210
+    Event = event_type
211
+    File = file_type
212
+    Page = html_documents_type
213
+    Thread = thread_type
214
+
215
+    def __init__(self, extend_content_status: typing.List[ContentType]):
216
+        self._content_types = [self.Folder]
217
+        self._content_types.extend(extend_content_status)
218
+        self._special_contents_types = [self.Comment]
219
+        self._extra_slugs = [self.Any_SLUG]
220
+
221
+    def get_one_by_slug(self, slug: str) -> ContentType:
222
+        """
223
+        Get ContentType object according to slug
224
+        match for both slug and slug_alias
225
+        """
226
+        content_types = self._content_types.copy()
227
+        content_types.extend(self._special_contents_types)
228
+        for item in content_types:
229
+            if item.slug == slug or (item.slug_alias and slug in item.slug_alias):  # nopep8
230
+                return item
252
         raise ContentTypeNotExist()
231
         raise ContentTypeNotExist()
253
 
232
 
254
-    def get_slug_aliases(self) -> typing.List[str]:
233
+    def endpoint_allowed_types_slug(self) -> typing.List[str]:
255
         """
234
         """
256
-        Get all slug aliases of a content,
257
-        useful for legacy code convertion
235
+        Return restricted list of content_type:
236
+        dont return special content_type like  comment, don't return
237
+        "any" slug, dont return content type slug alias , don't return event.
238
+        Useful to restrict slug param in schema.
258
         """
239
         """
259
-        # TODO - G.M - 2018-07-05 - Remove this legacy compat code
260
-        # when possible.
261
-        page_alias = [self.Page, self.PageLegacy]
262
-        if self.slug in page_alias:
263
-            return page_alias
264
-        else:
265
-            return [self.slug]
266
-
267
-    @classmethod
268
-    def all(cls) -> typing.List[str]:
269
-        return cls.allowed_types()
270
-
271
-    @classmethod
272
-    def allowed_types(cls) -> typing.List[str]:
273
-        contents_types = [status.slug for status in ALL_CONTENTS_DEFAULT_TYPES]
274
-        return contents_types
275
-
276
-    @classmethod
277
-    def allowed_type_values(cls) -> typing.List[str]:
240
+        allowed_type_slug = [contents_type.slug for contents_type in self._content_types]  # nopep8
241
+        return allowed_type_slug
242
+
243
+    def query_allowed_types_slugs(self) -> typing.List[str]:
278
         """
244
         """
279
-        All content type slug + special values like any
245
+        Return alls allowed types slug : content_type slug + all alias, any
246
+        and special content_type like comment. Do not return event.
247
+        Usefull allowed value to perform query to database.
280
         """
248
         """
281
-        content_types = cls.allowed_types()
282
-        content_types.append(ContentTypeLegacy.Any)
283
-        return content_types
284
-
285
-    @classmethod
286
-    def allowed_types_for_folding(cls):
287
-        # This method is used for showing only "main"
288
-        # types in the left-side treeview
289
-        contents_types = [status.slug for status in CONTENT_DEFAULT_TYPE]
290
-        return contents_types
291
-
292
-    # TODO - G.M - 30-05-2018 - This method don't do anything.
293
-    @classmethod
294
-    def sorted(cls, types: ['ContentType']) -> ['ContentType']:
295
-        return types
296
-
297
-    @property
298
-    def id(self):
299
-        return self.slug
300
-
301
-    def toDict(self):
302
-        raise NotImplementedError()
249
+        allowed_types_slug = []
250
+        for content_type in self._content_types:
251
+            allowed_types_slug.append(content_type.slug)
252
+            if content_type.slug_alias:
253
+                allowed_types_slug.extend(content_type.slug_alias)
254
+        for content_type in self._special_contents_types:
255
+            allowed_types_slug.append(content_type.slug)
256
+        allowed_types_slug.extend(self._extra_slugs)
257
+        return allowed_types_slug
258
+
259
+
260
+CONTENT_TYPES = ContentTypeList(
261
+    [
262
+        thread_type,
263
+        file_type,
264
+        markdownpluspage_type,
265
+        html_documents_type,
266
+    ]
267
+)

+ 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]:

+ 26 - 28
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,
291
                 ]
291
                 ]
292
 
292
 
293
 
293
 
294
-from tracim_backend.models.contents import ContentStatusLegacy as ContentStatus
295
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
294
+from tracim_backend.models.contents import CONTENT_STATUS
295
+from tracim_backend.models.contents import ContentStatus
296
+from tracim_backend.models.contents import CONTENT_TYPES
296
 # 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
297
 # is lost .
298
 # is lost .
298
 
299
 
351
 #         # self.icon = ContentStatus._ICONS[id]
352
 #         # self.icon = ContentStatus._ICONS[id]
352
 #         # self.css = ContentStatus._CSS[id]
353
 #         # self.css = ContentStatus._CSS[id]
353
 #         #
354
 #         #
354
-#         # if type==ContentType.Thread:
355
+#         # if type==CONTENT_TYPES.Thread.slug:
355
 #         #     self.label = ContentStatus._LABELS_THREAD[id]
356
 #         #     self.label = ContentStatus._LABELS_THREAD[id]
356
-#         # elif type==ContentType.File:
357
+#         # elif type==CONTENT_TYPES.File.slug:
357
 #         #     self.label = ContentStatus._LABELS_FILE[id]
358
 #         #     self.label = ContentStatus._LABELS_FILE[id]
358
 #         # else:
359
 #         # else:
359
 #         #     self.label = ContentStatus._LABELS[id]
360
 #         #     self.label = ContentStatus._LABELS[id]
499
 #     #     # TODO - DYNDATATYPE - D.A. - 2014-12-02
500
 #     #     # TODO - DYNDATATYPE - D.A. - 2014-12-02
500
 #     #     # Make this code dynamic loading data types
501
 #     #     # Make this code dynamic loading data types
501
 #     #
502
 #     #
502
-#     #     if content.type==ContentType.Folder:
503
+#     #     if content.type==CONTENT_TYPES.Folder.slug:
503
 #     #         return '/workspaces/{}/folders/{}'.format(content.workspace_id, content.content_id)
504
 #     #         return '/workspaces/{}/folders/{}'.format(content.workspace_id, content.content_id)
504
-#     #     elif content.type==ContentType.File:
505
+#     #     elif content.type==CONTENT_TYPES.File.slug:
505
 #     #         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)
506
-#     #     elif content.type==ContentType.Thread:
507
+#     #     elif content.type==CONTENT_TYPES.Thread.slug:
507
 #     #         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)
508
-#     #     elif content.type==ContentType.Page:
509
+#     #     elif content.type==CONTENT_TYPES.Page.slug:
509
 #     #         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)
510
 #     #
511
 #     #
511
 #     # @classmethod
512
 #     # @classmethod
544
 
545
 
545
     @classmethod
546
     @classmethod
546
     def check_properties(cls, item):
547
     def check_properties(cls, item):
547
-        if item.type == ContentType.Folder:
548
+        if item.type == CONTENT_TYPES.Folder.slug:
548
             properties = item.properties
549
             properties = item.properties
549
             if 'allowed_content' not in properties.keys():
550
             if 'allowed_content' not in properties.keys():
550
                 return False
551
                 return False
558
                 return False
559
                 return False
559
             return True
560
             return True
560
 
561
 
561
-        if item.type == ContentType.Event:
562
+        if item.type == CONTENT_TYPES.Event.slug:
562
             properties = item.properties
563
             properties = item.properties
563
             if 'name' not in properties.keys():
564
             if 'name' not in properties.keys():
564
                 return False
565
                 return False
572
 
573
 
573
         # 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
574
         # Only content who can be copied need this
575
         # Only content who can be copied need this
575
-        if item.type == ContentType.Any:
576
+        if item.type == CONTENT_TYPES.Any_SLUG:
576
             properties = item.properties
577
             properties = item.properties
577
             if 'origin' in properties.keys():
578
             if 'origin' in properties.keys():
578
                 return True
579
                 return True
580
 
581
 
581
     @classmethod
582
     @classmethod
582
     def reset_properties(cls, item):
583
     def reset_properties(cls, item):
583
-        if item.type == ContentType.Folder:
584
+        if item.type == CONTENT_TYPES.Folder.slug:
584
             item.properties = DEFAULT_PROPERTIES
585
             item.properties = DEFAULT_PROPERTIES
585
             return
586
             return
586
 
587
 
616
     properties = Column('properties', Text(), unique=False, nullable=False, default='')
617
     properties = Column('properties', Text(), unique=False, nullable=False, default='')
617
 
618
 
618
     type = Column(Unicode(32), unique=False, nullable=False)
619
     type = Column(Unicode(32), unique=False, nullable=False)
619
-    status = Column(Unicode(32), unique=False, nullable=False, default=ContentStatus.OPEN)
620
+    status = Column(Unicode(32), unique=False, nullable=False, default=str(CONTENT_STATUS.get_default_status().slug))
620
     created = Column(DateTime, unique=False, nullable=False, default=datetime.utcnow)
621
     created = Column(DateTime, unique=False, nullable=False, default=datetime.utcnow)
621
     updated = Column(DateTime, unique=False, nullable=False, default=datetime.utcnow)
622
     updated = Column(DateTime, unique=False, nullable=False, default=datetime.utcnow)
622
     is_deleted = Column(Boolean, unique=False, nullable=False, default=False)
623
     is_deleted = Column(Boolean, unique=False, nullable=False, default=False)
754
         super().__setattr__(key, value)
755
         super().__setattr__(key, value)
755
 
756
 
756
     def get_status(self) -> ContentStatus:
757
     def get_status(self) -> ContentStatus:
757
-        return ContentStatus(self.status)
758
+        return CONTENT_STATUS.get_one_by_slug(self.status)
758
 
759
 
759
     def get_label(self) -> str:
760
     def get_label(self) -> str:
760
         return self.label or self.file_name or ''
761
         return self.label or self.file_name or ''
779
     def get_label_as_file(self):
780
     def get_label_as_file(self):
780
         file_extension = self.file_extension or ''
781
         file_extension = self.file_extension or ''
781
 
782
 
782
-        if self.type == ContentType.Thread:
783
+        if self.type == CONTENT_TYPES.Thread.slug:
783
             file_extension = '.html'
784
             file_extension = '.html'
784
-        elif self.type == ContentType.Page:
785
+        elif self.type == CONTENT_TYPES.Page.slug:
785
             file_extension = '.html'
786
             file_extension = '.html'
786
 
787
 
787
         return '{0}{1}'.format(
788
         return '{0}{1}'.format(
1227
         return format_timedelta(delta_from_datetime - datetime_object,
1228
         return format_timedelta(delta_from_datetime - datetime_object,
1228
                                 locale=get_locale())
1229
                                 locale=get_locale())
1229
 
1230
 
1230
-    def get_child_nb(self, content_type: ContentType, content_status = ''):
1231
+    def get_child_nb(self, content_type: str, content_status = ''):
1231
         child_nb = 0
1232
         child_nb = 0
1232
         for child in self.get_valid_children():
1233
         for child in self.get_valid_children():
1233
-            if child.type == content_type or content_type == ContentType.Any:
1234
+            if child.type == content_type or content_type.slug == CONTENT_TYPES.Any_SLUG:
1234
                 if not content_status:
1235
                 if not content_status:
1235
                     child_nb = child_nb+1
1236
                     child_nb = child_nb+1
1236
                 elif content_status==child.status:
1237
                 elif content_status==child.status:
1247
         return self.revision.get_label_as_file()
1248
         return self.revision.get_label_as_file()
1248
 
1249
 
1249
     def get_status(self) -> ContentStatus:
1250
     def get_status(self) -> ContentStatus:
1250
-        return ContentStatus(
1251
+        return CONTENT_STATUS.get_one_by_slug(
1251
             self.status,
1252
             self.status,
1252
-            # TODO - G.M - 10-04-2018 - [Cleanup] Drop this
1253
-            # self.type.__str__()
1254
         )
1253
         )
1255
 
1254
 
1256
     def get_last_action(self) -> ActionDescription:
1255
     def get_last_action(self) -> ActionDescription:
1307
     def get_comments(self):
1306
     def get_comments(self):
1308
         children = []
1307
         children = []
1309
         for child in self.children:
1308
         for child in self.children:
1310
-            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:
1311
                 children.append(child.node)
1310
                 children.append(child.node)
1312
         return children
1311
         return children
1313
 
1312
 
1348
             allowed_types = self.properties['allowed_content']
1347
             allowed_types = self.properties['allowed_content']
1349
             for type_label, is_allowed in allowed_types.items():
1348
             for type_label, is_allowed in allowed_types.items():
1350
                 if is_allowed:
1349
                 if is_allowed:
1351
-                    types.append(ContentType(type_label))
1350
+                    types.append(CONTENT_TYPES.get_one_by_slug(type_label))
1352
         except Exception as e:
1351
         except Exception as e:
1353
             print(e.__str__())
1352
             print(e.__str__())
1354
             print('----- /*\ *****')
1353
             print('----- /*\ *****')
1355
             raise ValueError('Not allowed content property')
1354
             raise ValueError('Not allowed content property')
1356
 
1355
 
1357
-        return ContentType.sorted(types)
1356
+        return types
1358
 
1357
 
1359
     def get_history(self, drop_empty_revision=False) -> '[VirtualEvent]':
1358
     def get_history(self, drop_empty_revision=False) -> '[VirtualEvent]':
1360
         events = []
1359
         events = []
1447
 
1446
 
1448
     @classmethod
1447
     @classmethod
1449
     def create_from_content(cls, content: Content):
1448
     def create_from_content(cls, content: Content):
1450
-        content_type = ContentType(content.type)
1451
 
1449
 
1452
         label = content.get_label()
1450
         label = content.get_label()
1453
-        if content.type == ContentType.Comment:
1451
+        if content.type == CONTENT_TYPES.Comment.slug:
1454
             # TODO - G.M  - 10-04-2018 - [Cleanup] Remove label param
1452
             # TODO - G.M  - 10-04-2018 - [Cleanup] Remove label param
1455
             # from this object ?
1453
             # from this object ?
1456
             label = l_('<strong>{}</strong> wrote:').format(content.owner.get_display_name())
1454
             label = l_('<strong>{}</strong> wrote:').format(content.owner.get_display_name())
1458
         return VirtualEvent(id=content.content_id,
1456
         return VirtualEvent(id=content.content_id,
1459
                             created=content.created,
1457
                             created=content.created,
1460
                             owner=content.owner,
1458
                             owner=content.owner,
1461
-                            type=content_type,
1459
+                            type=ActionDescription(content.revision_type),
1462
                             label=label,
1460
                             label=label,
1463
                             content=content.description,
1461
                             content=content.description,
1464
                             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',

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

5
 Tests for /api/v2/system subpath endpoints.
5
 Tests for /api/v2/system subpath endpoints.
6
 """
6
 """
7
 
7
 
8
+
8
 class TestApplicationEndpoint(FunctionalTest):
9
 class TestApplicationEndpoint(FunctionalTest):
9
     """
10
     """
10
     Tests for /api/v2/system/applications
11
     Tests for /api/v2/system/applications
96
         res = self.testapp.get('/api/v2/system/content_types', status=200)
97
         res = self.testapp.get('/api/v2/system/content_types', status=200)
97
         res = res.json_body
98
         res = res.json_body
98
 
99
 
99
-        content_type = res[0]
100
+        content_type = res[1]
100
         assert content_type['slug'] == 'thread'
101
         assert content_type['slug'] == 'thread'
101
         assert content_type['fa_icon'] == 'comments-o'
102
         assert content_type['fa_icon'] == 'comments-o'
102
         assert content_type['hexcolor'] == '#ad4cf9'
103
         assert content_type['hexcolor'] == '#ad4cf9'
105
         assert 'available_statuses' in content_type
106
         assert 'available_statuses' in content_type
106
         assert len(content_type['available_statuses']) == 4
107
         assert len(content_type['available_statuses']) == 4
107
 
108
 
108
-        content_type = res[1]
109
+        content_type = res[2]
109
         assert content_type['slug'] == 'file'
110
         assert content_type['slug'] == 'file'
110
         assert content_type['fa_icon'] == 'paperclip'
111
         assert content_type['fa_icon'] == 'paperclip'
111
         assert content_type['hexcolor'] == '#FF9900'
112
         assert content_type['hexcolor'] == '#FF9900'
114
         assert 'available_statuses' in content_type
115
         assert 'available_statuses' in content_type
115
         assert len(content_type['available_statuses']) == 4
116
         assert len(content_type['available_statuses']) == 4
116
 
117
 
117
-        content_type = res[2]
118
+        content_type = res[3]
118
         assert content_type['slug'] == 'markdownpage'
119
         assert content_type['slug'] == 'markdownpage'
119
         assert content_type['fa_icon'] == 'file-code-o'
120
         assert content_type['fa_icon'] == 'file-code-o'
120
         assert content_type['hexcolor'] == '#f12d2d'
121
         assert content_type['hexcolor'] == '#f12d2d'
123
         assert 'available_statuses' in content_type
124
         assert 'available_statuses' in content_type
124
         assert len(content_type['available_statuses']) == 4
125
         assert len(content_type['available_statuses']) == 4
125
 
126
 
126
-        content_type = res[3]
127
+        content_type = res[4]
127
         assert content_type['slug'] == 'html-document'
128
         assert content_type['slug'] == 'html-document'
128
         assert content_type['fa_icon'] == 'file-text-o'
129
         assert content_type['fa_icon'] == 'file-text-o'
129
         assert content_type['hexcolor'] == '#3f52e3'
130
         assert content_type['hexcolor'] == '#3f52e3'

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

13
 from tracim_backend.lib.core.userworkspace import RoleApi
13
 from tracim_backend.lib.core.userworkspace import RoleApi
14
 from tracim_backend.lib.core.workspace import WorkspaceApi
14
 from tracim_backend.lib.core.workspace import WorkspaceApi
15
 from tracim_backend.models import get_tm_session
15
 from tracim_backend.models import get_tm_session
16
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
16
+from tracim_backend.models.contents import CONTENT_TYPES
17
 from tracim_backend.models.data import UserRoleInWorkspace
17
 from tracim_backend.models.data import UserRoleInWorkspace
18
 from tracim_backend.models.revision_protection import new_revision
18
 from tracim_backend.models.revision_protection import new_revision
19
 from tracim_backend.tests import FunctionalTest
19
 from tracim_backend.tests import FunctionalTest
87
             session=dbsession,
87
             session=dbsession,
88
             config=self.app_config,
88
             config=self.app_config,
89
         )
89
         )
90
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
91
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
90
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
91
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
92
         # creation order test
92
         # creation order test
93
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
94
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
93
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
94
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
95
         # update order test
95
         # update order test
96
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
97
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
96
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
97
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
98
         with new_revision(
98
         with new_revision(
99
             session=dbsession,
99
             session=dbsession,
100
             tm=transaction.manager,
100
             tm=transaction.manager,
103
             firstly_created_but_recently_updated.description = 'Just an update'
103
             firstly_created_but_recently_updated.description = 'Just an update'
104
         api.save(firstly_created_but_recently_updated)
104
         api.save(firstly_created_but_recently_updated)
105
         # comment change order
105
         # comment change order
106
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
107
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
106
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
107
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
108
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
108
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
109
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
109
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
110
         dbsession.flush()
110
         dbsession.flush()
111
         transaction.commit()
111
         transaction.commit()
112
 
112
 
205
             session=dbsession,
205
             session=dbsession,
206
             config=self.app_config,
206
             config=self.app_config,
207
         )
207
         )
208
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
209
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
208
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
209
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
210
         # creation order test
210
         # creation order test
211
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
212
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
211
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
212
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
213
         # update order test
213
         # update order test
214
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
215
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
214
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
215
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
216
+
216
         with new_revision(
217
         with new_revision(
217
             session=dbsession,
218
             session=dbsession,
218
             tm=transaction.manager,
219
             tm=transaction.manager,
221
             firstly_created_but_recently_updated.description = 'Just an update'
222
             firstly_created_but_recently_updated.description = 'Just an update'
222
         api.save(firstly_created_but_recently_updated)
223
         api.save(firstly_created_but_recently_updated)
223
         # comment change order
224
         # comment change order
224
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
225
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
225
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
226
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
226
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
227
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
227
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
228
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
228
         dbsession.flush()
229
         dbsession.flush()
229
         transaction.commit()
230
         transaction.commit()
230
 
231
 
301
             session=dbsession,
302
             session=dbsession,
302
             config=self.app_config,
303
             config=self.app_config,
303
         )
304
         )
304
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
305
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
305
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
306
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
306
         # creation order test
307
         # creation order test
307
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
308
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
308
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
309
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
309
         # update order test
310
         # update order test
310
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
311
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
311
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
312
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
312
         with new_revision(
313
         with new_revision(
313
             session=dbsession,
314
             session=dbsession,
314
             tm=transaction.manager,
315
             tm=transaction.manager,
317
             firstly_created_but_recently_updated.description = 'Just an update'
318
             firstly_created_but_recently_updated.description = 'Just an update'
318
         api.save(firstly_created_but_recently_updated)
319
         api.save(firstly_created_but_recently_updated)
319
         # comment change order
320
         # comment change order
320
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
321
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
321
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
322
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
322
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
323
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
323
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
324
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
324
         dbsession.flush()
325
         dbsession.flush()
325
         transaction.commit()
326
         transaction.commit()
326
 
327
 
426
             session=dbsession,
427
             session=dbsession,
427
             config=self.app_config,
428
             config=self.app_config,
428
         )
429
         )
429
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
430
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
430
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
431
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
431
         # creation order test
432
         # creation order test
432
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
433
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
433
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
434
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
434
         # update order test
435
         # update order test
435
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
436
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
436
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
437
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
437
         with new_revision(
438
         with new_revision(
438
             session=dbsession,
439
             session=dbsession,
439
             tm=transaction.manager,
440
             tm=transaction.manager,
442
             firstly_created_but_recently_updated.description = 'Just an update'
443
             firstly_created_but_recently_updated.description = 'Just an update'
443
         api.save(firstly_created_but_recently_updated)
444
         api.save(firstly_created_but_recently_updated)
444
         # comment change order
445
         # comment change order
445
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
446
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
446
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
447
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
447
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
448
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
448
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
449
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
449
         dbsession.flush()
450
         dbsession.flush()
450
         transaction.commit()
451
         transaction.commit()
451
 
452
 
498
             session=dbsession,
499
             session=dbsession,
499
             config=self.app_config,
500
             config=self.app_config,
500
         )
501
         )
501
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
502
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
502
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
503
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
503
         # creation order test
504
         # creation order test
504
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
505
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
505
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
506
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
506
         # update order test
507
         # update order test
507
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
508
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
508
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
509
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
509
         with new_revision(
510
         with new_revision(
510
             session=dbsession,
511
             session=dbsession,
511
             tm=transaction.manager,
512
             tm=transaction.manager,
514
             firstly_created_but_recently_updated.description = 'Just an update'
515
             firstly_created_but_recently_updated.description = 'Just an update'
515
         api.save(firstly_created_but_recently_updated)
516
         api.save(firstly_created_but_recently_updated)
516
         # comment change order
517
         # comment change order
517
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
518
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
518
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
519
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
519
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
520
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
520
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
521
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
521
         dbsession.flush()
522
         dbsession.flush()
522
         transaction.commit()
523
         transaction.commit()
523
 
524
 
610
             session=dbsession,
611
             session=dbsession,
611
             config=self.app_config,
612
             config=self.app_config,
612
         )
613
         )
613
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
614
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
614
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
615
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
615
         # creation order test
616
         # creation order test
616
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
617
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
617
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
618
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
618
         # update order test
619
         # update order test
619
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
620
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
620
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
621
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
621
         with new_revision(
622
         with new_revision(
622
             session=dbsession,
623
             session=dbsession,
623
             tm=transaction.manager,
624
             tm=transaction.manager,
626
             firstly_created_but_recently_updated.description = 'Just an update'
627
             firstly_created_but_recently_updated.description = 'Just an update'
627
         api.save(firstly_created_but_recently_updated)
628
         api.save(firstly_created_but_recently_updated)
628
         # comment change order
629
         # comment change order
629
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
630
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
630
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
631
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
631
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
632
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
632
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
633
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
633
         dbsession.flush()
634
         dbsession.flush()
634
         transaction.commit()
635
         transaction.commit()
635
 
636
 
714
             session=dbsession,
715
             session=dbsession,
715
             config=self.app_config,
716
             config=self.app_config,
716
         )
717
         )
717
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
718
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
718
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
719
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
719
         # creation order test
720
         # creation order test
720
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
721
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
721
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
722
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
722
         # update order test
723
         # update order test
723
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
724
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
724
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
725
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
725
         with new_revision(
726
         with new_revision(
726
             session=dbsession,
727
             session=dbsession,
727
             tm=transaction.manager,
728
             tm=transaction.manager,
730
             firstly_created_but_recently_updated.description = 'Just an update'
731
             firstly_created_but_recently_updated.description = 'Just an update'
731
         api.save(firstly_created_but_recently_updated)
732
         api.save(firstly_created_but_recently_updated)
732
         # comment change order
733
         # comment change order
733
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
734
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
734
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
735
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
735
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
736
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
736
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
737
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
737
         dbsession.flush()
738
         dbsession.flush()
738
         transaction.commit()
739
         transaction.commit()
739
 
740
 
826
             session=dbsession,
827
             session=dbsession,
827
             config=self.app_config,
828
             config=self.app_config,
828
         )
829
         )
829
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
830
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
830
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
831
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
831
         # creation order test
832
         # creation order test
832
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
833
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
833
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
834
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
834
         # update order test
835
         # update order test
835
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
836
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
836
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
837
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
837
         with new_revision(
838
         with new_revision(
838
             session=dbsession,
839
             session=dbsession,
839
             tm=transaction.manager,
840
             tm=transaction.manager,
842
             firstly_created_but_recently_updated.description = 'Just an update'
843
             firstly_created_but_recently_updated.description = 'Just an update'
843
         api.save(firstly_created_but_recently_updated)
844
         api.save(firstly_created_but_recently_updated)
844
         # comment change order
845
         # comment change order
845
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
846
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
846
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
847
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
847
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
848
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
848
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
849
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
849
         dbsession.flush()
850
         dbsession.flush()
850
         transaction.commit()
851
         transaction.commit()
851
 
852
 
949
             session=dbsession,
950
             session=dbsession,
950
             config=self.app_config,
951
             config=self.app_config,
951
         )
952
         )
952
-        main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True)  # nopep8
953
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
953
+        main_folder_workspace2 = api.create(CONTENT_TYPES.Folder.slug, workspace2, None, 'Hepla', '', True)  # nopep8
954
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
954
         # creation order test
955
         # creation order test
955
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
956
-        secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
956
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
957
+        secondly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another creation_order_test', '', True)  # nopep8
957
         # update order test
958
         # update order test
958
-        firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True)  # nopep8
959
-        secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
959
+        firstly_created_but_recently_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'update_order_test', '', True)  # nopep8
960
+        secondly_created_but_not_updated = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'another update_order_test', '', True)  # nopep8
960
         with new_revision(
961
         with new_revision(
961
             session=dbsession,
962
             session=dbsession,
962
             tm=transaction.manager,
963
             tm=transaction.manager,
965
             firstly_created_but_recently_updated.description = 'Just an update'
966
             firstly_created_but_recently_updated.description = 'Just an update'
966
         api.save(firstly_created_but_recently_updated)
967
         api.save(firstly_created_but_recently_updated)
967
         # comment change order
968
         # comment change order
968
-        firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
969
-        secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
969
+        firstly_created_but_recently_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is randomized label content', '', True)  # nopep8
970
+        secondly_created_but_not_commented = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'this is another randomized label content', '', True)  # nopep8
970
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
971
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
971
-        content_workspace_2 = api.create(ContentType.Page, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
972
+        content_workspace_2 = api.create(CONTENT_TYPES.Page.slug, workspace2,main_folder_workspace2, 'content_workspace_2', '',True)  # nopep8
972
         dbsession.flush()
973
         dbsession.flush()
973
         transaction.commit()
974
         transaction.commit()
974
 
975
 
1059
             session=dbsession,
1060
             session=dbsession,
1060
             config=self.app_config,
1061
             config=self.app_config,
1061
         )
1062
         )
1062
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1063
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1063
         # creation order test
1064
         # creation order test
1064
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1065
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1065
         api.mark_unread(firstly_created)
1066
         api.mark_unread(firstly_created)
1066
         api2.mark_unread(firstly_created)
1067
         api2.mark_unread(firstly_created)
1067
         dbsession.flush()
1068
         dbsession.flush()
1167
             session=dbsession,
1168
             session=dbsession,
1168
             config=self.app_config,
1169
             config=self.app_config,
1169
         )
1170
         )
1170
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1171
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1171
         # creation order test
1172
         # creation order test
1172
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1173
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1173
         api.mark_unread(firstly_created)
1174
         api.mark_unread(firstly_created)
1174
         api2.mark_unread(firstly_created)
1175
         api2.mark_unread(firstly_created)
1175
         dbsession.flush()
1176
         dbsession.flush()
1248
             session=dbsession,
1249
             session=dbsession,
1249
             config=self.app_config,
1250
             config=self.app_config,
1250
         )
1251
         )
1251
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1252
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1252
         # creation order test
1253
         # creation order test
1253
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1254
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1254
         api.mark_unread(firstly_created)
1255
         api.mark_unread(firstly_created)
1255
         api2.mark_unread(firstly_created)
1256
         api2.mark_unread(firstly_created)
1256
         dbsession.flush()
1257
         dbsession.flush()
1329
             session=dbsession,
1330
             session=dbsession,
1330
             config=self.app_config,
1331
             config=self.app_config,
1331
         )
1332
         )
1332
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1333
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1333
         # creation order test
1334
         # creation order test
1334
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1335
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1335
         api.mark_unread(firstly_created)
1336
         api.mark_unread(firstly_created)
1336
         api2.mark_unread(firstly_created)
1337
         api2.mark_unread(firstly_created)
1337
         dbsession.flush()
1338
         dbsession.flush()
1428
             session=dbsession,
1429
             session=dbsession,
1429
             config=self.app_config,
1430
             config=self.app_config,
1430
         )
1431
         )
1431
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1432
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1432
         # creation order test
1433
         # creation order test
1433
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1434
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1434
         api.mark_unread(firstly_created)
1435
         api.mark_unread(firstly_created)
1435
         api2.mark_unread(firstly_created)
1436
         api2.mark_unread(firstly_created)
1436
         dbsession.flush()
1437
         dbsession.flush()
1509
             session=dbsession,
1510
             session=dbsession,
1510
             config=self.app_config,
1511
             config=self.app_config,
1511
         )
1512
         )
1512
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1513
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1513
         # creation order test
1514
         # creation order test
1514
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1515
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1515
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
1516
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
1516
         api.mark_unread(firstly_created)
1517
         api.mark_unread(firstly_created)
1517
         api.mark_unread(comments)
1518
         api.mark_unread(comments)
1626
             session=dbsession,
1627
             session=dbsession,
1627
             config=self.app_config,
1628
             config=self.app_config,
1628
         )
1629
         )
1629
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1630
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1630
         # creation order test
1631
         # creation order test
1631
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1632
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1632
         api.mark_read(firstly_created)
1633
         api.mark_read(firstly_created)
1633
         api2.mark_read(firstly_created)
1634
         api2.mark_read(firstly_created)
1634
         dbsession.flush()
1635
         dbsession.flush()
1735
             session=dbsession,
1736
             session=dbsession,
1736
             config=self.app_config,
1737
             config=self.app_config,
1737
         )
1738
         )
1738
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1739
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1739
         # creation order test
1740
         # creation order test
1740
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1741
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1741
         api.mark_read(firstly_created)
1742
         api.mark_read(firstly_created)
1742
         api2.mark_read(firstly_created)
1743
         api2.mark_read(firstly_created)
1743
         dbsession.flush()
1744
         dbsession.flush()
1816
             session=dbsession,
1817
             session=dbsession,
1817
             config=self.app_config,
1818
             config=self.app_config,
1818
         )
1819
         )
1819
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1820
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1820
         # creation order test
1821
         # creation order test
1821
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1822
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1822
         api.mark_read(firstly_created)
1823
         api.mark_read(firstly_created)
1823
         api2.mark_read(firstly_created)
1824
         api2.mark_read(firstly_created)
1824
         dbsession.flush()
1825
         dbsession.flush()
1898
             session=dbsession,
1899
             session=dbsession,
1899
             config=self.app_config,
1900
             config=self.app_config,
1900
         )
1901
         )
1901
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1902
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1902
         # creation order test
1903
         # creation order test
1903
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1904
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1904
         api.mark_read(firstly_created)
1905
         api.mark_read(firstly_created)
1905
         api2.mark_read(firstly_created)
1906
         api2.mark_read(firstly_created)
1906
         dbsession.flush()
1907
         dbsession.flush()
1993
             session=dbsession,
1994
             session=dbsession,
1994
             config=self.app_config,
1995
             config=self.app_config,
1995
         )
1996
         )
1996
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
1997
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
1997
         # creation order test
1998
         # creation order test
1998
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1999
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
1999
         api.mark_read(firstly_created)
2000
         api.mark_read(firstly_created)
2000
         api2.mark_read(firstly_created)
2001
         api2.mark_read(firstly_created)
2001
         dbsession.flush()
2002
         dbsession.flush()
2044
             session=dbsession,
2045
             session=dbsession,
2045
             config=self.app_config,
2046
             config=self.app_config,
2046
         )
2047
         )
2047
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2048
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2048
         # creation order test
2049
         # creation order test
2049
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2050
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2050
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
2051
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
2051
         api.mark_read(firstly_created)
2052
         api.mark_read(firstly_created)
2052
         api.mark_read(comments)
2053
         api.mark_read(comments)
2137
             session=dbsession,
2138
             session=dbsession,
2138
             config=self.app_config,
2139
             config=self.app_config,
2139
         )
2140
         )
2140
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2141
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2141
         # creation order test
2142
         # creation order test
2142
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2143
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2143
         api.mark_unread(main_folder)
2144
         api.mark_unread(main_folder)
2144
         api.mark_unread(firstly_created)
2145
         api.mark_unread(firstly_created)
2145
         api2.mark_unread(main_folder)
2146
         api2.mark_unread(main_folder)
2234
             session=dbsession,
2235
             session=dbsession,
2235
             config=self.app_config,
2236
             config=self.app_config,
2236
         )
2237
         )
2237
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2238
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2238
         # creation order test
2239
         # creation order test
2239
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2240
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2240
         api.mark_unread(main_folder)
2241
         api.mark_unread(main_folder)
2241
         api.mark_unread(firstly_created)
2242
         api.mark_unread(firstly_created)
2242
         api2.mark_unread(main_folder)
2243
         api2.mark_unread(main_folder)
2331
             session=dbsession,
2332
             session=dbsession,
2332
             config=self.app_config,
2333
             config=self.app_config,
2333
         )
2334
         )
2334
-        main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True)  # nopep8
2335
+        main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True)  # nopep8
2335
         # creation order test
2336
         # creation order test
2336
-        firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2337
+        firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True)  # nopep8
2337
         api.mark_unread(main_folder)
2338
         api.mark_unread(main_folder)
2338
         api.mark_unread(firstly_created)
2339
         api.mark_unread(firstly_created)
2339
         api2.mark_unread(main_folder)
2340
         api2.mark_unread(main_folder)

+ 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)  # nopep8
2250
         last_actives = api.get_last_active(workspace=workspace, limit=2)  # 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,

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

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
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.contents import ContentStatusLegacy as ContentStatus
13
 from tracim_backend.models.context_models import ActiveContentFilter
13
 from tracim_backend.models.context_models import ActiveContentFilter
14
 from tracim_backend.models.context_models import ContentIdsQuery
14
 from tracim_backend.models.context_models import ContentIdsQuery
15
 from tracim_backend.models.context_models import UserWorkspaceAndContentPath
15
 from tracim_backend.models.context_models import UserWorkspaceAndContentPath
342
         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"),
343
     )
343
     )
344
     content_type = marshmallow.fields.String(
344
     content_type = marshmallow.fields.String(
345
-        example=ContentType.Any,
346
-        default=ContentType.Any,
347
-        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())
348
     )
348
     )
349
 
349
 
350
     @post_load
350
     @post_load
594
 class ContentTypeSchema(marshmallow.Schema):
594
 class ContentTypeSchema(marshmallow.Schema):
595
     slug = marshmallow.fields.String(
595
     slug = marshmallow.fields.String(
596
         example='pagehtml',
596
         example='pagehtml',
597
-        validate=OneOf(ContentType.allowed_types()),
597
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),
598
     )
598
     )
599
     fa_icon = marshmallow.fields.String(
599
     fa_icon = marshmallow.fields.String(
600
         example='fa-file-text-o',
600
         example='fa-file-text-o',
648
     )
648
     )
649
     content_type = marshmallow.fields.String(
649
     content_type = marshmallow.fields.String(
650
         example='html-document',
650
         example='html-document',
651
-        validate=OneOf(ContentType.allowed_types_for_folding()),  # nopep8
651
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),
652
     )
652
     )
653
     parent_id = marshmallow.fields.Integer(
653
     parent_id = marshmallow.fields.Integer(
654
         example=35,
654
         example=35,
683
     label = marshmallow.fields.Str(example='Intervention Report 12')
683
     label = marshmallow.fields.Str(example='Intervention Report 12')
684
     content_type = marshmallow.fields.Str(
684
     content_type = marshmallow.fields.Str(
685
         example='html-document',
685
         example='html-document',
686
-        validate=OneOf(ContentType.allowed_types()),
686
+        validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug()),
687
     )
687
     )
688
     sub_content_types = marshmallow.fields.List(
688
     sub_content_types = marshmallow.fields.List(
689
         marshmallow.fields.String(
689
         marshmallow.fields.String(
690
             example='html-content',
690
             example='html-content',
691
-            validate=OneOf(ContentType.allowed_types())
691
+            validate=OneOf(CONTENT_TYPES.endpoint_allowed_types_slug())
692
         ),
692
         ),
693
         description='list of content types allowed as sub contents. '
693
         description='list of content types allowed as sub contents. '
694
                     'This field is required for folder contents, '
694
                     'This field is required for folder contents, '
696
     )
696
     )
697
     status = marshmallow.fields.Str(
697
     status = marshmallow.fields.Str(
698
         example='closed-deprecated',
698
         example='closed-deprecated',
699
-        validate=OneOf(ContentStatus.allowed_values()),
699
+        validate=OneOf(CONTENT_STATUS.get_all_slugs_values()),
700
         description='this slug is found in content_type available statuses',
700
         description='this slug is found in content_type available statuses',
701
         default=open_status
701
         default=open_status
702
     )
702
     )
721
 # Content
721
 # Content
722
 #####
722
 #####
723
 
723
 
724
+
724
 class ContentSchema(ContentDigestSchema):
725
 class ContentSchema(ContentDigestSchema):
725
     current_revision_id = marshmallow.fields.Int(example=12)
726
     current_revision_id = marshmallow.fields.Int(example=12)
726
     created = marshmallow.fields.DateTime(
727
     created = marshmallow.fields.DateTime(
840
 class SetContentStatusSchema(marshmallow.Schema):
841
 class SetContentStatusSchema(marshmallow.Schema):
841
     status = marshmallow.fields.Str(
842
     status = marshmallow.fields.Str(
842
         example='closed-deprecated',
843
         example='closed-deprecated',
843
-        validate=OneOf(ContentStatus.allowed_values()),
844
+        validate=OneOf(CONTENT_STATUS.get_all_slugs_values()),
844
         description='this slug is found in content_type available statuses',
845
         description='this slug is found in content_type available statuses',
845
         default=open_status,
846
         default=open_status,
846
         required=True,
847
         required=True,

+ 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:

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

1
 from pyramid.config import Configurator
1
 from pyramid.config import Configurator
2
+
2
 try:  # Python 3.5+
3
 try:  # Python 3.5+
3
     from http import HTTPStatus
4
     from http import HTTPStatus
4
 except ImportError:
5
 except ImportError:
11
 from tracim_backend.lib.core.user import UserApi
12
 from tracim_backend.lib.core.user import UserApi
12
 from tracim_backend.lib.core.workspace import WorkspaceApi
13
 from tracim_backend.lib.core.workspace import WorkspaceApi
13
 from tracim_backend.lib.core.content import ContentApi
14
 from tracim_backend.lib.core.content import ContentApi
14
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
15
 from tracim_backend.views.controllers import Controller
15
 from tracim_backend.views.controllers import Controller
16
 from tracim_backend.lib.utils.authorization import require_same_user_or_profile
16
 from tracim_backend.lib.utils.authorization import require_same_user_or_profile
17
 from tracim_backend.lib.utils.authorization import require_profile
17
 from tracim_backend.lib.utils.authorization import require_profile
32
 from tracim_backend.views.core_api.schemas import ContentDigestSchema
32
 from tracim_backend.views.core_api.schemas import ContentDigestSchema
33
 from tracim_backend.views.core_api.schemas import ActiveContentFilterQuerySchema
33
 from tracim_backend.views.core_api.schemas import ActiveContentFilterQuerySchema
34
 from tracim_backend.views.core_api.schemas import WorkspaceDigestSchema
34
 from tracim_backend.views.core_api.schemas import WorkspaceDigestSchema
35
+from tracim_backend.models.contents import CONTENT_TYPES
35
 
36
 
36
 SWAGGER_TAG__USER_ENDPOINTS = 'Users'
37
 SWAGGER_TAG__USER_ENDPOINTS = 'Users'
37
 
38
 
271
             before_content = api.get_one(
272
             before_content = api.get_one(
272
                 content_id=content_filter.before_content_id,
273
                 content_id=content_filter.before_content_id,
273
                 workspace=workspace,
274
                 workspace=workspace,
274
-                content_type=ContentType.Any
275
+                content_type=CONTENT_TYPES.Any_SLUG
275
             )
276
             )
276
         last_actives = api.get_last_active(
277
         last_actives = api.get_last_active(
277
             workspace=workspace,
278
             workspace=workspace,

+ 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,