Bläddra i källkod

Support for deleted/archived filter

Guénaël Muller 6 år sedan
förälder
incheckning
5e822f1140

+ 40 - 0
tracim/fixtures/content.py Visa fil

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 from depot.io.utils import FileIntent
2
 from depot.io.utils import FileIntent
3
+import transaction
3
 
4
 
4
 from tracim import models
5
 from tracim import models
5
 from tracim.fixtures import Fixture
6
 from tracim.fixtures import Fixture
9
 from tracim.lib.core.workspace import WorkspaceApi
10
 from tracim.lib.core.workspace import WorkspaceApi
10
 from tracim.models.data import ContentType
11
 from tracim.models.data import ContentType
11
 from tracim.models.data import UserRoleInWorkspace
12
 from tracim.models.data import UserRoleInWorkspace
13
+from tracim.models.revision_protection import new_revision
12
 
14
 
13
 
15
 
14
 class Content(Fixture):
16
 class Content(Fixture):
160
             label='Current Menu',
162
             label='Current Menu',
161
             do_save=True,
163
             do_save=True,
162
         )
164
         )
165
+
166
+        new_fruit_salad = content_api.create(
167
+            content_type=ContentType.Page,
168
+            workspace=recipe_workspace,
169
+            parent=fruits_desserts_folder,
170
+            label='New Fruit Salad',
171
+            do_save=True,
172
+        )
173
+        old_fruit_salad = content_api.create(
174
+            content_type=ContentType.Page,
175
+            workspace=recipe_workspace,
176
+            parent=fruits_desserts_folder,
177
+            label='Fruit Salad',
178
+            do_save=True,
179
+        )
180
+        with new_revision(
181
+                session=self._session,
182
+                tm=transaction.manager,
183
+                content=old_fruit_salad,
184
+        ):
185
+            content_api.archive(old_fruit_salad)
186
+        content_api.save(old_fruit_salad)
187
+
188
+        bad_fruit_salad = content_api.create(
189
+            content_type=ContentType.Page,
190
+            workspace=recipe_workspace,
191
+            parent=fruits_desserts_folder,
192
+            label='Bad Fruit Salad',
193
+            do_save=True,
194
+        )
195
+        with new_revision(
196
+                session=self._session,
197
+                tm=transaction.manager,
198
+                content=bad_fruit_salad,
199
+        ):
200
+            content_api.delete(bad_fruit_salad)
201
+        content_api.save(bad_fruit_salad)
202
+
163
         self._session.flush()
203
         self._session.flush()

+ 6 - 4
tracim/lib/core/content.py Visa fil

3
 
3
 
4
 import os
4
 import os
5
 
5
 
6
-from operator import itemgetter
6
+from operator import itemgetter, not_
7
 
7
 
8
 import transaction
8
 import transaction
9
 from sqlalchemy import func
9
 from sqlalchemy import func
241
     def _base_query(self, workspace: Workspace=None) -> Query:
241
     def _base_query(self, workspace: Workspace=None) -> Query:
242
         result = self.__real_base_query(workspace)
242
         result = self.__real_base_query(workspace)
243
 
243
 
244
+        if not self._show_active:
245
+            result = result.filter(or_(
246
+                Content.is_deleted==True,
247
+                Content.is_archived==True,
248
+            ))
244
         if not self._show_deleted:
249
         if not self._show_deleted:
245
             result = result.filter(Content.is_deleted==False)
250
             result = result.filter(Content.is_deleted==False)
246
 
251
 
250
         if not self._show_temporary:
255
         if not self._show_temporary:
251
             result = result.filter(Content.is_temporary==False)
256
             result = result.filter(Content.is_temporary==False)
252
 
257
 
253
-        if not self._show_active:
254
-            result = result.filter(Content.is_active==False)
255
-
256
         return result
258
         return result
257
 
259
 
258
     def __revisions_real_base_query(
260
     def __revisions_real_base_query(

+ 13 - 15
tracim/tests/functional/test_workspaces.py Visa fil

465
         assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
465
         assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
466
         assert content['workspace_id'] == 1
466
         assert content['workspace_id'] == 1
467
 
467
 
468
-    @pytest.mark.xfail()
468
+
469
     def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
469
     def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
470
         """
470
         """
471
          Check obtain workspace folder active contents
471
          Check obtain workspace folder active contents
472
          """
472
          """
473
         params = {
473
         params = {
474
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
474
+            'parent_id': 10,
475
             'show_archived': 0,
475
             'show_archived': 0,
476
             'show_deleted': 0,
476
             'show_deleted': 0,
477
             'show_active': 1,
477
             'show_active': 1,
484
             )
484
             )
485
         )
485
         )
