Browse Source

Merge branch 'develop' of github.com:tracim/tracim_backend into feature/611_workspace_and_workspace_member_action_endpoints

Guénaël Muller 6 years ago
parent
commit
09d74fa3f3

+ 5 - 1
tracim/lib/core/content.py View File

985
         self.save(item, do_notify=False)
985
         self.save(item, do_notify=False)
986
 
986
 
987
         for child in item.children:
987
         for child in item.children:
988
-            with new_revision(child):
988
+            with new_revision(
989
+                session=self._session,
990
+                tm=transaction.manager,
991
+                content=child
992
+            ):
989
                 self.move_recursively(child, item, new_workspace)
993
                 self.move_recursively(child, item, new_workspace)
990
         return
994
         return
991
 
995
 

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

526
         return self.revision.label
526
         return self.revision.label
527
 
527
 
528
     @property
528
     @property
529
+    def revision_type(self) -> str:
530
+        return self.revision.revision_type
531
+
532
+    @property
529
     def content_type(self) -> str:
533
     def content_type(self) -> str:
530
         content_type = ContentType(self.revision.type)
534
         content_type = ContentType(self.revision.type)
531
         if content_type:
535
         if content_type:

+ 113 - 0
tracim/tests/functional/test_contents.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+import transaction
3
+
4
+from tracim import models
5
+from tracim.lib.core.content import ContentApi
6
+from tracim.lib.core.workspace import WorkspaceApi
7
+from tracim.models import get_tm_session
8
+from tracim.models.contents import ContentTypeLegacy as ContentType
9
+from tracim.models.revision_protection import new_revision
2
 from tracim.tests import FunctionalTest
10
 from tracim.tests import FunctionalTest
3
 from tracim.tests import set_html_document_slug_to_legacy
11
 from tracim.tests import set_html_document_slug_to_legacy
4
 from tracim.fixtures.content import Content as ContentFixtures
12
 from tracim.fixtures.content import Content as ContentFixtures
314
         assert revision['status'] == 'open'
322
         assert revision['status'] == 'open'
315
         assert revision['workspace_id'] == 2
323
         assert revision['workspace_id'] == 2
316
         assert revision['revision_id'] == 6
324
         assert revision['revision_id'] == 6
325
+        assert revision['revision_type'] == 'creation'
317
         assert revision['sub_content_types']
326
         assert revision['sub_content_types']
318
         # TODO - G.M - 2018-06-173 - Test with real comments
327
         # TODO - G.M - 2018-06-173 - Test with real comments
319
         assert revision['comment_ids'] == []
328
         assert revision['comment_ids'] == []
335
         assert revision['status'] == 'open'
344
         assert revision['status'] == 'open'
336
         assert revision['workspace_id'] == 2
345
         assert revision['workspace_id'] == 2
337
         assert revision['revision_id'] == 7
346
         assert revision['revision_id'] == 7
347
+        assert revision['revision_type'] == 'edition'
338
         assert revision['sub_content_types']
348
         assert revision['sub_content_types']
339
         # TODO - G.M - 2018-06-173 - Test with real comments
349
         # TODO - G.M - 2018-06-173 - Test with real comments
340
         assert revision['comment_ids'] == []
350
         assert revision['comment_ids'] == []
356
         assert revision['status'] == 'open'
366
         assert revision['status'] == 'open'
357
         assert revision['workspace_id'] == 2
367
         assert revision['workspace_id'] == 2
358
         assert revision['revision_id'] == 27
368
         assert revision['revision_id'] == 27
369
+        assert revision['revision_type'] == 'edition'
359
         assert revision['sub_content_types']
370
         assert revision['sub_content_types']
360
         # TODO - G.M - 2018-06-173 - Test with real comments
371
         # TODO - G.M - 2018-06-173 - Test with real comments
361
         assert revision['comment_ids'] == []
372
         assert revision['comment_ids'] == []
697
         assert revision['workspace_id'] == 2
708
         assert revision['workspace_id'] == 2
698
         assert revision['revision_id'] == 8
709
         assert revision['revision_id'] == 8
699
         assert revision['sub_content_types']
710
         assert revision['sub_content_types']
711
+        assert revision['revision_type'] == 'creation'
700
         assert revision['comment_ids'] == [18, 19, 20]
712
         assert revision['comment_ids'] == [18, 19, 20]
701
         # TODO - G.M - 2018-06-173 - check date format
713
         # TODO - G.M - 2018-06-173 - check date format
702
         assert revision['created']
714
         assert revision['created']
716
         assert revision['status'] == 'open'
728
         assert revision['status'] == 'open'
717
         assert revision['workspace_id'] == 2
729
         assert revision['workspace_id'] == 2
718
         assert revision['revision_id'] == 26
730
         assert revision['revision_id'] == 26
731
+        assert revision['revision_type'] == 'edition'
719
         assert revision['sub_content_types']
732
         assert revision['sub_content_types']
720
         assert revision['comment_ids'] == []
733
         assert revision['comment_ids'] == []
721
         # TODO - G.M - 2018-06-173 - check date format
