From de9b525737c76eb0802d7fca63ecc0f203c6f382 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 26 Jan 2023 10:46:34 +0100 Subject: [PATCH 1/2] . --- ereuse_devicehub/inventory/forms.py | 4 +++- ereuse_devicehub/resources/device/models.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 1e641f32..1910c3e8 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -297,7 +297,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): return is_lite - def save(self, commit=True): + def save(self, commit=True, user_trusts=True): if any([x == 'Error' for x in self.result.values()]): return schema = SnapshotSchema() @@ -332,6 +332,8 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): self.result[filename] = 'Error' continue + import pdb; pdb.set_trace() + response.device.user_trusts = user_trusts db.session.add(response) devices.append(response.device.binding.device) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 378613df..da129b55 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -898,7 +898,7 @@ class Device(Thing): if not snapshot1: return - self.create_new_device(snapshots.values()) + self.create_new_device(snapshots.values(), user_trusts=self.user_trusts) self.remove_snapshot(snapshots.keys()) return @@ -915,7 +915,7 @@ class Device(Thing): snapshot = file_snapshot.read() return json.loads(snapshot) - def create_new_device(self, snapshots): + def create_new_device(self, snapshots, user_trusts=True): from ereuse_devicehub.inventory.forms import UploadSnapshotForm new_snapshots = [] @@ -928,7 +928,7 @@ class Device(Thing): form.result = {} form.snapshots = new_snapshots form.create_new_devices = True - form.save(commit=False) + form.save(commit=False, user_trusts=user_trusts) def remove_snapshot(self, snapshots): from ereuse_devicehub.parser.models import SnapshotsLog From 6c9334fa761ddab7083183ce360150c8d636b68e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 26 Jan 2023 11:35:08 +0100 Subject: [PATCH 2/2] fix test 2 --- ereuse_devicehub/inventory/forms.py | 5 +++-- ereuse_devicehub/resources/device/models.py | 18 ++++++++++++++++++ ereuse_devicehub/resources/device/sync.py | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 1910c3e8..451684e1 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -44,6 +44,7 @@ from ereuse_devicehub.resources.action.views.snapshot import ( from ereuse_devicehub.resources.device.models import ( SAI, Cellphone, + Computer, ComputerMonitor, Desktop, Device, @@ -332,8 +333,8 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): self.result[filename] = 'Error' continue - import pdb; pdb.set_trace() - response.device.user_trusts = user_trusts + if isinstance(response.device, Computer): + response.device.user_trusts = user_trusts db.session.add(response) devices.append(response.device.binding.device) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index da129b55..8d2baec1 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -756,6 +756,24 @@ class Device(Thing): return "" + def get_exist_untrusted_device(self): + if isinstance(self, Computer): + if not self.system_uuid: + return True + + return ( + Computer.query.filter_by( + hid=self.hid, + user_trusts=False, + owner_id=g.user.id, + active=True, + placeholder=None, + ).first() + or False + ) + + return False + def get_from_db(self): if 'property_hid' in app.blueprints.keys(): try: diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 8dfba8b2..510e425a 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -171,6 +171,8 @@ class Sync: if not db_device or create_new_device: device.tags.clear() # We don't want to add the transient dummy tags + if create_new_device or device.get_exist_untrusted_device(): + device.user_trusts = False db.session.add(device) db_device = device try: