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 (
|
from ereuse_devicehub.resources.device.models import (
|
||||||
SAI,
|
SAI,
|
||||||
Cellphone,
|
Cellphone,
|
||||||
|
Computer,
|
||||||
ComputerMonitor,
|
ComputerMonitor,
|
||||||
Desktop,
|
Desktop,
|
||||||
Device,
|
Device,
|
||||||
|
@ -297,7 +298,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
|
||||||
|
|
||||||
return is_lite
|
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()]):
|
if any([x == 'Error' for x in self.result.values()]):
|
||||||
return
|
return
|
||||||
schema = SnapshotSchema()
|
schema = SnapshotSchema()
|
||||||
|
@ -332,6 +333,8 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
|
||||||
self.result[filename] = 'Error'
|
self.result[filename] = 'Error'
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if isinstance(response.device, Computer):
|
||||||
|
response.device.user_trusts = user_trusts
|
||||||
db.session.add(response)
|
db.session.add(response)
|
||||||
devices.append(response.device.binding.device)
|
devices.append(response.device.binding.device)
|
||||||
|
|
||||||
|
|
|
@ -756,6 +756,24 @@ class Device(Thing):
|
||||||
|
|
||||||
return ""
|
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):
|
def get_from_db(self):
|
||||||
if 'property_hid' in app.blueprints.keys():
|
if 'property_hid' in app.blueprints.keys():
|
||||||
try:
|
try:
|
||||||
|
@ -898,7 +916,7 @@ class Device(Thing):
|
||||||
if not snapshot1:
|
if not snapshot1:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.create_new_device(snapshots.values())
|
self.create_new_device(snapshots.values(), user_trusts=self.user_trusts)
|
||||||
self.remove_snapshot(snapshots.keys())
|
self.remove_snapshot(snapshots.keys())
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -915,7 +933,7 @@ class Device(Thing):
|
||||||
snapshot = file_snapshot.read()
|
snapshot = file_snapshot.read()
|
||||||
return json.loads(snapshot)
|
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
|
from ereuse_devicehub.inventory.forms import UploadSnapshotForm
|
||||||
|
|
||||||
new_snapshots = []
|
new_snapshots = []
|
||||||
|
@ -928,7 +946,7 @@ class Device(Thing):
|
||||||
form.result = {}
|
form.result = {}
|
||||||
form.snapshots = new_snapshots
|
form.snapshots = new_snapshots
|
||||||
form.create_new_devices = True
|
form.create_new_devices = True
|
||||||
form.save(commit=False)
|
form.save(commit=False, user_trusts=user_trusts)
|
||||||
|
|
||||||
def remove_snapshot(self, snapshots):
|
def remove_snapshot(self, snapshots):
|
||||||
from ereuse_devicehub.parser.models import SnapshotsLog
|
from ereuse_devicehub.parser.models import SnapshotsLog
|
||||||
|
|
|
@ -171,6 +171,8 @@ class Sync:
|
||||||
|
|
||||||
if not db_device or create_new_device:
|
if not db_device or create_new_device:
|
||||||
device.tags.clear() # We don't want to add the transient dummy tags
|
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.session.add(device)
|
||||||
db_device = device
|
db_device = device
|
||||||
try:
|
try:
|
||||||
|
|
Reference in New Issue