Browse Source

return updated_content instead of 204 for move endpoint

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

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

291
 
291
 
292
     @property
292
     @property
293
     def parent_id(self) -> int:
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
         return self.content.parent_id
299
         return self.content.parent_id
295
 
300
 
296
     @property
301
     @property

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

807
         res = self.testapp.put_json(
807
         res = self.testapp.put_json(
808
             '/api/v2/workspaces/2/contents/8/move',
808
             '/api/v2/workspaces/2/contents/8/move',
809
             params=params,
809
             params=params,
810
-            status=204
810
+            status=200
811
         )
811
         )
812
         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
812
         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
813
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
813
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
814
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
814
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
815
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
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
     def test_api_put_move_content__ok_200__to_root(self):
821
     def test_api_put_move_content__ok_200__to_root(self):
818
         """
822
         """
857
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
861
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
858
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
862
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
859
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
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
     def test_api_put_move_content__ok_200__with_workspace_id(self):
869
     def test_api_put_move_content__ok_200__with_workspace_id(self):
862
         """
870
         """
902
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
910
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
903
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
911
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
904
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
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
     def test_api_put_move_content__ok_200__to_another_workspace(self):
918
     def test_api_put_move_content__ok_200__to_another_workspace(self):
907
         """
919
         """
946
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
958
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
947
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
959
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
948
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
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
     def test_api_put_move_content__ok_200__to_another_workspace_root(self):
966
     def test_api_put_move_content__ok_200__to_another_workspace_root(self):
951
         """
967
         """
991
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
1007
         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
992
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
1008
         assert not [content for content in new_folder1_contents if content['content_id'] == 8]  # nopep8
993
         assert [content for content in new_folder2_contents if content['content_id'] == 8]  # nopep8
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
     def test_api_put_move_content__err_400__wrong_workspace_id(self):
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
 
85
 
86
 
86
 
87
 class FilterContentQuerySchema(marshmallow.Schema):
87
 class FilterContentQuerySchema(marshmallow.Schema):
88
-    parent_id = workspace_id = marshmallow.fields.Int(
88
+    parent_id = marshmallow.fields.Int(
89
         example=2,
89
         example=2,
90
-        default=None,
90
+        default=0,
91
         description='allow to filter items in a folder.'
91
         description='allow to filter items in a folder.'
92
                     ' If not set, then return all contents.'
92
                     ' If not set, then return all contents.'
93
                     ' If set to 0, then return root contents.'
93
                     ' If set to 0, then return root contents.'

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

166
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
166
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
167
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
167
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
168
     @hapic.input_body(ContentMoveSchema())
168
     @hapic.input_body(ContentMoveSchema())
169
-    @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)  # nopep8
169
+    @hapic.output_body(ContentDigestSchema())  # nopep8
170
     def move_content(
170
     def move_content(
171
             self,
171
             self,
172
             context,
172
             context,
209
                 new_workspace=new_workspace,
209
                 new_workspace=new_workspace,
210
                 must_stay_in_same_workspace=False,
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
     @hapic.with_api_doc()
218
     @hapic.with_api_doc()
215
     @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
219
     @hapic.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)