486
         res = self.testapp.get(
486
         res = self.testapp.get(
487
-            '/api/v2/workspaces/1/contents',
487
+            '/api/v2/workspaces/2/contents',
488
             status=200,
488
             status=200,
489
             params=params,
489
             params=params,
490
         ).json_body   # nopep8
490
         ).json_body   # nopep8
491
         # TODO - G.M - 30-05-2018 - Check this test
491
         # TODO - G.M - 30-05-2018 - Check this test
492
         raise NotImplementedError()
492
         raise NotImplementedError()
493
 
493
 
494
-    @pytest.mark.xfail()
495
     def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
494
     def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
496
         """
495
         """
497
          Check obtain workspace folder archived contents
496
          Check obtain workspace folder archived contents
498
          """
497
          """
499
         params = {
498
         params = {
500
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
501
-            'show_archived': 0,
499
+            'parent_id': 10,
500
+            'show_archived': 1,
502
             'show_deleted': 0,
501
             'show_deleted': 0,
503
-            'show_active': 1,
502
+            'show_active': 0,
504
         }
503
         }
505
         self.testapp.authorization = (
504
         self.testapp.authorization = (
506
             'Basic',
505
             'Basic',
510
             )
509
             )
511
         )
510
         )
512
         res = self.testapp.get(
511
         res = self.testapp.get(
513
-            '/api/v2/workspaces/1/contents',
512
+            '/api/v2/workspaces/2/contents',
514
             status=200,
513
             status=200,
515
             params=params,
514
             params=params,
516
         ).json_body   # nopep8
515
         ).json_body   # nopep8
517
         # TODO - G.M - 30-05-2018 - Check this test
516
         # TODO - G.M - 30-05-2018 - Check this test
518
         raise NotImplementedError()
517
         raise NotImplementedError()
519
 
518
 
520
-    @pytest.mark.xfail()
521
     def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
519
     def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
522
         """
520
         """
523
          Check obtain workspace folder deleted contents
521
          Check obtain workspace folder deleted contents
524
          """
522
          """
525
         params = {
523
         params = {
526
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
524
+            'parent_id': 10,
527
             'show_archived': 0,
525
             'show_archived': 0,
528
-            'show_deleted': 0,
529
-            'show_active': 1,
526
+            'show_deleted': 1,
527
+            'show_active': 0,
530
         }
528
         }
531
         self.testapp.authorization = (
529
         self.testapp.authorization = (
532
             'Basic',
530
             'Basic',
536
             )
534
             )
537
         )
535
         )
538
         res = self.testapp.get(
536
         res = self.testapp.get(
539
-            '/api/v2/workspaces/1/contents',
537
+            '/api/v2/workspaces/2/contents',
540
             status=200,
538
             status=200,
541
             params=params,
539
             params=params,
542
         ).json_body   # nopep8
540
         ).json_body   # nopep8
549
         (archived, deleted, active) result should be empty list.
547
         (archived, deleted, active) result should be empty list.
550
         """
548
         """
551
         params = {
549
         params = {
552
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
550
+            'parent_id': 10,
553
             'show_archived': 0,
551
             'show_archived': 0,
554
             'show_deleted': 0,
552
             'show_deleted': 0,
555
             'show_active': 0,
553
             'show_active': 0,
562
             )
560
             )
563
         )
561
         )
564
         res = self.testapp.get(
562
         res = self.testapp.get(
565
-            '/api/v2/workspaces/1/contents',
563
+            '/api/v2/workspaces/2/contents',
566
             status=200,
564
             status=200,
567
             params=params,
565
             params=params,
568
         ).json_body   # nopep8
566
         ).json_body   # nopep8

+ 0 - 1
tracim/views/core_api/workspace_controller.py Visa fil

93
         """
93
         """
94
         return list of contents found in the workspace
94
         return list of contents found in the workspace
95
         """
95
         """
96
-        #hapic_data.query=
97
         app_config = request.registry.settings['CFG']
96
         app_config = request.registry.settings['CFG']
98
         content_filter = hapic_data.query
97
         content_filter = hapic_data.query
99
         api = ContentApi(
98
         api = ContentApi(