Ver código fonte

Merge branch 'develop' of github.com:tracim/tracim_backend into feature/614_file_content_endpoints

Guénaël Muller 6 anos atrás
pai
commit
5c83f04a67

+ 5 - 1
tracim/lib/core/content.py Ver arquivo

1101
         self.save(item, do_notify=False)
1101
         self.save(item, do_notify=False)
1102
 
1102
 
1103
         for child in item.children:
1103
         for child in item.children:
1104
-            with new_revision(child):
1104
+            with new_revision(
1105
+                session=self._session,
1106
+                tm=transaction.manager,
1107
+                content=child
1108
+            ):
1105
                 self.move_recursively(child, item, new_workspace)
1109
                 self.move_recursively(child, item, new_workspace)
1106
         return
1110
         return
1107
 
1111
 

+ 4 - 0
tracim/models/context_models.py Ver arquivo

514
         return self.revision.label
514
         return self.revision.label
515
 
515
 
516
     @property
516
     @property
517
+    def revision_type(self) -> str:
518
+        return self.revision.revision_type
519
+
520
+    @property
517
     def content_type(self) -> str:
521
     def content_type(self) -> str:
518
         content_type = ContentType(self.revision.type)
522
         content_type = ContentType(self.revision.type)
519
         if content_type:
523
         if content_type:

+ 113 - 0
tracim/tests/functional/test_contents.py Ver arquivo

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
 import io
10
 import io
3
 
11
 
4
 import transaction
12
 import transaction
327
         assert revision['status'] == 'open'
335
         assert revision['status'] == 'open'
328
         assert revision['workspace_id'] == 2
336
         assert revision['workspace_id'] == 2
329
         assert revision['revision_id'] == 6
337
         assert revision['revision_id'] == 6
338
+        assert revision['revision_type'] == 'creation'
330
         assert revision['sub_content_types']
339
         assert revision['sub_content_types']
331
         # TODO - G.M - 2018-06-173 - Test with real comments
340
         # TODO - G.M - 2018-06-173 - Test with real comments
332
         assert revision['comment_ids'] == []
341
         assert revision['comment_ids'] == []
348
         assert revision['status'] == 'open'
357
         assert revision['status'] == 'open'
349
         assert revision['workspace_id'] == 2
358
         assert revision['workspace_id'] == 2
350
         assert revision['revision_id'] == 7
359
         assert revision['revision_id'] == 7
360
+        assert revision['revision_type'] == 'edition'
351
         assert revision['sub_content_types']
361
         assert revision['sub_content_types']
352
         # TODO - G.M - 2018-06-173 - Test with real comments
362
         # TODO - G.M - 2018-06-173 - Test with real comments
353
         assert revision['comment_ids'] == []
363
         assert revision['comment_ids'] == []
369
         assert revision['status'] == 'open'
379
         assert revision['status'] == 'open'
370
         assert revision['workspace_id'] == 2
380
         assert revision['workspace_id'] == 2
371
         assert revision['revision_id'] == 27
381
         assert revision['revision_id'] == 27
382
+        assert revision['revision_type'] == 'edition'
372
         assert revision['sub_content_types']
383
         assert revision['sub_content_types']
373
         # TODO - G.M - 2018-06-173 - Test with real comments
384
         # TODO - G.M - 2018-06-173 - Test with real comments
374
         assert revision['comment_ids'] == []
385
         assert revision['comment_ids'] == []
1929
         assert revision['workspace_id'] == 2
1940
         assert revision['workspace_id'] == 2
1930
         assert revision['revision_id'] == 8
1941
         assert revision['revision_id'] == 8
1931
         assert revision['sub_content_types']
1942
         assert revision['sub_content_types']
1943
+        assert revision['revision_type'] == 'creation'
1932
         assert revision['comment_ids'] == [18, 19, 20]
1944
         assert revision['comment_ids'] == [18, 19, 20]
1933
         # TODO - G.M - 2018-06-173 - check date format
1945
         # TODO - G.M - 2018-06-173 - check date format
1934
         assert revision['created']
1946
         assert revision['created']
1948
         assert revision['status'] == 'open'
1960
         assert revision['status'] == 'open'
1949
         assert revision['workspace_id'] == 2
1961
         assert revision['workspace_id'] == 2
1950
         assert revision['revision_id'] == 26
1962
         assert revision['revision_id'] == 26
1963
+        assert revision['revision_type'] == 'edition'
1951
         assert revision['sub_content_types']
1964
         assert revision['sub_content_types']
1952
         assert revision['comment_ids'] == []
1965
         assert revision['comment_ids'] == []
1953
         # TODO - G.M - 2018-06-173 - check date format
1966
         # TODO - G.M - 2018-06-173 - check date format
1957
         assert revision['author']['avatar_url'] is None
