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: