Преглед изворни кода

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

Skylsmoi пре 6 година
родитељ
комит
20bca5c7e2
31 измењених фајлова са 670 додато и 680 уклоњено
  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 Прегледај датотеку

@@ -7,6 +7,11 @@ The other is workspace related and is called "workspace role".
7 7
 
8 8
 ## Global profile
9 9
 
10
+|                               | Normal User | Managers    | Admin          |
11
+|-------------------------------|-------------|-------------|----------------|
12
+| slug                            | users       | managers    | administrators |
13
+|-------------------------------|-------------|-------------|---------|
14
+
10 15
 
11 16
 |                               | Normal User | Managers    | Admin   |
12 17
 |-------------------------------|-------------|-------------|---------|
@@ -22,11 +27,18 @@ The other is workspace related and is called "workspace role".
22 27
 | access to all user data (/users/{user_id} endpoints) |personal-only|personal-only| yes     |
23 28
 
24 29
 
30
+
31
+
25 32
 ## Workspace Roles
26 33
 
27 34
 
28 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 42
 | read content                 |  yes   | yes         | yes             | yes               |
31 43
 |------------------------------|--------|-------------|-----------------|-------------------|
32 44
 | create content               |  no    | yes         | yes             | yes               |

+ 7 - 6
backend/tracim_backend/config.py Прегледај датотеку

@@ -3,8 +3,9 @@ from urllib.parse import urlparse
3 3
 from paste.deploy.converters import asbool
4 4
 from tracim_backend.lib.utils.logger import logger
5 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 11
 class CFG(object):
@@ -145,11 +146,11 @@ class CFG(object):
145 146
         ]
146 147
 
147 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 155
         if settings.get('email.notification.from'):
