Merge pull request #424 from eReuse/bugfix/4219-testing
Bugfix/4219 testing
This commit is contained in:
commit
c961573c91
|
@ -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,
|
||||
|
@ -297,7 +298,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 +333,8 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
|
|||
self.result[filename] = 'Error'
|
||||
continue
|
||||
|
||||
if isinstance(response.device, Computer):
|
||||
response.device.user_trusts = user_trusts
|
||||
db.session.add(response)
|
||||
devices.append(response.device.binding.device)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
@ -898,7 +916,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 +933,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 +946,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
|
||||
|
|
|
@ -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:
|
||||
|
|
Reference in a new issue