reliable and unreliable device. Active and deactive devices and snapshots
This commit is contained in:
parent
14ce3892ac
commit
50856671ed
|
@ -203,7 +203,9 @@ class FilterForm(FlaskForm):
|
||||||
if filter_type:
|
if filter_type:
|
||||||
self.devices = self.devices.filter(Device.type.in_(filter_type))
|
self.devices = self.devices.filter(Device.type.in_(filter_type))
|
||||||
|
|
||||||
return self.devices.order_by(Device.updated.desc())
|
return self.devices.filter(Device.active == True).order_by(
|
||||||
|
Device.updated.desc()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LotForm(FlaskForm):
|
class LotForm(FlaskForm):
|
||||||
|
@ -1704,8 +1706,11 @@ class UserTrustsForm(FlaskForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, snapshot_uuid, *args, **kwargs):
|
def __init__(self, snapshot_uuid, *args, **kwargs):
|
||||||
self.snapshot = Snapshot.query.filter_by(uuid=snapshot_uuid).first()
|
self.snapshot = Snapshot.query.filter_by(uuid=snapshot_uuid).one()
|
||||||
self.device = self.snapshot.device if self.snapshot.device else None
|
self.device = None
|
||||||
|
if self.snapshot.device:
|
||||||
|
self.device = self.snapshot.device
|
||||||
|
|
||||||
self.snapshot_type.kwargs['default'] = self.snapshot.get_new_device()
|
self.snapshot_type.kwargs['default'] = self.snapshot.get_new_device()
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -1725,7 +1730,7 @@ class UserTrustsForm(FlaskForm):
|
||||||
except Exception:
|
except Exception:
|
||||||
self._unic = (
|
self._unic = (
|
||||||
Device.query.filter_by(
|
Device.query.filter_by(
|
||||||
hid=self.device.hid, owner=g.user, placeholder=None
|
hid=self.device.hid, owner=g.user, placeholder=None, active=True
|
||||||
).count()
|
).count()
|
||||||
< 2
|
< 2
|
||||||
)
|
)
|
||||||
|
@ -1736,6 +1741,9 @@ class UserTrustsForm(FlaskForm):
|
||||||
if not self.snapshot or not self.device:
|
if not self.snapshot or not self.device:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not self.snapshot.active:
|
||||||
|
return False
|
||||||
|
|
||||||
if not hasattr(self.device, 'system_uuid'):
|
if not hasattr(self.device, 'system_uuid'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1761,10 +1769,10 @@ class UserTrustsForm(FlaskForm):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.snapshot_type.data == 'update' and not self.unic():
|
if self.snapshot_type.data == 'update' and not self.unic():
|
||||||
self.device.merge()
|
self.device.reliable()
|
||||||
|
|
||||||
if self.snapshot_type.data == 'new_device' and self.unic():
|
if self.snapshot_type.data == 'new_device' and self.unic():
|
||||||
self.device.split()
|
self.device.unreliable()
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -38,10 +38,15 @@ class SnapshotsLog(Thing):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return Severity(self.severity)
|
if self.snapshot:
|
||||||
|
if not self.snapshot.active:
|
||||||
|
return Severity(2)
|
||||||
|
return Severity(self.severity)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
def get_device(self):
|
def get_device(self):
|
||||||
if self.snapshot:
|
if self.snapshot and self.snapshot.active:
|
||||||
if self.snapshot.device.binding:
|
if self.snapshot.device.binding:
|
||||||
return self.snapshot.device.binding.device.devicehub_id
|
return self.snapshot.device.binding.device.devicehub_id
|
||||||
return self.snapshot.device.devicehub_id
|
return self.snapshot.device.devicehub_id
|
||||||
|
@ -67,6 +72,9 @@ class SnapshotsLog(Thing):
|
||||||
if not self.snapshot:
|
if not self.snapshot:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
if not self.snapshot.active:
|
||||||
|
return ''
|
||||||
|
|
||||||
if not self.snapshot.device:
|
if not self.snapshot.device:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,7 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
||||||
sid = Column(CIText(), nullable=True)
|
sid = Column(CIText(), nullable=True)
|
||||||
settings_version = Column(CIText(), nullable=True)
|
settings_version = Column(CIText(), nullable=True)
|
||||||
is_server_erase = Column(Boolean(), nullable=True)
|
is_server_erase = Column(Boolean(), nullable=True)
|
||||||
active = Column(Boolean(), nullable=True)
|
active = Column(Boolean(), default=True, nullable=False)
|
||||||
|
|
||||||
def get_last_lifetimes(self):
|
def get_last_lifetimes(self):
|
||||||
"""We get the lifetime and serial_number of the first disk"""
|
"""We get the lifetime and serial_number of the first disk"""
|
||||||
|
|
|
@ -877,14 +877,77 @@ class Device(Thing):
|
||||||
}
|
}
|
||||||
return types.get(self.type, '')
|
return types.get(self.type, '')
|
||||||
|
|
||||||
def split(self):
|
def unreliable(self):
|
||||||
self.user_trusts = False
|
self.user_trusts = False
|
||||||
|
i = 0
|
||||||
|
snapshot1 = None
|
||||||
|
|
||||||
|
for ac in self.actions:
|
||||||
|
if ac.type == 'Snapshot':
|
||||||
|
if i == 0:
|
||||||
|
snapshot1 = ac
|
||||||
|
if i > 0:
|
||||||
|
ac.active = False
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
if not snapshot1:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.reset_components(snapshot1)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def merge(self):
|
def reliable(self):
|
||||||
self.user_trusts = True
|
# self.user_trusts = True
|
||||||
|
computers = Computer.query.filter_by(
|
||||||
|
hid=self.hid,
|
||||||
|
owner_id=g.user.id,
|
||||||
|
active=True,
|
||||||
|
placeholder=None,
|
||||||
|
).order_by(Device.created.asc())
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
computer1 = None
|
||||||
|
for d in computers:
|
||||||
|
if i == 0:
|
||||||
|
d.user_trusts = True
|
||||||
|
computer1 = d
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
d.user_trusts = True
|
||||||
|
d.active = False
|
||||||
|
d.binding.device.active = False
|
||||||
|
for ac in d.actions:
|
||||||
|
if ac.type == 'Snapshot':
|
||||||
|
ac.active = False
|
||||||
|
|
||||||
|
for c in d.components:
|
||||||
|
c.parent = None
|
||||||
|
|
||||||
|
if not computer1:
|
||||||
|
return
|
||||||
|
|
||||||
|
snapshot1 = None
|
||||||
|
for ac in computer1.actions_one:
|
||||||
|
if ac.type == 'Snapshot':
|
||||||
|
snapshot1 = ac
|
||||||
|
break
|
||||||
|
|
||||||
|
if not snapshot1:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.reset_components(snapshot1)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def reset_components(self, snapshot):
|
||||||
|
for c in snapshot.components:
|
||||||
|
if c.parent is None:
|
||||||
|
c.parent = snapshot.device
|
||||||
|
|
||||||
|
snapshot.device.components = snapshot.components
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.id < other.id
|
return self.id < other.id
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ class Sync:
|
||||||
|
|
||||||
if component.hid:
|
if component.hid:
|
||||||
db_component = Device.query.filter_by(
|
db_component = Device.query.filter_by(
|
||||||
hid=component.hid, owner_id=g.user.id, placeholder=None
|
hid=component.hid, owner_id=g.user.id, placeholder=None, active=True
|
||||||
).first()
|
).first()
|
||||||
is_new = False
|
is_new = False
|
||||||
if not db_component:
|
if not db_component:
|
||||||
|
|
Reference in New Issue