Browse Source

Support for deleted/archived filter

Guénaël Muller 6 years ago
parent
commit
5e822f1140

+ 40 - 0
tracim/fixtures/content.py View File

@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from depot.io.utils import FileIntent
3
+import transaction
3 4
 
4 5
 from tracim import models
5 6
 from tracim.fixtures import Fixture
@@ -9,6 +10,7 @@ from tracim.lib.core.userworkspace import RoleApi
9 10
 from tracim.lib.core.workspace import WorkspaceApi
10 11
 from tracim.models.data import ContentType
11 12
 from tracim.models.data import UserRoleInWorkspace
13
+from tracim.models.revision_protection import new_revision
12 14
 
13 15
 
14 16
 class Content(Fixture):
@@ -160,4 +162,42 @@ class Content(Fixture):
160 162
             label='Current Menu',
161 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 203
         self._session.flush()

+ 6 - 4
tracim/lib/core/content.py View File

@@ -3,7 +3,7 @@ from contextlib import contextmanager
3 3
 
4 4
 import os
5 5
 
6
-from operator import itemgetter
6
+from operator import itemgetter, not_
7 7
 
8 8
 import transaction
9 9
 from sqlalchemy import func
@@ -241,6 +241,11 @@ class ContentApi(object):
241 241
     def _base_query(self, workspace: Workspace=None) -> Query:
242 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 249
         if not self._show_deleted:
245 250
             result = result.filter(Content.is_deleted==False)
246 251
 
@@ -250,9 +255,6 @@ class ContentApi(object):
250 255
         if not self._show_temporary:
251 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 258
         return result
257 259
 
258 260
     def __revisions_real_base_query(

+ 13 - 15
tracim/tests/functional/test_workspaces.py View File

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

+ 0 - 1
tracim/views/core_api/workspace_controller.py View File

@@ -93,7 +93,6 @@ class WorkspaceController(Controller):
93 93
         """
94 94
         return list of contents found in the workspace
95 95
         """
96
-        #hapic_data.query=
97 96
         app_config = request.registry.settings['CFG']
98 97
         content_filter = hapic_data.query
99 98
         api = ContentApi(