734
         # TODO - G.M - 2018-06-173 - check date format
725
         assert revision['author']['avatar_url'] is None
738
         assert revision['author']['avatar_url'] is None
726
         assert revision['author']['public_name'] == 'Bob i.'
739
         assert revision['author']['public_name'] == 'Bob i.'
727
 
740
 
741
+    def test_api__get_thread_revisions__ok_200__most_revision_type(self) -> None:
742
+        """
743
+        get threads revisions
744
+        """
745
+        dbsession = get_tm_session(self.session_factory, transaction.manager)
746
+        admin = dbsession.query(models.User) \
747
+            .filter(models.User.email == 'admin@admin.admin') \
748
+            .one()
749
+        workspace_api = WorkspaceApi(
750
+            current_user=admin,
751
+            session=dbsession,
752
+            config=self.app_config
753
+        )
754
+        business_workspace = workspace_api.get_one(1)
755
+        content_api = ContentApi(
756
+            current_user=admin,
757
+            session=dbsession,
758
+            config=self.app_config
759
+        )
760
+        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
761
+        test_thread = content_api.create(
762
+            content_type=ContentType.Thread,
763
+            workspace=business_workspace,
764
+            parent=tool_folder,
765
+            label='Test Thread',
766
+            do_save=True,
767
+            do_notify=False,
768
+        )
769
+        with new_revision(
770
+           session=dbsession,
771
+           tm=transaction.manager,
772
+           content=test_thread,
773
+        ):
774
+            content_api.update_content(
775
+                test_thread,
776
+                new_label='test_thread_updated',
777
+                new_content='Just a test'
778
+            )
779
+        content_api.save(test_thread)
780
+        with new_revision(
781
+           session=dbsession,
782
+           tm=transaction.manager,
783
+           content=test_thread,
784
+        ):
785
+            content_api.archive(test_thread)
786
+        content_api.save(test_thread)
787
+
788
+        with new_revision(
789
+           session=dbsession,
790
+           tm=transaction.manager,
791
+           content=test_thread,
792
+        ):
793
+            content_api.unarchive(test_thread)
794
+        content_api.save(test_thread)
795
+
796
+        with new_revision(
797
+           session=dbsession,
798
+           tm=transaction.manager,
799
+           content=test_thread,
800
+        ):
801
+            content_api.delete(test_thread)
802
+        content_api.save(test_thread)
803
+
804
+        with new_revision(
805
+           session=dbsession,
806
+           tm=transaction.manager,
807
+           content=test_thread,
808
+        ):
809
+            content_api.undelete(test_thread)
810
+        content_api.save(test_thread)
811
+        dbsession.flush()
812
+        transaction.commit()
813
+        self.testapp.authorization = (
814
+            'Basic',
815
+            (
816
+                'admin@admin.admin',
817
+                'admin@admin.admin'
818
+            )
819
+        )
820
+        res = self.testapp.get(
821
+            '/api/v2/workspaces/1/threads/{}/revisions'.format(test_thread.content_id),  # nopep8
822
+            status=200
823
+        )
824
+        revisions = res.json_body
825
+        assert len(revisions) == 6
826
+        for revision in revisions:
827
+            revision['content_type'] == 'thread'
828
+            revision['workspace_id'] == 1
829
+            revision['content_id'] == test_thread.content_id
830
+        revision = revisions[0]
831
+        revision['revision_type'] == 'creation'
832
+        revision = revisions[1]
833
+        revision['revision_type'] == 'archiving'
834
+        revision = revisions[2]
835
+        revision['revision_type'] == 'unarchiving'
836
+        revision = revisions[3]
837
+        revision['revision_type'] == 'deletion'
838
+        revision = revisions[4]
839
+        revision['revision_type'] == 'undeletion'
840
+
728
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
841
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
729
         """
842
         """
730
         Set thread status
843
         Set thread status

+ 5 - 0
tracim/views/core_api/schemas.py View File

24
 from tracim.models.context_models import ContentFilter
24
 from tracim.models.context_models import ContentFilter
25
 from tracim.models.context_models import LoginCredentials
25
 from tracim.models.context_models import LoginCredentials
26
 from tracim.models.data import UserRoleInWorkspace
26
 from tracim.models.data import UserRoleInWorkspace
27
+from tracim.models.data import ActionDescription
27
 
28
 
28
 
29
 
29
 class UserDigestSchema(marshmallow.Schema):
30
 class UserDigestSchema(marshmallow.Schema):
550
         example=12,
551
         example=12,
551
         validate=Range(min=1, error="Value must be greater than 0"),
552
         validate=Range(min=1, error="Value must be greater than 0"),
552
     )
553
     )
554
+    revision_type = marshmallow.fields.String(
555
+        example=ActionDescription.CREATION,
556
+        validate=OneOf(ActionDescription.allowed_values()),
557
+    )
553
     created = marshmallow.fields.DateTime(
558
     created = marshmallow.fields.DateTime(
554
         format=DATETIME_FORMAT,
559
         format=DATETIME_FORMAT,
555
         description='Content creation date',
560
         description='Content creation date',