1970
         assert revision['author']['avatar_url'] is None
1958
         assert revision['author']['public_name'] == 'Bob i.'
1971
         assert revision['author']['public_name'] == 'Bob i.'
1959
 
1972
 
1973
+    def test_api__get_thread_revisions__ok_200__most_revision_type(self) -> None:
1974
+        """
1975
+        get threads revisions
1976
+        """
1977
+        dbsession = get_tm_session(self.session_factory, transaction.manager)
1978
+        admin = dbsession.query(models.User) \
1979
+            .filter(models.User.email == 'admin@admin.admin') \
1980
+            .one()
1981
+        workspace_api = WorkspaceApi(
1982
+            current_user=admin,
1983
+            session=dbsession,
1984
+            config=self.app_config
1985
+        )
1986
+        business_workspace = workspace_api.get_one(1)
1987
+        content_api = ContentApi(
1988
+            current_user=admin,
1989
+            session=dbsession,
1990
+            config=self.app_config
1991
+        )
1992
+        tool_folder = content_api.get_one(1, content_type=ContentType.Any)
1993
+        test_thread = content_api.create(
1994
+            content_type=ContentType.Thread,
1995
+            workspace=business_workspace,
1996
+            parent=tool_folder,
1997
+            label='Test Thread',
1998
+            do_save=True,
1999
+            do_notify=False,
2000
+        )
2001
+        with new_revision(
2002
+           session=dbsession,
2003
+           tm=transaction.manager,
2004
+           content=test_thread,
2005
+        ):
2006
+            content_api.update_content(
2007
+                test_thread,
2008
+                new_label='test_thread_updated',
2009
+                new_content='Just a test'
2010
+            )
2011
+        content_api.save(test_thread)
2012
+        with new_revision(
2013
+           session=dbsession,
2014
+           tm=transaction.manager,
2015
+           content=test_thread,
2016
+        ):
2017
+            content_api.archive(test_thread)
2018
+        content_api.save(test_thread)
2019
+
2020
+        with new_revision(
2021
+           session=dbsession,
2022
+           tm=transaction.manager,
2023
+           content=test_thread,
2024
+        ):
2025
+            content_api.unarchive(test_thread)
2026
+        content_api.save(test_thread)
2027
+
2028
+        with new_revision(
2029
+           session=dbsession,
2030
+           tm=transaction.manager,
2031
+           content=test_thread,
2032
+        ):
2033
+            content_api.delete(test_thread)
2034
+        content_api.save(test_thread)
2035
+
2036
+        with new_revision(
2037
+           session=dbsession,
2038
+           tm=transaction.manager,
2039
+           content=test_thread,
2040
+        ):
2041
+            content_api.undelete(test_thread)
2042
+        content_api.save(test_thread)
2043
+        dbsession.flush()
2044
+        transaction.commit()
2045
+        self.testapp.authorization = (
2046
+            'Basic',
2047
+            (
2048
+                'admin@admin.admin',
2049
+                'admin@admin.admin'
2050
+            )
2051
+        )
2052
+        res = self.testapp.get(
2053
+            '/api/v2/workspaces/1/threads/{}/revisions'.format(test_thread.content_id),  # nopep8
2054
+            status=200
2055
+        )
2056
+        revisions = res.json_body
2057
+        assert len(revisions) == 6
2058
+        for revision in revisions:
2059
+            revision['content_type'] == 'thread'
2060
+            revision['workspace_id'] == 1
2061
+            revision['content_id'] == test_thread.content_id
2062
+        revision = revisions[0]
2063
+        revision['revision_type'] == 'creation'
2064
+        revision = revisions[1]
2065
+        revision['revision_type'] == 'archiving'
2066
+        revision = revisions[2]
2067
+        revision['revision_type'] == 'unarchiving'
2068
+        revision = revisions[3]
2069
+        revision['revision_type'] == 'deletion'
2070
+        revision = revisions[4]
2071
+        revision['revision_type'] == 'undeletion'
2072
+
1960
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
2073
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
1961
         """
2074
         """
1962
         Set thread status
2075
         Set thread status

+ 5 - 0
tracim/views/core_api/schemas.py Ver arquivo

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):
549
         example=12,
550
         example=12,
550
         validate=Range(min=1, error="Value must be greater than 0"),
551
         validate=Range(min=1, error="Value must be greater than 0"),
551
     )
552
     )
553
+    revision_type = marshmallow.fields.String(
554
+        example=ActionDescription.CREATION,
555
+        validate=OneOf(ActionDescription.allowed_values()),
556
+    )
552
     created = marshmallow.fields.DateTime(
557
     created = marshmallow.fields.DateTime(
553
         format=DATETIME_FORMAT,
558
         format=DATETIME_FORMAT,
554
         description='Content creation date',
559
         description='Content creation date',