DataWipe instead of ToErased

This commit is contained in:
Cayo Puigdefabregas 2021-07-29 12:45:43 +02:00
parent f8ce81cc19
commit bfe56a8626
8 changed files with 19 additions and 21 deletions

View File

@ -57,8 +57,8 @@ def upgrade():
op.create_index('document_type_index', 'document', ['type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}') op.create_index('document_type_index', 'document', ['type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}')
# ToErased table # DataWipe table
op.create_table('to_erased', op.create_table('data_wipe',
sa.Column('document_id', sa.BigInteger(), nullable=True), sa.Column('document_id', sa.BigInteger(), nullable=True),
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ), sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
@ -69,5 +69,5 @@ def upgrade():
def downgrade(): def downgrade():
op.drop_table('to_erased', schema=f'{get_inv()}') op.drop_table('data_wipe', schema=f'{get_inv()}')
op.drop_table('document', schema=f'{get_inv()}') op.drop_table('document', schema=f'{get_inv()}')

View File

@ -199,9 +199,9 @@ class ToPrepareDef(ActionDef):
SCHEMA = schemas.ToPrepare SCHEMA = schemas.ToPrepare
class ToErasedDef(ActionDef): class DataWipeDef(ActionDef):
VIEW = None VIEW = None
SCHEMA = schemas.ToErased SCHEMA = schemas.DataWipe
class AllocateDef(ActionDef): class AllocateDef(ActionDef):

View File

@ -1327,7 +1327,7 @@ class ToPrepare(ActionWithMultipleDevices):
pass pass
class ToErased(JoinedTableMixin, ActionWithMultipleDevices): class DataWipe(JoinedTableMixin, ActionWithMultipleDevices):
"""The device has been selected for insert one proof of erease disk. """The device has been selected for insert one proof of erease disk.
""" """
document_comment = """The user that gets the device due this deal.""" document_comment = """The user that gets the device due this deal."""
@ -1338,7 +1338,7 @@ class ToErased(JoinedTableMixin, ActionWithMultipleDevices):
backref=backref('actions', backref=backref('actions',
lazy=True, lazy=True,
cascade=CASCADE_OWN), cascade=CASCADE_OWN),
primaryjoin='ToErased.document_id == Document.id') primaryjoin='DataWipe.document_id == Document.id')
class Prepare(ActionWithMultipleDevices): class Prepare(ActionWithMultipleDevices):

View File

@ -431,11 +431,9 @@ class Prepare(ActionWithMultipleDevices):
__doc__ = m.Prepare.__doc__ __doc__ = m.Prepare.__doc__
class ToErased(ActionWithMultipleDevices): class DataWipe(ActionWithMultipleDevices):
__doc__ = m.ToErased.__doc__ __doc__ = m.DataWipe.__doc__
document = NestedOn(s_generic_document.Document, only_query='id') document = NestedOn(s_generic_document.Document, only_query='id')
# document = NestedOn('EraseDocument')
# device = NestedOn(s_device.Device, only_query='id')
class Live(ActionWithOneDevice): class Live(ActionWithOneDevice):

View File

@ -9,7 +9,7 @@ from ereuse_devicehub.resources.action.models import (Trade, Confirm, ConfirmRev
Revoke, RevokeDocument, ConfirmDocument, Revoke, RevokeDocument, ConfirmDocument,
ConfirmRevokeDocument) ConfirmRevokeDocument)
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User
from ereuse_devicehub.resources.action.models import ToErased from ereuse_devicehub.resources.action.models import DataWipe
from ereuse_devicehub.resources.documents.models import Document from ereuse_devicehub.resources.documents.models import Document
from ereuse_devicehub.resources.device.models import DataStorage from ereuse_devicehub.resources.device.models import DataStorage
from ereuse_devicehub.resources.documents.schemas import Document as sh_document from ereuse_devicehub.resources.documents.schemas import Document as sh_document
@ -37,7 +37,7 @@ class ErasedView():
schema = sh_document() schema = sh_document()
[data.pop(x, None) for x in ['severity', 'devices', 'name', 'description']] [data.pop(x, None) for x in ['severity', 'devices', 'name', 'description']]
doc_data = schema.load(data) doc_data = schema.load(data)
doc_data['type'] = 'ToErased' doc_data['type'] = 'DataWipe'
self.document = Document(**doc_data) self.document = Document(**doc_data)
db.session.add(self.document) db.session.add(self.document)
@ -57,5 +57,5 @@ class ErasedView():
self.data['devices'].add(component) self.data['devices'].add(component)
self.data['document'] = self.document self.data['document'] = self.document
self.erased = ToErased(**self.data) self.erased = DataWipe(**self.data)
db.session.add(self.erased) db.session.add(self.erased)

