Browse Source

return updated_content instead of 204 for move endpoint

Guénaël Muller 6 years ago
parent
commit
3381cb62c7

+ 5 - 0
tracim/models/context_models.py View File

@@ -291,6 +291,11 @@ class ContentInContext(object):
291 291
 
292 292
     @property
293 293
     def parent_id(self) -> int:
294
+        """
295
+        Return parent_id of the content, if it doesn't exist return 0
296
+        """
297
+        if not self.content.parent_id:
298
+            return 0
294 299
         return self.content.parent_id
295 300
 
296 301
     @property

+ 21 - 1
tracim/tests/functional/test_workspaces.py View File

@@ -807,12 +807,16 @@ class TestWorkspaceContents(FunctionalTest):
807 807
         res = self.testapp.put_json(
808 808
             '/api/v2/workspaces/2/contents/8/move',
809 809
             params=params,
810
-            status=204
810
+            status=200
811 811
         )
812 812
         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
813 813
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
814 814
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
815 815
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
816
+        assert res.json_body
817
+        assert res.json_body['parent_id'] == 4
818
+        assert res.json_body['content_id'] == 8
819
+        assert res.json_body['workspace_id'] == 2
816 820
 
817 821
     def test_api_put_move_content__ok_200__to_root(self):
818 822
         """
@@ -857,6 +861,10 @@ class TestWorkspaceContents(FunctionalTest):
857 861
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
858 862
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
859 863
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
864
+        assert res.json_body
865
+        assert res.json_body['parent_id'] == 0
866
+        assert res.json_body['content_id'] == 8
867
+        assert res.json_body['workspace_id'] == 2
860 868
 
861 869
     def test_api_put_move_content__ok_200__with_workspace_id(self):
862 870
         """
@@ -902,6 +910,10 @@ class TestWorkspaceContents(FunctionalTest):
902 910
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
903 911
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
904 912
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
913
+        assert res.json_body
914
+        assert res.json_body['parent_id'] == 4
915
+        assert res.json_body['content_id'] == 8
916
+        assert res.json_body['workspace_id'] == 2
905 917
 
906 918
     def test_api_put_move_content__ok_200__to_another_workspace(self):
907 919
         """
@@ -946,6 +958,10 @@ class TestWorkspaceContents(FunctionalTest):
946 958
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
947 959
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
948 960
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
961
+        assert res.json_body
962
+        assert res.json_body['parent_id'] == 2
963
+        assert res.json_body['content_id'] == 8
964
+        assert res.json_body['workspace_id'] == 1
949 965
 
950 966
     def test_api_put_move_content__ok_200__to_another_workspace_root(self):
951 967
         """
@@ -991,6 +1007,10 @@ class TestWorkspaceContents(FunctionalTest):
991 1007
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
992 1008
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
993 1009
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
1010
+        assert res.json_body
1011
+        assert res.json_body['parent_id'] == 0
1012
+        assert res.json_body['content_id'] == 8
1013
+        assert res.json_body['workspace_id'] == 1
994 1014
 
995 1015
     def test_api_put_move_content__err_400__wrong_workspace_id(self):
996 1016
         """

+ 2 - 2
tracim/views/core_api/schemas.py View File

@@ -85,9 +85,9 @@ class WorkspaceAndContentIdPathSchema(WorkspaceIdPathSchema, ContentIdPathSchema
85 85
 
86 86
 
87 87
 class FilterContentQuerySchema(marshmallow.Schema):
88
-    parent_id = workspace_id = marshmallow.fields.Int(
88
+    parent_id = marshmallow.fields.Int(
89 89
         example=2,
90
-        default=None,
90
+        default=0,
91 91
         description='allow to filter items in a folder.'
92 92
                     ' If not set, then return all contents.'
93 93
                     ' If set to 0, then return root contents.'

+ 6 - 2
tracim/views/core_api/workspace_controller.py View File

@@ -166,7 +166,7 @@ class WorkspaceController(Controller):
166 166
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
167 167
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
168 168
     @hapic.input_body(ContentMoveSchema())
169
-    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
169
+    @hapic.output_body(ContentDigestSchema())  # nopep8
170 170
     def move_content(
171 171
             self,
172 172
             context,
@@ -209,7 +209,11 @@ class WorkspaceController(Controller):
209 209
                 new_workspace=new_workspace,
210 210
                 must_stay_in_same_workspace=False,
211 211
             )
212
-        return
212
+        updated_content = api.get_one(
213
+            path_data.content_id,
214
+            content_type=ContentType.Any
215
+        )
216
+        return api.get_content_in_context(updated_content)
213 217
 
214 218
     @hapic.with_api_doc()
215 219
     @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)