瀏覽代碼

add content_filter to workspace_content endpoint

Guénaël Muller 6 年之前
父節點
當前提交
2471e19b3c

+ 2 - 2
tracim/lib/core/content.py 查看文件

713
 
713
 
714
     def get_all(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> typing.List[Content]:
714
     def get_all(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> typing.List[Content]:
715
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
715
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
716
-        assert content_type is not None# DYN_REMOVE
717
-        assert isinstance(content_type, str) # DYN_REMOVE
716
+        if not content_type:
717
+            content_type = ContentType.Any
718
 
718
 
719
         resultset = self._base_query(workspace)
719
         resultset = self._base_query(workspace)
720
 
720
 

+ 9 - 0
tracim/models/contents.py 查看文件

261
         return contents_types
261
         return contents_types
262
 
262
 
263
     @classmethod
263
     @classmethod
264
+    def allowed_type_values(cls) -> typing.List[str]:
265
+        """
266
+        All content type slug + special values like any
267
+        """
268
+        content_types = cls.allowed_types()
269
+        content_types.append(ContentTypeLegacy.Any)
270
+        return content_types
271
+
272
+    @classmethod
264
     def allowed_types_for_folding(cls):
273
     def allowed_types_for_folding(cls):
265
         # This method is used for showing only "main"
274
         # This method is used for showing only "main"
266
         # types in the left-side treeview
275
         # types in the left-side treeview

+ 2 - 0
tracim/models/context_models.py 查看文件

68
             show_archived: int = 0,
68
             show_archived: int = 0,
69
             show_deleted: int = 0,
69
             show_deleted: int = 0,
70
             show_active: int = 1,
70
             show_active: int = 1,
71
+            content_type: str = None,
71
     ) -> None:
72
     ) -> None:
72
         self.parent_id = parent_id
73
         self.parent_id = parent_id
73
         self.show_archived = bool(show_archived)
74
         self.show_archived = bool(show_archived)
74
         self.show_deleted = bool(show_deleted)
75
         self.show_deleted = bool(show_deleted)
75
         self.show_active = bool(show_active)
76
         self.show_active = bool(show_active)
77
+        self.content_type = content_type
76
 
78
 
77
 
79
 
78
 class ContentCreation(object):
80
 class ContentCreation(object):

+ 34 - 0
tracim/tests/functional/test_workspaces.py 查看文件

241
         assert len(res) == 3
241
         assert len(res) == 3
242
         content = res[0]
242
         content = res[0]
243
         assert content['content_id'] == 1
243
         assert content['content_id'] == 1
244
+        assert content['content_type'] == 'folder'
244
         assert content['is_archived'] is False
245
         assert content['is_archived'] is False
245
         assert content['is_deleted'] is False
246
         assert content['is_deleted'] is False
246
         assert content['label'] == 'Tools'
247
         assert content['label'] == 'Tools'
252
         assert content['workspace_id'] == 1
253
         assert content['workspace_id'] == 1
253
         content = res[1]
254
         content = res[1]
254
         assert content['content_id'] == 2
255
         assert content['content_id'] == 2
256
+        assert content['content_type'] == 'folder'
255
         assert content['is_archived'] is False
257
         assert content['is_archived'] is False
256
         assert content['is_deleted'] is False
258
         assert content['is_deleted'] is False
257
         assert content['label'] == 'Menus'
259
         assert content['label'] == 'Menus'
263
         assert content['workspace_id'] == 1
265
         assert content['workspace_id'] == 1
264
         content = res[2]
266
         content = res[2]
265
         assert content['content_id'] == 11
267
         assert content['content_id'] == 11
268
+        assert content['content_type'] == 'html-documents'
269
+        assert content['is_archived'] is False
270
+        assert content['is_deleted'] is False
271
+        assert content['label'] == 'Current Menu'
272
+        assert content['parent_id'] == 2
273
+        assert content['show_in_ui'] is True
274
+        assert content['slug'] == 'current-menu'
275
+        assert content['status'] == 'open'
276
+        assert set(content['sub_content_types']) == {'thread', 'html-documents', 'folder', 'file'}  # nopep8
277
+        assert content['workspace_id'] == 1
278
+
279
+    def test_api__get_workspace_content__ok_200__get_default_html_documents(self):
280
+        """
281
+        Check obtain workspace contents with defaults filters + content_filter
282
+        """
283
+        self.testapp.authorization = (
284
+            'Basic',
285
+            (
286
+                'admin@admin.admin',
287
+                'admin@admin.admin'
288
+            )
289
+        )
290
+        params = {
291
+            'content_type': 'html-documents',
292
+        }
293
+        res = self.testapp.get('/api/v2/workspaces/1/contents', status=200, params=params).json_body   # nopep8
294
+        assert len(res) == 1
295
+        content = res[0]
296
+        assert content
297
+        assert content['content_id'] == 11
298
+        assert content['content_type'] == 'html-documents'
266
         assert content['is_archived'] is False
299
         assert content['is_archived'] is False
267
         assert content['is_deleted'] is False
300
         assert content['is_deleted'] is False
268
         assert content['label'] == 'Current Menu'
301
         assert content['label'] == 'Current Menu'
549
             'show_archived': 1,
582
             'show_archived': 1,
550
             'show_deleted': 1,
583
             'show_deleted': 1,
551
             'show_active': 1,
584
             'show_active': 1,
585
+            'content_type': 'any'
552
         }
586
         }
553
         self.testapp.authorization = (
587
         self.testapp.authorization = (
554
             'Basic',
588
             'Basic',

+ 5 - 0
tracim/views/core_api/schemas.py 查看文件

142
                     'The reason for this parameter to exist is for example '
142
                     'The reason for this parameter to exist is for example '
143
                     'to allow to show only archived documents'
143
                     'to allow to show only archived documents'
144
     )
144
     )
145
+    content_type = marshmallow.fields.String(
146
+        example=ContentType.Any,
147
+        default=ContentType.Any,
148
+        validate=OneOf(ContentType.allowed_type_values())
149
+    )
145
 
150
 
146
     @post_load
151
     @post_load
147
     def make_content_filter(self, data):
152
     def make_content_filter(self, data):

+ 1 - 0
tracim/views/core_api/workspace_controller.py 查看文件

107
         contents = api.get_all(
107
         contents = api.get_all(
108
             parent_id=content_filter.parent_id,
108
             parent_id=content_filter.parent_id,
109
             workspace=request.current_workspace,
109
             workspace=request.current_workspace,
110
+            content_type=content_filter.content_type,
110
         )
111
         )
111
         contents = [
112
         contents = [
112
             api.get_content_in_context(content) for content in contents
113
             api.get_content_in_context(content) for content in contents