From aa4ebeb504a33f33e27c9c9e8d0b959c3cede888 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 5 Oct 2021 14:33:28 +0200 Subject: [PATCH] fixing, vanish deactivate devices --- ereuse_devicehub/resources/device/views.py | 3 +-- tests/test_action.py | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 52805c77..8bab2a3c 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -70,7 +70,6 @@ class Filters(query.Query): # due to having multiple paths to the same lot = query.Join((Device.id == LotDeviceDescendants.device_id), LotQ) - active = True class Sorting(query.Sort): @@ -159,7 +158,7 @@ class DeviceView(View): trades_dev_ids = {d.id for t in trades for d in t.devices} - query = Device.query.filter( + query = Device.query.filter(Device.active == True).filter( (Device.owner_id == g.user.id) | (Device.id.in_(trades_dev_ids)) ).distinct() diff --git a/tests/test_action.py b/tests/test_action.py index ecd4cfed..6da60f8d 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -2512,6 +2512,7 @@ def test_delete_devices(user: UserClient): action, _ = user.post(res=models.Action, data=request) + # Check get one device user.get(res=Device, item=snap['device']['devicehubID'], status=404) db_device = Device.query.filter_by(id=snap['device']['id']).one() @@ -2520,3 +2521,10 @@ def test_delete_devices(user: UserClient): assert action_delete.t == 'Delete' assert str(action_delete.id) == action['id'] assert db_device.active == False + + + # Check use of filter from frontend + url = '/devices/?filter={"type":["Computer"]}' + + devices, res = user.get(url, None) + assert len(devices['items']) == 0