155 156
             raise Exception(

+ 18 - 18
backend/tracim_backend/fixtures/content.py Прегледај датотеку

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

+ 65 - 59
backend/tracim_backend/lib/core/content.py Прегледај датотеку

@@ -34,13 +34,15 @@ from tracim_backend.exceptions import EmptyLabelNotAllowed
34 34
 from tracim_backend.exceptions import ContentNotFound
35 35
 from tracim_backend.exceptions import WorkspacesDoNotMatch
36 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 40
 from tracim_backend.models.revision_protection import new_revision
38 41
 from tracim_backend.models.auth import User
39 42
 from tracim_backend.models.data import ActionDescription
40
-from tracim_backend.models.data import ContentStatus
41 43
 from tracim_backend.models.data import ContentRevisionRO
42 44
 from tracim_backend.models.data import Content
43
-from tracim_backend.models.data import ContentType
45
+
44 46
 from tracim_backend.models.data import NodeTreeItem
45 47
 from tracim_backend.models.data import RevisionReadStatus
46 48
 from tracim_backend.models.data import UserRoleInWorkspace
@@ -75,10 +77,10 @@ def compare_content_for_sorting_by_type_and_name(
75 77
     else:
76 78
         # TODO - D.A. - 2014-12-02 - Manage Content Types Dynamically
77 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 86
         content_1_type_index = content_type_order.index(content1.type)
@@ -105,15 +107,15 @@ class ContentApi(object):
105 107
     SEARCH_SEPARATORS = ',| '
106 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 120
     def __init__(
119 121
             self,
@@ -230,7 +232,7 @@ class ContentApi(object):
230 232
 
231 233
         # Exclude non displayable types
232 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 237
         if workspace:
236 238
             result = result.filter(Content.workspace_id == workspace.workspace_id)
@@ -369,8 +371,8 @@ class ContentApi(object):
369 371
     #     removed_item_ids = removed_item_ids or []  # FDV
370 372
     # 
371 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 376
     #         allowed_node_types = ContentType.all()
375 377
     # 
376 378
     #     parent_id = parent.content_id if parent else None
@@ -395,7 +397,7 @@ class ContentApi(object):
395 397
     #     for folder in folders:
396 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 401
     #             content_type__allowed = folder.properties['allowed_content'][allowed_content_type] == True
400 402
     # 
401 403
     #             if is_folder and content_type__allowed:
@@ -404,12 +406,13 @@ class ContentApi(object):
404 406
     # 
405 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 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 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 416
             label = self.generate_folder_label(workspace, parent)
414 417
 
415 418
         content = Content()
@@ -421,7 +424,7 @@ class ContentApi(object):
421 424
         elif label:
422 425
             content.label = label
423 426
         else:
424
-            if content_type == ContentType.Comment:
427
+            if content_type_slug == CONTENT_TYPES.Comment.slug:
425 428
                 # INFO - G.M - 2018-07-16 - Default label for comments is
426 429
                 # empty string.
427 430
                 content.label = ''
@@ -431,13 +434,13 @@ class ContentApi(object):
431 434
         content.owner = self._user
432 435
         content.parent = parent
433 436
         content.workspace = workspace
434
-        content.type = content_type
437
+        content.type = content_type_slug
435 438
         content.is_temporary = is_temporary
436 439
         content.revision_type = ActionDescription.CREATION
437 440
 
438 441
         if content.type in (
439
-                ContentType.Page,
440
-                ContentType.Thread,
442
+                CONTENT_TYPES.Page.slug,
443
+                CONTENT_TYPES.Thread.slug,
441 444
         ):
442 445
             content.file_extension = '.html'
443 446
 
@@ -447,7 +450,7 @@ class ContentApi(object):
447 450
         return content
448 451
 
449 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 454
         if not content:
452 455
             raise EmptyCommentContentNotAllowed()
453 456
         item = Content()
@@ -456,7 +459,7 @@ class ContentApi(object):
456 459
         if not workspace:
457 460
             workspace = item.parent.workspace
458 461
         item.workspace = workspace
459
-        item.type = ContentType.Comment
462
+        item.type = CONTENT_TYPES.Comment.slug
460 463
         item.description = content
461 464
         item.label = ''
462 465
         item.revision_type = ActionDescription.COMMENT
@@ -492,7 +495,7 @@ class ContentApi(object):
492 495
 
493 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 499
             base_request = base_request.filter(Content.type==content_type)
497 500
 
498 501
         if parent:
@@ -577,20 +580,20 @@ class ContentApi(object):
577 580
         return query.filter(
578 581
             or_(
579 582
                 and_(
580
-                    Content.type == ContentType.File,
583
+                    Content.type == CONTENT_TYPES.File.slug,
581 584
                     Content.label == file_name,
582 585
                     Content.file_extension == file_extension,
583 586
                 ),
584 587
                 and_(
585
-                    Content.type == ContentType.Thread,
588
+                    Content.type == CONTENT_TYPES.Thread.slug,
586 589
                     Content.label == file_name,
587 590
                 ),
588 591
                 and_(
589
-                    Content.type == ContentType.Page,
592
+                    Content.type == CONTENT_TYPES.Page.slug,
590 593
                     Content.label == file_name,
591 594
                 ),
592 595
                 and_(
593
-                    Content.type == ContentType.Folder,
596
+                    Content.type == CONTENT_TYPES.Folder.slug,
594 597
                     Content.label == content_label,
595 598
                 ),
596 599
             )
@@ -671,7 +674,7 @@ class ContentApi(object):
671 674
             # Filter query on label
672 675
             folder_query = query \
673 676
                 .filter(
674
-                    Content.type == ContentType.Folder,
677
+                    Content.type == CONTENT_TYPES.Folder.slug,
675 678
                     Content.label == label,
676 679
                     Content.workspace_id == workspace.workspace_id,
677 680
                 )
@@ -723,22 +726,22 @@ class ContentApi(object):
723 726
 
724 727
         return query.filter(or_(
725 728
             and_(
726
-                Content.type == ContentType.File,
729
+                Content.type == CONTENT_TYPES.File.slug,
727 730
                 file_name_filter,
728 731
                 file_extension_filter,
729 732
             ),
730 733
             and_(
731
-                Content.type == ContentType.Thread,
734
+                Content.type == CONTENT_TYPES.Thread.slug,
732 735
                 file_name_filter,
733 736
                 file_extension_filter,
734 737
             ),
735 738
             and_(
736
-                Content.type == ContentType.Page,
739
+                Content.type == CONTENT_TYPES.Page.slug,
737 740
                 file_name_filter,
738 741
                 file_extension_filter,
739 742
             ),
740 743
             and_(
741
-                Content.type == ContentType.Folder,
744
+                Content.type == CONTENT_TYPES.Folder.slug,
742 745
                 label_filter,
743 746
             ),
744 747
         ))
@@ -844,25 +847,28 @@ class ContentApi(object):
844 847
     def _get_all_query(
845 848
         self,
846 849
         parent_id: int = None,
847
-        content_type: str = ContentType.Any,
850
+        content_type_slug: str = CONTENT_TYPES.Any_SLUG,
848 851
         workspace: Workspace = None
849 852
     ) -> Query:
850 853
         """
851 854
         Extended filter for better "get all data" query
852 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 857
         :param workspace: filter by workspace
855 858
         :return:
856 859
         """
857 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 862
         resultset = self._base_query(workspace)
860 863
 
861
-        if content_type!=ContentType.Any:
864
+        if content_type_slug != CONTENT_TYPES.Any_SLUG:
862 865
             # INFO - G.M - 2018-07-05 - convert with
863 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 873
         if parent_id:
868 874
             resultset = resultset.filter(Content.parent_id==parent_id)
@@ -871,7 +877,7 @@ class ContentApi(object):
871 877
 
872 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 881
         return self._get_all_query(parent_id, content_type, workspace).all()
876 882
 
877 883
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
@@ -895,14 +901,14 @@ class ContentApi(object):
895 901
 
896 902
     # TODO - G.M - 2018-07-17 - [Cleanup] Drop this method if unneeded
897 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 905
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
900 906
         assert content_type is not None# DYN_REMOVE
901 907
         assert isinstance(content_type, str) # DYN_REMOVE
902 908
 
903 909
         resultset = self._base_query(workspace)
904 910
 
905
-        if content_type != ContentType.Any:
911
+        if content_type != CONTENT_TYPES.Any_SLUG:
906 912
             resultset = resultset.filter(Content.type==content_type)
907 913
 
908 914
         resultset = resultset.filter(Content.is_deleted == self._show_deleted)
@@ -919,7 +925,7 @@ class ContentApi(object):
919 925
 
920 926
         resultset = self._base_query(workspace)
921 927
 
922
-        if content_type != ContentType.Any:
928
+        if content_type != CONTENT_TYPES.Any_SLUG:
923 929
             resultset = resultset.filter(Content.type==content_type)
924 930
 
925 931
         return resultset.all()
@@ -945,7 +951,7 @@ class ContentApi(object):
945 951
     #
946 952
     #     resultset = self._base_query(workspace)
947 953
     #
948
-    #     if content_type != ContentType.Any:
954
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
949 955
     #         resultset = resultset.filter(Content.type==content_type)
950 956
     #
951 957
     #     return resultset.all()
@@ -978,7 +984,7 @@ class ContentApi(object):
978 984
                     Content.content_id.in_(content_ids),
979 985
                     and_(
980 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,7 +996,7 @@ class ContentApi(object):
990 996
         before_content_find = False
991 997
         for content in resultset:
992 998
             related_active_content = None
993
-            if ContentType.Comment == content.type:
999
+            if CONTENT_TYPES.Comment.slug == content.type:
994 1000
                 related_active_content = content.parent
995 1001
             else:
996 1002
                 related_active_content = content
@@ -1040,12 +1046,12 @@ class ContentApi(object):
1040 1046
     #         .filter(Content.content_id.in_(not_read_content_ids)) \
1041 1047
     #         .order_by(desc(Content.updated))
1042 1048
     #
1043
-    #     if content_type != ContentType.Any:
1049
+    #     if content_type != CONTENT_TYPES.Any_SLUG:
1044 1050
     #         not_read_contents = not_read_contents.filter(
1045 1051
     #             Content.type==content_type)
1046 1052
     #     else:
1047 1053
     #         not_read_contents = not_read_contents.filter(
1048
-    #             Content.type!=ContentType.Folder)
1054
+    #             Content.type!=CONTENT_TYPES.Folder.slug)
1049 1055
     #
1050 1056
     #     if parent_id:
1051 1057
     #         not_read_contents = not_read_contents.filter(
@@ -1054,7 +1060,7 @@ class ContentApi(object):
1054 1060
     #     result = []
1055 1061
     #     for item in not_read_contents:
1056 1062
     #         new_item = None
1057
-    #         if ContentType.Comment == item.type:
1063
+    #         if CONTENT_TYPES.Comment.slug == item.type:
1058 1064
     #             new_item = item.parent
1059 1065
     #         else:
1060 1066
     #             new_item = item
@@ -1086,7 +1092,7 @@ class ContentApi(object):
1086 1092
         folder.properties = properties
1087 1093
 
1088 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 1096
             content.status = new_status
1091 1097
             content.revision_type = ActionDescription.STATUS_UPDATE
1092 1098
         else:
@@ -1296,7 +1302,7 @@ class ContentApi(object):
1296 1302
                 self.mark_read(child, read_datetime=read_datetime,
1297 1303
                                do_flush=False)
1298 1304
 
1299
-            if ContentType.Comment == content.type:
1305
+            if CONTENT_TYPES.Comment.slug == content.type:
1300 1306
                 self.mark_read(content.parent, read_datetime=read_datetime,
1301 1307
                                do_flush=False, recursive=False)
1302 1308
                 for comment in content.parent.get_comments():
@@ -1416,12 +1422,12 @@ class ContentApi(object):
1416 1422
         return title_keyworded_items
1417 1423
 
1418 1424
     def get_all_types(self) -> typing.List[ContentType]:
1419
-        labels = ContentType.all()
1425
+        labels = CONTENT_TYPES.endpoint_allowed_types_slug()
1420 1426
         content_types = []
1421 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 1432
     # TODO - G.M - 2018-07-24 - [Cleanup] Is this method already needed ?
1427 1433
     def exclude_unavailable(

+ 10 - 10
backend/tracim_backend/lib/mail_notifier/notifier.py Прегледај датотеку

@@ -19,9 +19,9 @@ from tracim_backend.lib.core.workspace import WorkspaceApi
19 19
 from tracim_backend.lib.utils.logger import logger
20 20
 from tracim_backend.models import User
21 21
 from tracim_backend.models.auth import User
22
+from tracim_backend.models.contents import CONTENT_TYPES
22 23
 from tracim_backend.models.data import ActionDescription
23 24
 from tracim_backend.models.data import Content
24
-from tracim_backend.models.data import ContentType
25 25
 from tracim_backend.models.data import UserRoleInWorkspace
26 26
 from tracim_backend.lib.utils.translation import fake_translator as l_, \
27 27
     fake_translator as _
@@ -233,8 +233,8 @@ class EmailManager(object):
233 233
             config=self.config,
234 234
             show_archived=True,
235 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 238
         notifiable_roles = WorkspaceApi(
239 239
             current_user=user,
240 240
             session=self.session,
@@ -455,20 +455,20 @@ class EmailManager(object):
455 455
             content_text = content.description
456 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 459
                 call_to_action_text = l_('Answer')
460 460
                 content_intro = l_('<span id="content-intro-username">{}</span> started a thread entitled:').format(actor.display_name)
461 461
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.label) + \
462 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 465
                 content_intro = l_('<span id="content-intro-username">{}</span> added a file entitled:').format(actor.display_name)
466 466
                 if content.description:
467 467
                     content_text = content.description
468 468
                 else:
469 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 472
                 content_intro = l_('<span id="content-intro-username">{}</span> added a page entitled:').format(actor.display_name)
473 473
                 content_text = '<span id="content-body-only-title">{}</span>'.format(content.label)
474 474
 
@@ -476,11 +476,11 @@ class EmailManager(object):
476 476
             content_text = content.description
477 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 480
                 content_intro = l_('<span id="content-intro-username">{}</span> uploaded a new revision.').format(actor.display_name)
481 481
                 content_text = ''
482 482
 
483
-            elif ContentType.Page == content.type:
483
+            elif CONTENT_TYPES.Page.slug == content.type:
484 484
                 content_intro = l_('<span id="content-intro-username">{}</span> updated this page.').format(actor.display_name)
485 485
                 previous_revision = content.get_previous_revision()
486 486
                 title_diff = ''
@@ -490,7 +490,7 @@ class EmailManager(object):
490 490
                     title_diff + \
491 491
                     htmldiff(previous_revision.description, content.description)
492 492
 
493
-            elif ContentType.Thread == content.type:
493
+            elif CONTENT_TYPES.Thread.slug == content.type:
494 494
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the thread description.').format(actor.display_name)
495 495
                 previous_revision = content.get_previous_revision()
496 496
                 title_diff = ''
@@ -503,7 +503,7 @@ class EmailManager(object):
503 503
         elif ActionDescription.EDITION == action:
504 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 507
                 content_intro = l_('<span id="content-intro-username">{}</span> updated the file description.').format(actor.display_name)
508 508
                 content_text = '<p id="content-body-intro">{}</p>'.format(content.get_label()) + \
509 509
                     content.description

+ 6 - 6
backend/tracim_backend/lib/utils/authorization.py Прегледај датотеку

@@ -5,15 +5,15 @@ import functools
5 5
 from pyramid.interfaces import IAuthorizationPolicy
6 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 11
 try:
12 12
     from json.decoder import JSONDecodeError
13 13
 except ImportError:  # python3.4
14 14
     JSONDecodeError = ValueError
15 15
 
16
-from tracim_backend.models.contents import ContentTypeLegacy as ContentType
16
+from tracim_backend.models.contents import ContentType
17 17
 from tracim_backend.exceptions import InsufficientUserRoleInWorkspace
18 18
 from tracim_backend.exceptions import ContentTypeNotAllowed
19 19
 from tracim_backend.exceptions import InsufficientUserProfile
@@ -133,18 +133,18 @@ def require_candidate_workspace_role(minimal_required_role: int) -> typing.Calla
133 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 138
     Restricts access to specific file type or raise an exception.
139 139
     Check role for candidate_workspace.
140
-    :param content_types: list of NewContentType object
140
+    :param content_types: list of ContentType object
141 141
     :return: decorator
142 142
     """
143 143
     def decorator(func: typing.Callable) -> typing.Callable:
144 144
         @functools.wraps(func)
145 145
         def wrapper(self, context, request: 'TracimRequest') -> typing.Callable:
146 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 148
             content_types_slug = [content_type.slug for content_type in content_types]  # nopep8
149 149
             if current_content_type_slug in content_types_slug:
150 150
                 return func(self, context, request)

+ 3 - 3
backend/tracim_backend/lib/utils/request.py Прегледај датотеку

@@ -15,7 +15,7 @@ from tracim_backend.exceptions import UserNotFoundInTracimRequest
15 15
 from tracim_backend.exceptions import UserDoesNotExist
16 16
 from tracim_backend.exceptions import WorkspaceNotFound
17 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 19
 from tracim_backend.lib.core.content import ContentApi
20 20
 from tracim_backend.lib.core.user import UserApi
21 21
 from tracim_backend.lib.core.workspace import WorkspaceApi
@@ -233,7 +233,7 @@ class TracimRequest(Request):
233 233
             )
234 234
             comment = api.get_one(
235 235
                 comment_id,
236
-                content_type=ContentType.Comment,
236
+                content_type=CONTENT_TYPES.Comment.slug,
237 237
                 workspace=workspace,
238 238
                 parent=content,
239 239
             )
@@ -271,7 +271,7 @@ class TracimRequest(Request):
271 271
                 session=request.dbsession,
272 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 275
         except NoResultFound as exc:
276 276
             raise ContentNotFound(
277 277
                 'Content {} does not exist '

+ 7 - 5
backend/tracim_backend/lib/webdav/dav_provider.py Прегледај датотеку

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

+ 3 - 2
backend/tracim_backend/lib/webdav/design.py Прегледај датотеку

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

+ 37 - 34
backend/tracim_backend/lib/webdav/resources.py Прегледај датотеку

@@ -19,10 +19,11 @@ from tracim_backend.lib.webdav.utils import transform_to_display, HistoryType, \
19 19
     FakeFileStream
20 20
 from tracim_backend.lib.webdav.utils import transform_to_bdd
21 21
 from tracim_backend.lib.core.workspace import WorkspaceApi
22
+from tracim_backend.models.contents import CONTENT_TYPES
22 23
 from tracim_backend.models.data import User, ContentRevisionRO
23 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 27
 from tracim_backend.lib.webdav.design import designThread, designPage
27 28
 
28 29
 from wsgidav import compat
@@ -236,7 +237,7 @@ class WorkspaceResource(DAVCollection):
236 237
 
237 238
         for content in children:
238 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 241
                 self._file_count += 1
241 242
             retlist.append(content.get_label_as_file())
242 243
 
@@ -288,7 +289,7 @@ class WorkspaceResource(DAVCollection):
288 289
             raise DAVError(HTTP_FORBIDDEN)
289 290
 
290 291
         folder = self.content_api.create(
291
-            content_type=ContentType.Folder,
292
+            content_type_slug=CONTENT_TYPES.Folder.slug,
292 293
             workspace=self.workspace,
293 294
             label=label,
294 295
             parent=self.content
@@ -331,12 +332,12 @@ class WorkspaceResource(DAVCollection):
331 332
     def getMemberList(self) -> [_DAVResource]:
332 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 337
         for content in children:
337 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 341
                 members.append(
341 342
                     FolderResource(
342 343
                         path=content_path,
@@ -347,7 +348,7 @@ class WorkspaceResource(DAVCollection):
347 348
                         session=self.session,
348 349
                     )
349 350
                 )
350
-            elif content.type == ContentType.File:
351
+            elif content.type == CONTENT_TYPES.File.slug:
351 352
                 self._file_count += 1
352 353
                 members.append(
353 354
                     FileResource(
@@ -553,7 +554,7 @@ class FolderResource(WorkspaceResource):
553 554
         )
554 555
         visible_children = content_api.get_all(
555 556
             self.content.content_id,
556
-            ContentType.Any,
557
+            CONTENT_TYPES.Any_SLUG,
557 558
             self.workspace,
558 559
         )
559 560
 
@@ -561,7 +562,7 @@ class FolderResource(WorkspaceResource):
561 562
             content_path = '%s/%s' % (self.path, transform_to_display(content.get_label_as_file()))
562 563
 
563 564
             try:
564
-                if content.type == ContentType.Folder:
565
+                if content.type == CONTENT_TYPES.Folder.slug:
565 566
                     members.append(
566 567
                         FolderResource(
567 568
                             path=content_path,
@@ -572,7 +573,7 @@ class FolderResource(WorkspaceResource):
572 573
                             session=self.session,
573 574
                         )
574 575
                     )
575
-                elif content.type == ContentType.File:
576
+                elif content.type == CONTENT_TYPES.File.slug:
576 577
                     self._file_count += 1
577 578
                     members.append(
578 579
                         FileResource(
@@ -592,13 +593,15 @@ class FolderResource(WorkspaceResource):
592 593
                             user=self.user,
593 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 606
         if self._file_count > 0 and self.provider.show_history():
604 607
             members.append(
@@ -708,11 +711,11 @@ class HistoryFolderResource(FolderResource):
708 711
         ret = []
709 712
 
710 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 715
             if (self._is_archived and content.is_archived or
713 716
                 self._is_deleted and content.is_deleted or
714 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 719
                 ret.append(content.get_label_as_file())
717 720
 
718 721
         return ret
@@ -741,7 +744,7 @@ class HistoryFolderResource(FolderResource):
741 744
         if self.content:
742 745
             children = self.content.children
743 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 749
         for content in children:
747 750
             if content.is_archived == self._is_archived and content.is_deleted == self._is_deleted:
@@ -812,13 +815,13 @@ class DeletedFolderResource(HistoryFolderResource):
812 815
         if self.content:
813 816
             children = self.content.children
814 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 820
         for content in children:
818 821
             if content.is_deleted:
819 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 825
                     self._file_count += 1
823 826
 
824 827
         return retlist
@@ -829,13 +832,13 @@ class DeletedFolderResource(HistoryFolderResource):
829 832
         if self.content:
830 833
             children = self.content.children
831 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 837
         for content in children:
835 838
             if content.is_deleted:
836 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 842
                     members.append(
840 843
                         FolderResource(
841 844
                             content_path,
@@ -845,7 +848,7 @@ class DeletedFolderResource(HistoryFolderResource):
845 848
                             user=self.user,
846 849
                             session=self.session,
847 850
                         ))
848
-                elif content.type == ContentType.File:
851
+                elif content.type == CONTENT_TYPES.File.slug:
849 852
                     self._file_count += 1
850 853
                     members.append(
851 854
                         FileResource(
@@ -936,10 +939,10 @@ class ArchivedFolderResource(HistoryFolderResource):
936 939
         retlist = []
937 940
 
938 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 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 946
                 self._file_count += 1
944 947
 
945 948
         return retlist
@@ -950,13 +953,13 @@ class ArchivedFolderResource(HistoryFolderResource):
950 953
         if self.content:
951 954
             children = self.content.children
952 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 958
         for content in children:
956 959
             if content.is_archived:
957 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 963
                     members.append(
961 964
                         FolderResource(
962 965
                             content_path,
@@ -966,7 +969,7 @@ class ArchivedFolderResource(HistoryFolderResource):
966 969
                             user=self.user,
967 970
                             session=self.session,
968 971
                         ))
969
-                elif content.type == ContentType.File:
972
+                elif content.type == CONTENT_TYPES.File.slug:
970 973
                     self._file_count += 1
971 974
                     members.append(
972 975
                         FileResource(
@@ -1053,7 +1056,7 @@ class HistoryFileFolderResource(HistoryFolderResource):
1053 1056
 
1054 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 1060
             return HistoryFileResource(
1058 1061
                 path='%s%s' % (left_side, transform_to_display(revision.file_name)),
1059 1062
                 environ=self.environ,
@@ -1079,7 +1082,7 @@ class HistoryFileFolderResource(HistoryFolderResource):
1079 1082
 
1080 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 1086
                 members.append(HistoryFileResource(
1084 1087
                     path='%s%s' % (left_side, transform_to_display(content.file_name)),
1085 1088
                     environ=self.environ,
@@ -1425,13 +1428,13 @@ class OtherFileResource(FileResource):
1425 1428
         return filestream
1426 1429
 
1427 1430
     def design(self):
1428
-        if self.content.type == ContentType.Page:
1431
+        if self.content.type == CONTENT_TYPES.Page.slug:
1429 1432
             return designPage(self.content, self.content_revision)
1430 1433
         else:
1431 1434
             return designThread(
1432 1435
                 self.content,
1433 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 Прегледај датотеку

@@ -4,12 +4,14 @@ import transaction
4 4
 from os.path import normpath as base_normpath
5 5
 
6 6
 from sqlalchemy.orm import Session
7
+from tracim_backend.models.contents import CONTENT_TYPES
7 8
 from wsgidav import util
8 9
 from wsgidav import compat
9 10
 
10 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 15
 from tracim_backend.models.revision_protection import new_revision
14 16
 
15 17
 
@@ -177,7 +179,7 @@ class FakeFileStream(object):
177 179
 
178 180
         file = self._api.create(
179 181
             filename=self._file_name,
180
-            content_type=ContentType.File,
182
+            content_type_slug=CONTENT_TYPES.File.slug,
181 183
             workspace=self._workspace,
182 184
             parent=self._parent,
183 185
             is_temporary=is_temporary

+ 108 - 143
backend/tracim_backend/models/contents.py Прегледај датотеку

@@ -19,9 +19,9 @@ class GlobalStatus(Enum):
19 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 26
     def __init__(
27 27
             self,
@@ -38,7 +38,7 @@ class NewContentStatus(object):
38 38
         self.hexcolor = hexcolor
39 39
 
40 40
 
41
-open_status = NewContentStatus(
41
+open_status = ContentStatus(
42 42
     slug='open',
43 43
     global_status=GlobalStatus.OPEN.value,
44 44
     label='Open',
@@ -46,7 +46,7 @@ open_status = NewContentStatus(
46 46
     hexcolor='#3f52e3',
47 47
 )
48 48
 
49
-closed_validated_status = NewContentStatus(
49
+closed_validated_status = ContentStatus(
50 50
     slug='closed-validated',
51 51
     global_status=GlobalStatus.CLOSED.value,
52 52
     label='Validated',
@@ -54,7 +54,7 @@ closed_validated_status = NewContentStatus(
54 54
     hexcolor='#008000',
55 55
 )
56 56
 
57
-closed_unvalidated_status = NewContentStatus(
57
+closed_unvalidated_status = ContentStatus(
58 58
     slug='closed-unvalidated',
59 59
     global_status=GlobalStatus.CLOSED.value,
60 60
     label='Cancelled',
@@ -62,7 +62,7 @@ closed_unvalidated_status = NewContentStatus(
62 62
     hexcolor='#f63434',
63 63
 )
64 64
 
65
-closed_deprecated_status = NewContentStatus(
65
+closed_deprecated_status = ContentStatus(
66 66
     slug='closed-deprecated',
67 67
     global_status=GlobalStatus.CLOSED.value,
68 68
     label='Deprecated',
@@ -71,50 +71,44 @@ closed_deprecated_status = NewContentStatus(
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 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 108
 # ContentType
115 109
 
116 110
 
117
-class NewContentType(object):
111
+class ContentType(object):
118 112
     """
119 113
     Future ContentType object class
120 114
     """
@@ -125,8 +119,8 @@ class NewContentType(object):
125 119
             hexcolor: str,
126 120
             label: str,
127 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 125
         self.slug = slug
132 126
         self.fa_icon = fa_icon
@@ -134,169 +128,140 @@ class NewContentType(object):
134 128
         self.label = label
135 129
         self.creation_label = creation_label
136 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 135
     slug='thread',
141 136
     fa_icon=thread.fa_icon,
142 137
     hexcolor=thread.hexcolor,
143 138
     label='Thread',
144 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 144
     slug='file',
150 145
     fa_icon=_file.fa_icon,
151 146
     hexcolor=_file.hexcolor,
152 147
     label='File',
153 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 153
     slug='markdownpage',
159 154
     fa_icon=markdownpluspage.fa_icon,
160 155
     hexcolor=markdownpluspage.hexcolor,
161 156
     label='Rich Markdown File',
162 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 162
     slug='html-document',
168 163
     fa_icon=html_documents.fa_icon,
169 164
     hexcolor=html_documents.hexcolor,
170 165
     label='Text Document',
171 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 171
 # TODO - G.M - 31-05-2018 - Set Better folder params
176
-folder_type = NewContentType(
172
+folder_type = ContentType(
177 173
     slug='folder',
178 174
     fa_icon=thread.fa_icon,
179 175
     hexcolor=thread.hexcolor,
180 176
     label='Folder',
181 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 182
 # TODO - G.M - 31-05-2018 - Set Better Event params
194
-event_type = NewContentType(
183
+event_type = ContentType(
195 184
     slug='event',
196 185
     fa_icon=thread.fa_icon,
197 186
     hexcolor=thread.hexcolor,
198 187
     label='Event',
199 188
     creation_label='Event',
200
-    available_statuses=CONTENT_DEFAULT_STATUS,
189
+    available_statuses=CONTENT_STATUS.get_all(),
201 190
 )
202 191
 
203 192
 # TODO - G.M - 31-05-2018 - Set Better Event params
204
-comment_type = NewContentType(
193
+comment_type = ContentType(
205 194
     slug='comment',
206 195
     fa_icon=thread.fa_icon,
207 196
     hexcolor=thread.hexcolor,
208 197
     label='Comment',
209 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 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 Прегледај датотеку

@@ -16,7 +16,7 @@ from tracim_backend.models.data import UserRoleInWorkspace
16 16
 from tracim_backend.models.roles import WorkspaceRoles
17 17
 from tracim_backend.models.workspace_menu_entries import default_workspace_menu_entry
18 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 22
 class PreviewAllowedDim(object):
@@ -578,7 +578,7 @@ class ContentInContext(object):
578 578
 
579 579
     @property
580 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 582
         return content_type.slug
583 583
 
584 584
     @property
@@ -690,11 +690,7 @@ class RevisionInContext(object):
690 690
 
691 691
     @property
692 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 695
     @property
700 696
     def sub_content_types(self) -> typing.List[str]:

+ 26 - 28
backend/tracim_backend/models/data.py Прегледај датотеку

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

+ 3 - 3
backend/tracim_backend/tests/__init__.py Прегледај датотеку

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

+ 37 - 38
backend/tracim_backend/tests/functional/test_contents.py Прегледај датотеку

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

+ 5 - 5
backend/tracim_backend/tests/functional/test_mail_notification.py Прегледај датотеку

@@ -11,7 +11,7 @@ from tracim_backend.fixtures.users_and_groups import Base as BaseFixture
11 11
 from tracim_backend.fixtures.content import Content as ContentFixture
12 12
 from tracim_backend.lib.utils.utils import get_redis_connection
13 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 16
 from tracim_backend.lib.core.content import ContentApi
17 17
 from tracim_backend.lib.core.user import UserApi
@@ -139,7 +139,7 @@ class TestNotificationsSync(MailHogTest):
139 139
             config=self.app_config,
140 140
         )
141 141
         item = api.create(
142
-            ContentType.Folder,
142
+            CONTENT_TYPES.Folder.slug,
143 143
             workspace,
144 144
             None,
145 145
             'parent',
@@ -147,7 +147,7 @@ class TestNotificationsSync(MailHogTest):
147 147
             do_notify=False,
148 148
         )
149 149
         item2 = api.create(
150
-            ContentType.File,
150
+            CONTENT_TYPES.File.slug,
151 151
             workspace,
152 152
             item,
153 153
             'file1',
@@ -231,7 +231,7 @@ class TestNotificationsAsync(MailHogTest):
231 231
             config=self.app_config,
232 232
         )
233 233
         item = api.create(
234
-            ContentType.Folder,
234
+            CONTENT_TYPES.Folder.slug,
235 235
             workspace,
236 236
             None,
237 237
             'parent',
@@ -239,7 +239,7 @@ class TestNotificationsAsync(MailHogTest):
239 239
             do_notify=False,
240 240
         )
241 241
         item2 = api.create(
242
-            ContentType.File,
242
+            CONTENT_TYPES.File.slug,
243 243
             workspace,
244 244
             item,
245 245
             'file1',

+ 5 - 4
backend/tracim_backend/tests/functional/test_system.py Прегледај датотеку

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

+ 113 - 112
backend/tracim_backend/tests/functional/test_user.py Прегледај датотеку

@@ -13,7 +13,7 @@ from tracim_backend.lib.core.group import GroupApi
13 13
 from tracim_backend.lib.core.userworkspace import RoleApi
14 14
 from tracim_backend.lib.core.workspace import WorkspaceApi
15 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 17
 from tracim_backend.models.data import UserRoleInWorkspace
18 18
 from tracim_backend.models.revision_protection import new_revision
19 19
 from tracim_backend.tests import FunctionalTest
@@ -87,14 +87,14 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
87 87
             session=dbsession,
88 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 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 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 98
         with new_revision(
99 99
             session=dbsession,
100 100
             tm=transaction.manager,
@@ -103,10 +103,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
103 103
             firstly_created_but_recently_updated.description = 'Just an update'
104 104
         api.save(firstly_created_but_recently_updated)
105 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 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 110
         dbsession.flush()
111 111
         transaction.commit()
112 112
 
@@ -205,14 +205,15 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
205 205
             session=dbsession,
206 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 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 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 217
         with new_revision(
217 218
             session=dbsession,
218 219
             tm=transaction.manager,
@@ -221,10 +222,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
221 222
             firstly_created_but_recently_updated.description = 'Just an update'
222 223
         api.save(firstly_created_but_recently_updated)
223 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 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 229
         dbsession.flush()
229 230
         transaction.commit()
230 231
 
@@ -301,14 +302,14 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
301 302
             session=dbsession,
302 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 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 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 313
         with new_revision(
313 314
             session=dbsession,
314 315
             tm=transaction.manager,
@@ -317,10 +318,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
317 318
             firstly_created_but_recently_updated.description = 'Just an update'
318 319
         api.save(firstly_created_but_recently_updated)
319 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 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 325
         dbsession.flush()
325 326
         transaction.commit()
326 327
 
@@ -426,14 +427,14 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
426 427
             session=dbsession,
427 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 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 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 438
         with new_revision(
438 439
             session=dbsession,
439 440
             tm=transaction.manager,
@@ -442,10 +443,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
442 443
             firstly_created_but_recently_updated.description = 'Just an update'
443 444
         api.save(firstly_created_but_recently_updated)
444 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 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 450
         dbsession.flush()
450 451
         transaction.commit()
451 452
 
@@ -498,14 +499,14 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
498 499
             session=dbsession,
499 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 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 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 510
         with new_revision(
510 511
             session=dbsession,
511 512
             tm=transaction.manager,
@@ -514,10 +515,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
514 515
             firstly_created_but_recently_updated.description = 'Just an update'
515 516
         api.save(firstly_created_but_recently_updated)
516 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 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 522
         dbsession.flush()
522 523
         transaction.commit()
523 524
 
@@ -610,14 +611,14 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
610 611
             session=dbsession,
611 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 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 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 622
         with new_revision(
622 623
             session=dbsession,
623 624
             tm=transaction.manager,
@@ -626,10 +627,10 @@ class TestUserRecentlyActiveContentEndpoint(FunctionalTest):
626 627
             firstly_created_but_recently_updated.description = 'Just an update'
627 628
         api.save(firstly_created_but_recently_updated)
628 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 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 634
         dbsession.flush()
634 635
         transaction.commit()
635 636
 
@@ -714,14 +715,14 @@ class TestUserReadStatusEndpoint(FunctionalTest):
714 715
             session=dbsession,
715 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 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 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 726
         with new_revision(
726 727
             session=dbsession,
727 728
             tm=transaction.manager,
@@ -730,10 +731,10 @@ class TestUserReadStatusEndpoint(FunctionalTest):
730 731
             firstly_created_but_recently_updated.description = 'Just an update'
731 732
         api.save(firstly_created_but_recently_updated)
732 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 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 738
         dbsession.flush()
738 739
         transaction.commit()
739 740
 
@@ -826,14 +827,14 @@ class TestUserReadStatusEndpoint(FunctionalTest):
826 827
             session=dbsession,
827 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 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 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 838
         with new_revision(
838 839
             session=dbsession,
839 840
             tm=transaction.manager,
@@ -842,10 +843,10 @@ class TestUserReadStatusEndpoint(FunctionalTest):
842 843
             firstly_created_but_recently_updated.description = 'Just an update'
843 844
         api.save(firstly_created_but_recently_updated)
844 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 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 850
         dbsession.flush()
850 851
         transaction.commit()
851 852
 
@@ -949,14 +950,14 @@ class TestUserReadStatusEndpoint(FunctionalTest):
949 950
             session=dbsession,
950 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 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 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 961
         with new_revision(
961 962
             session=dbsession,
962 963
             tm=transaction.manager,
@@ -965,10 +966,10 @@ class TestUserReadStatusEndpoint(FunctionalTest):
965 966
             firstly_created_but_recently_updated.description = 'Just an update'
966 967
         api.save(firstly_created_but_recently_updated)
967 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 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 973
         dbsession.flush()
973 974
         transaction.commit()
974 975
 
@@ -1059,9 +1060,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1059 1060
             session=dbsession,
1060 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 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 1066
         api.mark_unread(firstly_created)
1066 1067
         api2.mark_unread(firstly_created)
1067 1068
         dbsession.flush()
@@ -1167,9 +1168,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1167 1168
             session=dbsession,
1168 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 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 1174
         api.mark_unread(firstly_created)
1174 1175
         api2.mark_unread(firstly_created)
1175 1176
         dbsession.flush()
@@ -1248,9 +1249,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1248 1249
             session=dbsession,
1249 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 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 1255
         api.mark_unread(firstly_created)
1255 1256
         api2.mark_unread(firstly_created)
1256 1257
         dbsession.flush()
@@ -1329,9 +1330,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1329 1330
             session=dbsession,
1330 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 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 1336
         api.mark_unread(firstly_created)
1336 1337
         api2.mark_unread(firstly_created)
1337 1338
         dbsession.flush()
@@ -1428,9 +1429,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1428 1429
             session=dbsession,
1429 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 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 1435
         api.mark_unread(firstly_created)
1435 1436
         api2.mark_unread(firstly_created)
1436 1437
         dbsession.flush()
@@ -1509,9 +1510,9 @@ class TestUserSetContentAsRead(FunctionalTest):
1509 1510
             session=dbsession,
1510 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 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 1516
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
1516 1517
         api.mark_unread(firstly_created)
1517 1518
         api.mark_unread(comments)
@@ -1626,9 +1627,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
1626 1627
             session=dbsession,
1627 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 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 1633
         api.mark_read(firstly_created)
1633 1634
         api2.mark_read(firstly_created)
1634 1635
         dbsession.flush()
@@ -1735,9 +1736,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
1735 1736
             session=dbsession,
1736 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 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 1742
         api.mark_read(firstly_created)
1742 1743
         api2.mark_read(firstly_created)
1743 1744
         dbsession.flush()
@@ -1816,9 +1817,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
1816 1817
             session=dbsession,
1817 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 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 1823
         api.mark_read(firstly_created)
1823 1824
         api2.mark_read(firstly_created)
1824 1825
         dbsession.flush()
@@ -1898,9 +1899,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
1898 1899
             session=dbsession,
1899 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 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 1905
         api.mark_read(firstly_created)
1905 1906
         api2.mark_read(firstly_created)
1906 1907
         dbsession.flush()
@@ -1993,9 +1994,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
1993 1994
             session=dbsession,
1994 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 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 2000
         api.mark_read(firstly_created)
2000 2001
         api2.mark_read(firstly_created)
2001 2002
         dbsession.flush()
@@ -2044,9 +2045,9 @@ class TestUserSetContentAsUnread(FunctionalTest):
2044 2045
             session=dbsession,
2045 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 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 2051
         comments = api.create_comment(workspace, firstly_created, 'juste a super comment', True)  # nopep8
2051 2052
         api.mark_read(firstly_created)
2052 2053
         api.mark_read(comments)
@@ -2137,9 +2138,9 @@ class TestUserSetWorkspaceAsRead(FunctionalTest):
2137 2138
             session=dbsession,
2138 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 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 2144
         api.mark_unread(main_folder)
2144 2145
         api.mark_unread(firstly_created)
2145 2146
         api2.mark_unread(main_folder)
@@ -2234,9 +2235,9 @@ class TestUserSetWorkspaceAsRead(FunctionalTest):
2234 2235
             session=dbsession,
2235 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 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 2241
         api.mark_unread(main_folder)
2241 2242
         api.mark_unread(firstly_created)
2242 2243
         api2.mark_unread(main_folder)
@@ -2331,9 +2332,9 @@ class TestUserSetWorkspaceAsRead(FunctionalTest):
2331 2332
             session=dbsession,
2332 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 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 2338
         api.mark_unread(main_folder)
2338 2339
         api.mark_unread(firstly_created)
2339 2340
         api2.mark_unread(main_folder)

+ 14 - 14
backend/tracim_backend/tests/functional/test_workspaces.py Прегледај датотеку

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

+ 115 - 115
backend/tracim_backend/tests/library/test_content_api.py Прегледај датотеку

@@ -14,6 +14,7 @@ from tracim_backend.exceptions import SameValueError
14 14
 from tracim_backend.lib.core.workspace import RoleApi
15 15
 # TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi
16 16
 from tracim_backend.lib.core.workspace import WorkspaceApi
17
+from tracim_backend.models.contents import CONTENT_TYPES
17 18
 from tracim_backend.models.revision_protection import new_revision
18 19
 from tracim_backend.models.auth import User
19 20
 from tracim_backend.models.auth import Group
@@ -22,7 +23,6 @@ from tracim_backend.models.data import ActionDescription
22 23
 from tracim_backend.models.data import ContentRevisionRO
23 24
 from tracim_backend.models.data import Workspace
24 25
 from tracim_backend.models.data import Content
25
-from tracim_backend.models.data import ContentType
26 26
 from tracim_backend.models.data import UserRoleInWorkspace
27 27
 from tracim_backend.fixtures.users_and_groups import Test as FixtureTest
28 28
 from tracim_backend.tests import DefaultTest
@@ -129,14 +129,14 @@ class TestContentApi(DefaultTest):
129 129
             config=self.app_config,
130 130
         )
131 131
         item = api.create(
132
-            content_type=ContentType.Folder,
132
+            content_type_slug=CONTENT_TYPES.Folder.slug,
133 133
             workspace=workspace,
134 134
             parent=None,
135 135
             label='not_deleted',
136 136
             do_save=True
137 137
         )
138 138
         item2 = api.create(
139
-            content_type=ContentType.Folder,
139
+            content_type_slug=CONTENT_TYPES.Folder.slug,
140 140
             workspace=workspace,
141 141
             parent=None,
142 142
             label='to_delete',
@@ -159,10 +159,10 @@ class TestContentApi(DefaultTest):
159 159
             session=self.session,
160 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 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 166
         with new_revision(
167 167
                 session=self.session,
168 168
                 tm=transaction.manager,
@@ -184,7 +184,7 @@ class TestContentApi(DefaultTest):
184 184
             session=self.session,
185 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 188
         eq_(1, len(items))
189 189
         transaction.commit()
190 190
 
@@ -202,7 +202,7 @@ class TestContentApi(DefaultTest):
202 202
             config=self.app_config,
203 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 206
         eq_(2, len(items))
207 207
 
208 208
     def test_archive(self):
@@ -240,14 +240,14 @@ class TestContentApi(DefaultTest):
240 240
             config=self.app_config,
241 241
         )
242 242
         item = api.create(
243
-            content_type=ContentType.Folder,
243
+            content_type_slug=CONTENT_TYPES.Folder.slug,
244 244
             workspace=workspace,
245 245
             parent=None,
246 246
             label='not_archived',
247 247
             do_save=True
248 248
         )
249 249
         item2 = api.create(
250
-            content_type=ContentType.Folder,
250
+            content_type_slug=CONTENT_TYPES.Folder.slug,
251 251
             workspace=workspace,
252 252
             parent=None,
253 253
             label='to_archive',
@@ -269,10 +269,10 @@ class TestContentApi(DefaultTest):
269 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 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 276
         with new_revision(
277 277
                 session=self.session,
278 278
                 tm=transaction.manager,
@@ -295,7 +295,7 @@ class TestContentApi(DefaultTest):
295 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 299
         eq_(1, len(items))
300 300
         transaction.commit()
301 301
 
@@ -320,7 +320,7 @@ class TestContentApi(DefaultTest):
320 320
             config=self.app_config,
321 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 324
         eq_(2, len(items))
325 325
 
326 326
     def test_get_all_with_filter(self):
@@ -358,14 +358,14 @@ class TestContentApi(DefaultTest):
358 358
             config=self.app_config,
359 359
         )
360 360
         item = api.create(
361
-            content_type=ContentType.Folder,
361
+            content_type_slug=CONTENT_TYPES.Folder.slug,
362 362
             workspace=workspace,
363 363
             parent=None,
364 364
             label='thefolder',
365 365
             do_save=True
366 366
         )
367 367
         item2 = api.create(
368
-            content_type=ContentType.File,
368
+            content_type_slug=CONTENT_TYPES.File.slug,
369 369
             workspace=workspace,
370 370
             parent=None,
371 371
             label='thefile',
@@ -389,14 +389,14 @@ class TestContentApi(DefaultTest):
389 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 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 396
         eq_(1, len(items2))
397 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 400
         eq_(1, len(items3))
401 401
         eq_('thefolder', items3[0].label)
402 402
 
@@ -428,21 +428,21 @@ class TestContentApi(DefaultTest):
428 428
             config=self.app_config,
429 429
         )
430 430
         item = api.create(
431
-            ContentType.Folder,
431
+            CONTENT_TYPES.Folder.slug,
432 432
             workspace,
433 433
             None,
434 434
             'parent',
435 435
             do_save=True,
436 436
         )
437 437
         item2 = api.create(
438
-            ContentType.File,
438
+            CONTENT_TYPES.File.slug,
439 439
             workspace,
440 440
             item,
441 441
             'file1',
442 442
             do_save=True,
443 443
         )
444 444
         item3 = api.create(
445
-            ContentType.File,
445
+            CONTENT_TYPES.File.slug,
446 446
             workspace,
447 447
             None,
448 448
             'file2',
@@ -468,10 +468,10 @@ class TestContentApi(DefaultTest):
468 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 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 475
         eq_(1, len(items2))
476 476
         eq_(child_id, items2[0].content_id)
477 477
 
@@ -506,7 +506,7 @@ class TestContentApi(DefaultTest):
506 506
             session=self.session,
507 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 510
         with new_revision(
511 511
             session=self.session,
512 512
             tm=transaction.manager,
@@ -546,7 +546,7 @@ class TestContentApi(DefaultTest):
546 546
             session=self.session,
547 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 550
         with new_revision(
551 551
             session=self.session,
552 552
             tm=transaction.manager,
@@ -591,14 +591,14 @@ class TestContentApi(DefaultTest):
591 591
             session=self.session,
592 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 595
         c = api.create_comment(workspace, p, 'this is the comment', True)
596 596
 
597 597
         eq_(Content, c.__class__)
598 598
         eq_(p.content_id, c.parent_id)
599 599
         eq_(user, c.owner)
600 600
         eq_(workspace, c.workspace)
601
-        eq_(ContentType.Comment, c.type)
601
+        eq_(CONTENT_TYPES.Comment.slug, c.type)
602 602
         eq_('this is the comment', c.description)
603 603
         eq_('', c.label)
604 604
         eq_(ActionDescription.COMMENT, c.revision_type)
@@ -652,7 +652,7 @@ class TestContentApi(DefaultTest):
652 652
             config=self.app_config,
653 653
         )
654 654
         foldera = api.create(
655
-            ContentType.Folder,
655
+            CONTENT_TYPES.Folder.slug,
656 656
             workspace,
657 657
             None,
658 658
             'folder a',
@@ -661,7 +661,7 @@ class TestContentApi(DefaultTest):
661 661
         )
662 662
         with self.session.no_autoflush:
663 663
             text_file = api.create(
664
-                content_type=ContentType.File,
664
+                content_type_slug=CONTENT_TYPES.File.slug,
665 665
                 workspace=workspace,
666 666
                 parent=foldera,
667 667
                 label='test_file',
@@ -689,7 +689,7 @@ class TestContentApi(DefaultTest):
689 689
             save_now=True
690 690
         )
691 691
         folderb = api2.create(
692
-            ContentType.Folder,
692
+            CONTENT_TYPES.Folder.slug,
693 693
             workspace2,
694 694
             None,
695 695
             'folder b',
@@ -773,7 +773,7 @@ class TestContentApi(DefaultTest):
773 773
             config=self.app_config,
774 774
         )
775 775
         foldera = api.create(
776
-            ContentType.Folder,
776
+            CONTENT_TYPES.Folder.slug,
777 777
             workspace,
778 778
             None,
779 779
             'folder a',
@@ -782,7 +782,7 @@ class TestContentApi(DefaultTest):
782 782
         )
783 783
         with self.session.no_autoflush:
784 784
             text_file = api.create(
785
-                content_type=ContentType.File,
785
+                content_type_slug=CONTENT_TYPES.File.slug,
786 786
                 workspace=workspace,
787 787
                 parent=foldera,
788 788
                 label='test_file',
@@ -810,7 +810,7 @@ class TestContentApi(DefaultTest):
810 810
             save_now=True
811 811
         )
812 812
         folderb = api2.create(
813
-            ContentType.Folder,
813
+            CONTENT_TYPES.Folder.slug,
814 814
             workspace2,
815 815
             None,
816 816
             'folder b',
@@ -891,7 +891,7 @@ class TestContentApi(DefaultTest):
891 891
             config=self.app_config,
892 892
         )
893 893
         foldera = api.create(
894
-            ContentType.Folder,
894
+            CONTENT_TYPES.Folder.slug,
895 895
             workspace,
896 896
             None,
897 897
             'folder a',
@@ -900,7 +900,7 @@ class TestContentApi(DefaultTest):
900 900
         )
901 901
         with self.session.no_autoflush:
902 902
             text_file = api.create(
903
-                content_type=ContentType.File,
903
+                content_type_slug=CONTENT_TYPES.File.slug,
904 904
                 workspace=workspace,
905 905
                 parent=foldera,
906 906
                 label='test_file',
@@ -1014,13 +1014,13 @@ class TestContentApi(DefaultTest):
1014 1014
 
1015 1015
         # Creates page_1 & page_2 in workspace 1
1016 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 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 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 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 1024
                                    'this is page3', do_save=True)
1025 1025
 
1026 1026
         for rev in page_1.revisions:
@@ -1118,7 +1118,7 @@ class TestContentApi(DefaultTest):
1118 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 1122
                                    'this is a page', do_save=True)
1123 1123
 
1124 1124
         for rev in page_1.revisions:
@@ -1187,21 +1187,21 @@ class TestContentApi(DefaultTest):
1187 1187
         )
1188 1188
 
1189 1189
         page_2 = cont_api_a.create(
1190
-            ContentType.Page,
1190
+            CONTENT_TYPES.Page.slug,
1191 1191
             workspace,
1192 1192
             None,
1193 1193
             'this is page1',
1194 1194
             do_save=True
1195 1195
         )
1196 1196
         page_3 = cont_api_a.create(
1197
-            ContentType.Thread,
1197
+            CONTENT_TYPES.Thread.slug,
1198 1198
             workspace,
1199 1199
             None,
1200 1200
             'this is page2',
1201 1201
             do_save=True
1202 1202
         )
1203 1203
         page_4 = cont_api_a.create(
1204
-            ContentType.File,
1204
+            CONTENT_TYPES.File.slug,
1205 1205
             workspace,
1206 1206
             None,
1207 1207
             'this is page3',
@@ -1285,7 +1285,7 @@ class TestContentApi(DefaultTest):
1285 1285
         )
1286 1286
 
1287 1287
         p = api.create(
1288
-            content_type=ContentType.Page,
1288
+            content_type_slug=CONTENT_TYPES.Page.slug,
1289 1289
             workspace=workspace,
1290 1290
             parent=None,
1291 1291
             label='this_is_a_page',
@@ -1312,7 +1312,7 @@ class TestContentApi(DefaultTest):
1312 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 1316
         eq_(u1id, content.owner_id)
1317 1317
         eq_(poid, content.owner_id)
1318 1318
 
@@ -1326,7 +1326,7 @@ class TestContentApi(DefaultTest):
1326 1326
             session=self.session,
1327 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 1330
         with new_revision(
1331 1331
            session=self.session,
1332 1332
            tm=transaction.manager,
@@ -1353,7 +1353,7 @@ class TestContentApi(DefaultTest):
1353 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 1357
         eq_(u2id, updated.owner_id,
1358 1358
             'the owner id should be {} (found {})'.format(u2id,
1359 1359
                                                           updated.owner_id))
@@ -1412,7 +1412,7 @@ class TestContentApi(DefaultTest):
1412 1412
         )
1413 1413
         with self.session.no_autoflush:
1414 1414
             page = api.create(
1415
-                content_type=ContentType.Page,
1415
+                content_type_slug=CONTENT_TYPES.Page.slug,
1416 1416
                 workspace=workspace,
1417 1417
                 label="same_content",
1418 1418
                 do_save=False
@@ -1426,7 +1426,7 @@ class TestContentApi(DefaultTest):
1426 1426
             session=self.session,
1427 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 1430
         with new_revision(
1431 1431
            session=self.session,
1432 1432
            tm=transaction.manager,
@@ -1495,7 +1495,7 @@ class TestContentApi(DefaultTest):
1495 1495
             config=self.app_config,
1496 1496
         )
1497 1497
         p = api.create(
1498
-            content_type=ContentType.File,
1498
+            content_type_slug=CONTENT_TYPES.File.slug,
1499 1499
             workspace=workspace,
1500 1500
             parent=None,
1501 1501
             label='this_is_a_page',
@@ -1524,7 +1524,7 @@ class TestContentApi(DefaultTest):
1524 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 1528
         eq_(u1id, content.owner_id)
1529 1529
         eq_(poid, content.owner_id)
1530 1530
 
@@ -1538,7 +1538,7 @@ class TestContentApi(DefaultTest):
1538 1538
             session=self.session,
1539 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 1542
         with new_revision(
1543 1543
             session=self.session,
1544 1544
             tm=transaction.manager,
@@ -1561,7 +1561,7 @@ class TestContentApi(DefaultTest):
1561 1561
             config=self.app_config,
1562 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 1565
         eq_(u2id, updated.owner_id,
1566 1566
             'the owner id should be {} (found {})'.format(u2id,
1567 1567
                                                           updated.owner_id))
@@ -1622,7 +1622,7 @@ class TestContentApi(DefaultTest):
1622 1622
         )
1623 1623
         with self.session.no_autoflush:
1624 1624
             page = api.create(
1625
-                content_type=ContentType.Page,
1625
+                content_type_slug=CONTENT_TYPES.Page.slug,
1626 1626
                 workspace=workspace,
1627 1627
                 label="same_content",
1628 1628
                 do_save=False
@@ -1641,7 +1641,7 @@ class TestContentApi(DefaultTest):
1641 1641
             session=self.session,
1642 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 1645
         with new_revision(
1646 1646
             session=self.session,
1647 1647
             tm=transaction.manager,
@@ -1713,7 +1713,7 @@ class TestContentApi(DefaultTest):
1713 1713
             config=self.app_config,
1714 1714
         )
1715 1715
         p = api.create(
1716
-            content_type=ContentType.File,
1716
+            content_type_slug=CONTENT_TYPES.File.slug,
1717 1717
             workspace=workspace,
1718 1718
             parent=None,
1719 1719
             label='this_is_a_page',
@@ -1741,7 +1741,7 @@ class TestContentApi(DefaultTest):
1741 1741
             config=self.app_config,
1742 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 1745
         eq_(u1id, content.owner_id)
1746 1746
         eq_(poid, content.owner_id)
1747 1747
 
@@ -1757,7 +1757,7 @@ class TestContentApi(DefaultTest):
1757 1757
             config=self.app_config,
1758 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 1761
         with new_revision(
1762 1762
                 session=self.session,
1763 1763
                 tm=transaction.manager,
@@ -1796,7 +1796,7 @@ class TestContentApi(DefaultTest):
1796 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 1800
         eq_(u2id, updated.owner_id,
1801 1801
             'the owner id should be {} (found {})'.format(u2id,
1802 1802
                                                           updated.owner_id))
@@ -1805,7 +1805,7 @@ class TestContentApi(DefaultTest):
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 1809
         with new_revision(
1810 1810
             session=self.session,
1811 1811
             tm=transaction.manager,
@@ -1874,7 +1874,7 @@ class TestContentApi(DefaultTest):
1874 1874
             show_deleted=True,
1875 1875
         )
1876 1876
         p = api.create(
1877
-            content_type=ContentType.File,
1877
+            content_type_slug=CONTENT_TYPES.File.slug,
1878 1878
             workspace=workspace,
1879 1879
             parent=None,
1880 1880
             label='this_is_a_page',
@@ -1900,7 +1900,7 @@ class TestContentApi(DefaultTest):
1900 1900
             config=self.app_config,
1901 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 1904
         eq_(u1id, content.owner_id)
1905 1905
         eq_(poid, content.owner_id)
1906 1906
 
@@ -1915,7 +1915,7 @@ class TestContentApi(DefaultTest):
1915 1915
             config=self.app_config,
1916 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 1919
         with new_revision(
1920 1920
                 session=self.session,
1921 1921
                 tm=transaction.manager,
@@ -1956,7 +1956,7 @@ class TestContentApi(DefaultTest):
1956 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 1960
         eq_(u2id, updated.owner_id,
1961 1961
             'the owner id should be {} (found {})'.format(u2id,
1962 1962
                                                           updated.owner_id))
@@ -1965,7 +1965,7 @@ class TestContentApi(DefaultTest):
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 1969
         with new_revision(
1970 1970
             tm=transaction.manager,
1971 1971
             session=self.session,
@@ -2016,14 +2016,14 @@ class TestContentApi(DefaultTest):
2016 2016
             session=self.session,
2017 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 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 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 2027
         with new_revision(
2028 2028
             session=self.session,
2029 2029
             tm=transaction.manager,
@@ -2032,11 +2032,11 @@ class TestContentApi(DefaultTest):
2032 2032
             firstly_created_but_recently_updated.description = 'Just an update'
2033 2033
         api.save(firstly_created_but_recently_updated)
2034 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 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 2040
         last_actives = api.get_last_active()
2041 2041
         assert len(last_actives) == 9
2042 2042
         # workspace_2 content
@@ -2088,13 +2088,13 @@ class TestContentApi(DefaultTest):
2088 2088
             session=self.session,
2089 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 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 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 2098
         with new_revision(
2099 2099
             session=self.session,
2100 2100
             tm=transaction.manager,
@@ -2103,8 +2103,8 @@ class TestContentApi(DefaultTest):
2103 2103
             firstly_created_but_recently_updated.description = 'Just an update'
2104 2104
         api.save(firstly_created_but_recently_updated)
2105 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 2108
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2109 2109
 
2110 2110
         last_actives = api.get_last_active(workspace=workspace)
@@ -2153,13 +2153,13 @@ class TestContentApi(DefaultTest):
2153 2153
             session=self.session,
2154 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 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 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 2163
         with new_revision(
2164 2164
             session=self.session,
2165 2165
             tm=transaction.manager,
@@ -2168,8 +2168,8 @@ class TestContentApi(DefaultTest):
2168 2168
             firstly_created_but_recently_updated.description = 'Just an update'
2169 2169
         api.save(firstly_created_but_recently_updated)
2170 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 2173
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2174 2174
 
2175 2175
         selected_contents = [
@@ -2228,13 +2228,13 @@ class TestContentApi(DefaultTest):
2228 2228
             session=self.session,
2229 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 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 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 2238
         with new_revision(
2239 2239
             session=self.session,
2240 2240
             tm=transaction.manager,
@@ -2243,8 +2243,8 @@ class TestContentApi(DefaultTest):
2243 2243
             firstly_created_but_recently_updated.description = 'Just an update'
2244 2244
         api.save(firstly_created_but_recently_updated)
2245 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 2248
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2249 2249
 
2250 2250
         last_actives = api.get_last_active(workspace=workspace, limit=2)  # nopep8
@@ -2309,13 +2309,13 @@ class TestContentApi(DefaultTest):
2309 2309
             session=self.session,
2310 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 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 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 2319
         with new_revision(
2320 2320
             session=self.session,
2321 2321
             tm=transaction.manager,
@@ -2324,8 +2324,8 @@ class TestContentApi(DefaultTest):
2324 2324
             firstly_created_but_recently_updated.description = 'Just an update'
2325 2325
         api.save(firstly_created_but_recently_updated)
2326 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 2329
         comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True)  # nopep8
2330 2330
 
2331 2331
         last_actives = api.get_last_active(workspace=workspace2)
@@ -2366,9 +2366,9 @@ class TestContentApi(DefaultTest):
2366 2366
             session=self.session,
2367 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 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 2372
                        'this is randomized label content', '', True)
2373 2373
 
2374 2374
         with new_revision(
@@ -2422,9 +2422,9 @@ class TestContentApi(DefaultTest):
2422 2422
             session=self.session,
2423 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 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 2428
                        'this is dummy label content', '', True)
2429 2429
 
2430 2430
         with new_revision(
@@ -2476,21 +2476,21 @@ class TestContentApi(DefaultTest):
2476 2476
             config=self.app_config,
2477 2477
         )
2478 2478
         a = api.create(
2479
-            content_type=ContentType.Folder,
2479
+            content_type_slug=CONTENT_TYPES.Folder.slug,
2480 2480
             workspace=workspace,
2481 2481
             parent=None,
2482 2482
             label='this is randomized folder',
2483 2483
             do_save=True
2484 2484
         )
2485 2485
         p1 = api.create(
2486
-            content_type=ContentType.Page,
2486
+            content_type_slug=CONTENT_TYPES.Page.slug,
2487 2487
             workspace=workspace,
2488 2488
             parent=a,
2489 2489
             label='this is dummy label content',
2490 2490
             do_save=True
2491 2491
         )
2492 2492
         p2 = api.create(
2493
-            content_type=ContentType.Page,
2493
+            content_type_slug=CONTENT_TYPES.Page.slug,
2494 2494
             workspace=workspace,
2495 2495
             parent=a,
2496 2496
             label='Hey ! Jon !',
@@ -2540,22 +2540,22 @@ class TestContentApi(DefaultTest):
2540 2540
         folder_1 = self._create_content_and_test(
2541 2541
             'folder_1',
2542 2542
             workspace=workspace,
2543
-            type=ContentType.Folder
2543
+            type=CONTENT_TYPES.Folder.slug
2544 2544
         )
2545 2545
         folder_2 = self._create_content_and_test(
2546 2546
             'folder_2',
2547 2547
             workspace=workspace,
2548
-            type=ContentType.Folder
2548
+            type=CONTENT_TYPES.Folder.slug
2549 2549
         )
2550 2550
         page_1 = self._create_content_and_test(
2551 2551
             'foo', workspace=workspace,
2552
-            type=ContentType.Page,
2552
+            type=CONTENT_TYPES.Page.slug,
2553 2553
             parent=folder_1
2554 2554
         )
2555 2555
         page_2 = self._create_content_and_test(
2556 2556
             'bar',
2557 2557
             workspace=workspace,
2558
-            type=ContentType.Page,
2558
+            type=CONTENT_TYPES.Page.slug,
2559 2559
             parent=folder_2
2560 2560
         )
2561 2561
 
@@ -2636,7 +2636,7 @@ class TestContentApiSecurity(DefaultTest):
2636 2636
             session=self.session,
2637 2637
             config=self.app_config,
2638 2638
         ).create(
2639
-            content_type=ContentType.Page,
2639
+            content_type_slug=CONTENT_TYPES.Page.slug,
2640 2640
             workspace=bob_workspace,
2641 2641
             label='bob_page',
2642 2642
             do_save=True,
@@ -2647,7 +2647,7 @@ class TestContentApiSecurity(DefaultTest):
2647 2647
             session=self.session,
2648 2648
             config=self.app_config,
2649 2649
         ).create(
2650
-            content_type=ContentType.Page,
2650
+            content_type_slug=CONTENT_TYPES.Page.slug,
2651 2651
             workspace=admin_workspace,
2652 2652
             label='admin_page',
2653 2653
             do_save=True,

+ 6 - 6
backend/tracim_backend/tests/models/test_content.py Прегледај датотеку

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

+ 4 - 3
backend/tracim_backend/tests/models/test_content_revision.py Прегледај датотеку

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

+ 5 - 5
backend/tracim_backend/views/contents_api/comment_controller.py Прегледај датотеку

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

+ 14 - 14
backend/tracim_backend/views/contents_api/file_controller.py Прегледај датотеку

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

+ 5 - 5
backend/tracim_backend/views/contents_api/html_document_controller.py Прегледај датотеку

@@ -26,7 +26,7 @@ from tracim_backend.lib.utils.authorization import require_workspace_role
26 26
 from tracim_backend.exceptions import EmptyLabelNotAllowed
27 27
 from tracim_backend.models.context_models import ContentInContext
28 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 30
 from tracim_backend.models.contents import html_documents_type
31 31
 from tracim_backend.models.revision_protection import new_revision
32 32
 
@@ -52,7 +52,7 @@ class HTMLDocumentController(Controller):
52 52
         )
53 53
         content = api.get_one(
54 54
             hapic_data.path.content_id,
55
-            content_type=ContentType.Any
55
+            content_type=CONTENT_TYPES.Any_SLUG
56 56
         )
57 57
         return api.get_content_in_context(content)
58 58
 
@@ -75,7 +75,7 @@ class HTMLDocumentController(Controller):
75 75
         )
76 76
         content = api.get_one(
77 77
             hapic_data.path.content_id,
78
-            content_type=ContentType.Any
78
+            content_type=CONTENT_TYPES.Any_SLUG
79 79
         )
80 80
         with new_revision(
81 81
                 session=request.dbsession,
@@ -113,7 +113,7 @@ class HTMLDocumentController(Controller):
113 113
         )
114 114
         content = api.get_one(
115 115
             hapic_data.path.content_id,
116
-            content_type=ContentType.Any
116
+            content_type=CONTENT_TYPES.Any_SLUG
117 117
         )
118 118
         revisions = content.revisions
119 119
         return [
@@ -144,7 +144,7 @@ class HTMLDocumentController(Controller):
144 144
         )
145 145
         content = api.get_one(
146 146
             hapic_data.path.content_id,
147
-            content_type=ContentType.Any
147
+            content_type=CONTENT_TYPES.Any_SLUG
148 148
         )
149 149
         with new_revision(
150 150
                 session=request.dbsession,

+ 5 - 5
backend/tracim_backend/views/contents_api/threads_controller.py Прегледај датотеку

@@ -25,7 +25,7 @@ from tracim_backend.lib.utils.authorization import require_workspace_role
25 25
 from tracim_backend.exceptions import EmptyLabelNotAllowed
26 26
 from tracim_backend.models.context_models import ContentInContext
27 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 29
 from tracim_backend.models.contents import thread_type
30 30
 from tracim_backend.models.revision_protection import new_revision
31 31
 
@@ -51,7 +51,7 @@ class ThreadController(Controller):
51 51
         )
52 52
         content = api.get_one(
53 53
             hapic_data.path.content_id,
54
-            content_type=ContentType.Any
54
+            content_type=CONTENT_TYPES.Any_SLUG
55 55
         )
56 56
         return api.get_content_in_context(content)
57 57
 
@@ -74,7 +74,7 @@ class ThreadController(Controller):
74 74
         )
75 75
         content = api.get_one(
76 76
             hapic_data.path.content_id,
77
-            content_type=ContentType.Any
77
+            content_type=CONTENT_TYPES.Any_SLUG
78 78
         )
79 79
         with new_revision(
80 80
                 session=request.dbsession,
@@ -112,7 +112,7 @@ class ThreadController(Controller):
112 112
         )
113 113
         content = api.get_one(
114 114
             hapic_data.path.content_id,
115
-            content_type=ContentType.Any
115
+            content_type=CONTENT_TYPES.Any_SLUG
116 116
         )
117 117
         revisions = content.revisions
118 118
         return [
@@ -138,7 +138,7 @@ class ThreadController(Controller):
138 138
         )
139 139
         content = api.get_one(
140 140
             hapic_data.path.content_id,
141
-            content_type=ContentType.Any
141
+            content_type=CONTENT_TYPES.Any_SLUG
142 142
         )
143 143
         with new_revision(
144 144
                 session=request.dbsession,

+ 12 - 11
backend/tracim_backend/views/core_api/schemas.py Прегледај датотеку

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

+ 3 - 3
backend/tracim_backend/views/core_api/system_controller.py Прегледај датотеку

@@ -5,7 +5,7 @@ from tracim_backend.exceptions import InsufficientUserProfile
5 5
 from tracim_backend.lib.utils.authorization import require_profile
6 6
 from tracim_backend.models import Group
7 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 10
 try:  # Python 3.5+
11 11
     from http import HTTPStatus
@@ -39,8 +39,8 @@ class SystemController(Controller):
39 39
         """
40 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 44
         return content_types
45 45
 
46 46
     def bind(self, configurator: Configurator) -> None:

+ 3 - 2
backend/tracim_backend/views/core_api/user_controller.py Прегледај датотеку

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

+ 11 - 11
backend/tracim_backend/views/core_api/workspace_controller.py Прегледај датотеку

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