View File

@ -251,7 +251,7 @@ class ActionView(View):
confirm_revoke = trade_view.ConfirmRevokeDocumentView(json, resource_def, self.schema) confirm_revoke = trade_view.ConfirmRevokeDocumentView(json, resource_def, self.schema)
return confirm_revoke.post() return confirm_revoke.post()
if json['type'] == 'ToErased': if json['type'] == 'DataWipe':
erased = ErasedView(json, resource_def.schema) erased = ErasedView(json, resource_def.schema)
return erased.post() return erased.post()

View File

@ -700,10 +700,10 @@ class Computer(Device):
def external_document_erasure(self): def external_document_erasure(self):
"""Returns the external ``DataStorage`` proof of erasure. """Returns the external ``DataStorage`` proof of erasure.
""" """
from ereuse_devicehub.resources.action.models import ToErased from ereuse_devicehub.resources.action.models import DataWipe
urls = set() urls = set()
try: try:
ev = self.last_action_of(ToErased) ev = self.last_action_of(DataWipe)
urls.add(ev.document.url.to_text()) urls.add(ev.document.url.to_text())
except LookupError: except LookupError:
pass pass
@ -902,9 +902,9 @@ class DataStorage(JoinedComponentTableMixin, Component):
def external_document_erasure(self): def external_document_erasure(self):
"""Returns the external ``DataStorage`` proof of erasure. """Returns the external ``DataStorage`` proof of erasure.
""" """
from ereuse_devicehub.resources.action.models import ToErased from ereuse_devicehub.resources.action.models import DataWipe
try: try:
ev = self.last_action_of(ToErased) ev = self.last_action_of(DataWipe)
return ev.document.url.to_text() return ev.document.url.to_text()
except LookupError: except LookupError:
return None return None

View File

@ -2419,10 +2419,10 @@ def test_action_web_erase(user: UserClient, client: Client):
bfile = BytesIO(b'abc') bfile = BytesIO(b'abc')
hash3 = hashlib.sha3_256(bfile.read()).hexdigest() hash3 = hashlib.sha3_256(bfile.read()).hexdigest()
snap, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) snap, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot)
request = {'type': 'ToErased', 'devices': [snap['device']['id']], 'name': 'borrado universal', 'severity': 'Info', 'description': 'nada que describir', 'url': 'http://www.google.com/', 'documentId': '33', 'endTime': '2021-07-07T22:00:00.000Z', 'filename': 'Certificado de borrado1.pdf', 'hash': hash3} request = {'type': 'DataWipe', 'devices': [snap['device']['id']], 'name': 'borrado universal', 'severity': 'Info', 'description': 'nada que describir', 'url': 'http://www.google.com/', 'documentId': '33', 'endTime': '2021-07-07T22:00:00.000Z', 'filename': 'Certificado de borrado1.pdf', 'hash': hash3}
user.post(res=models.Action, data=request) user.post(res=models.Action, data=request)
action = models.ToErased.query.one() action = models.DataWipe.query.one()
for dev in action.devices: for dev in action.devices:
assert action in dev.actions assert action in dev.actions