From 34def901cbf64a3ba65649fd8ce7dec8cf3752c0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 15 Jun 2022 12:18:44 +0200 Subject: [PATCH] change uuid in views and forms for system_uuid --- ereuse_devicehub/inventory/forms.py | 2 +- ereuse_devicehub/parser/parser.py | 4 ++-- .../resources/action/views/snapshot.py | 2 +- ereuse_devicehub/resources/device/sync.py | 15 +++++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index df564982..f338e102 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -271,7 +271,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): self.version = snapshot_json.get('version') system_uuid = self.get_uuid(debug) if system_uuid: - snapshot_json['device']['uuid'] = system_uuid + snapshot_json['device']['system_uuid'] = system_uuid try: snapshot_json = schema.load(snapshot_json) diff --git a/ereuse_devicehub/parser/parser.py b/ereuse_devicehub/parser/parser.py index fa511f66..49e7dee6 100644 --- a/ereuse_devicehub/parser/parser.py +++ b/ereuse_devicehub/parser/parser.py @@ -52,7 +52,7 @@ class ParseSnapshot: self.device['type'] = self.get_type() self.device['sku'] = self.get_sku() self.device['version'] = self.get_version() - self.device['uuid'] = self.get_uuid() + self.device['system_uuid'] = self.get_uuid() def set_components(self): self.get_cpu() @@ -379,7 +379,7 @@ class ParseSnapshotLsHw: raise ValidationError(txt) self.device = pc - self.device['uuid'] = self.get_uuid() + self.device['system_uuid'] = self.get_uuid() def set_components(self): memory = None diff --git a/ereuse_devicehub/resources/action/views/snapshot.py b/ereuse_devicehub/resources/action/views/snapshot.py index 59739655..1aaf3985 100644 --- a/ereuse_devicehub/resources/action/views/snapshot.py +++ b/ereuse_devicehub/resources/action/views/snapshot.py @@ -169,7 +169,7 @@ class SnapshotView(SnapshotMixin): self.sid = None system_uuid = self.get_uuid(snapshot_json.pop('debug', None)) if system_uuid: - snapshot_json['device']['uuid'] = system_uuid + snapshot_json['device']['system_uuid'] = system_uuid try: self.snapshot_json = resource_def.schema.load(snapshot_json) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 6d2ca495..4871d6b7 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -177,12 +177,15 @@ class Sync: inspect(tag).transient for tag in device.tags ), 'Tags cannot be synced from DB' db_device = None - if isinstance(db_device, Computer): - if db_device.uuid: - db_device = Computer.query.filter_by( - uuid=device.uuid, owner_id=g.user.id, active=True - ).one() - elif device.hid: + if isinstance(device, Computer): + # first search by uuid + if device.system_uuid: + with suppress(ResourceNotFound): + db_device = Computer.query.filter_by( + system_uuid=device.system_uuid, owner_id=g.user.id, active=True + ).one() + # if no there are any Computer by uuid search by hid + if not db_device and device.hid: with suppress(ResourceNotFound): db_device = Device.query.filter_by( hid=device.hid, owner_id=g.user.id, active=True