deactivate devices
This commit is contained in:
parent
ec2d286ed3
commit
6dd54d9645
|
@ -833,6 +833,11 @@ class TransferOwnershipBlockchain(Trade):
|
||||||
class Delete(ActionWithMultipleDevices):
|
class Delete(ActionWithMultipleDevices):
|
||||||
__doc__ = m.Delete.__doc__
|
__doc__ = m.Delete.__doc__
|
||||||
|
|
||||||
|
@post_load
|
||||||
|
def deactivate_device(self, data):
|
||||||
|
for dev in data['devices']:
|
||||||
|
dev.active = False
|
||||||
|
|
||||||
|
|
||||||
class Migrate(ActionWithMultipleDevices):
|
class Migrate(ActionWithMultipleDevices):
|
||||||
__doc__ = m.Migrate.__doc__
|
__doc__ = m.Migrate.__doc__
|
||||||
|
|
|
@ -126,6 +126,7 @@ class Device(Thing):
|
||||||
allocated.comment = "device is allocated or not."
|
allocated.comment = "device is allocated or not."
|
||||||
devicehub_id = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
|
devicehub_id = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
|
||||||
devicehub_id.comment = "device have a unique code."
|
devicehub_id.comment = "device have a unique code."
|
||||||
|
active = db.Column(Boolean, default=True)
|
||||||
|
|
||||||
_NON_PHYSICAL_PROPS = {
|
_NON_PHYSICAL_PROPS = {
|
||||||
'id',
|
'id',
|
||||||
|
@ -149,7 +150,8 @@ class Device(Thing):
|
||||||
'sku',
|
'sku',
|
||||||
'image',
|
'image',
|
||||||
'allocated',
|
'allocated',
|
||||||
'devicehub_id'
|
'devicehub_id',
|
||||||
|
'active'
|
||||||
}
|
}
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
@ -70,6 +70,7 @@ class Filters(query.Query):
|
||||||
# due to having multiple paths to the same
|
# due to having multiple paths to the same
|
||||||
lot = query.Join((Device.id == LotDeviceDescendants.device_id),
|
lot = query.Join((Device.id == LotDeviceDescendants.device_id),
|
||||||
LotQ)
|
LotQ)
|
||||||
|
active = True
|
||||||
|
|
||||||
|
|
||||||
class Sorting(query.Sort):
|
class Sorting(query.Sort):
|
||||||
|
@ -104,7 +105,7 @@ class DeviceView(View):
|
||||||
return super().get(id)
|
return super().get(id)
|
||||||
|
|
||||||
def patch(self, id):
|
def patch(self, id):
|
||||||
dev = Device.query.filter_by(id=id, owner_id=g.user.id).one()
|
dev = Device.query.filter_by(id=id, owner_id=g.user.id, active=True).one()
|
||||||
if isinstance(dev, Computer):
|
if isinstance(dev, Computer):
|
||||||
resource_def = app.resources['Computer']
|
resource_def = app.resources['Computer']
|
||||||
# TODO check how to handle the 'actions_one'
|
# TODO check how to handle the 'actions_one'
|
||||||
|
@ -129,12 +130,12 @@ class DeviceView(View):
|
||||||
return self.one_private(id)
|
return self.one_private(id)
|
||||||
|
|
||||||
def one_public(self, id: int):
|
def one_public(self, id: int):
|
||||||
device = Device.query.filter_by(devicehub_id=id).one()
|
device = Device.query.filter_by(devicehub_id=id, active=True).one()
|
||||||
return render_template('devices/layout.html', device=device, states=states)
|
return render_template('devices/layout.html', device=device, states=states)
|
||||||
|
|
||||||
@auth.Auth.requires_auth
|
@auth.Auth.requires_auth
|
||||||
def one_private(self, id: str):
|
def one_private(self, id: str):
|
||||||
device = Device.query.filter_by(devicehub_id=id, owner_id=g.user.id).first()
|
device = Device.query.filter_by(devicehub_id=id, owner_id=g.user.id, active=True).first()
|
||||||
if not device:
|
if not device:
|
||||||
return self.one_public(id)
|
return self.one_public(id)
|
||||||
return self.schema.jsonify(device)
|
return self.schema.jsonify(device)
|
||||||
|
|
|
@ -2512,7 +2512,7 @@ def test_delete_devices(user: UserClient):
|
||||||
|
|
||||||
action, _ = user.post(res=models.Action, data=request)
|
action, _ = user.post(res=models.Action, data=request)
|
||||||
|
|
||||||
user.get(res=Device, item=snap['device']['devicehubID'])
|
user.get(res=Device, item=snap['device']['devicehubID'], status=404)
|
||||||
db_device = Device.query.filter_by(id=snap['device']['id']).one()
|
db_device = Device.query.filter_by(id=snap['device']['id']).one()
|
||||||
|
|
||||||
action_delete = sorted(db_device.actions, key=lambda x: x.created)[-1]
|
action_delete = sorted(db_device.actions, key=lambda x: x.created)[-1]
|
||||||
|
|
Reference in New Issue