From bfe56a8626907e6f22e0e115782e369b527d6dc7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 29 Jul 2021 12:45:43 +0200 Subject: [PATCH] DataWipe instead of ToErased --- .../migrations/versions/7ecb8ff7abad_documents.py | 6 +++--- ereuse_devicehub/resources/action/__init__.py | 4 ++-- ereuse_devicehub/resources/action/models.py | 4 ++-- ereuse_devicehub/resources/action/schemas.py | 6 ++---- ereuse_devicehub/resources/action/views/documents.py | 6 +++--- ereuse_devicehub/resources/action/views/views.py | 2 +- ereuse_devicehub/resources/device/models.py | 8 ++++---- tests/test_action.py | 4 ++-- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py index deaed24e..730e8f8a 100644 --- a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py +++ b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py @@ -57,8 +57,8 @@ def upgrade(): op.create_index('document_type_index', 'document', ['type'], unique=False, postgresql_using='hash', schema=f'{get_inv()}') - # ToErased table - op.create_table('to_erased', + # DataWipe table + op.create_table('data_wipe', sa.Column('document_id', sa.BigInteger(), nullable=True), sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ), @@ -69,5 +69,5 @@ def upgrade(): 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()}') diff --git a/ereuse_devicehub/resources/action/__init__.py b/ereuse_devicehub/resources/action/__init__.py index 2ee1e0da..bdc55014 100644 --- a/ereuse_devicehub/resources/action/__init__.py +++ b/ereuse_devicehub/resources/action/__init__.py @@ -199,9 +199,9 @@ class ToPrepareDef(ActionDef): SCHEMA = schemas.ToPrepare -class ToErasedDef(ActionDef): +class DataWipeDef(ActionDef): VIEW = None - SCHEMA = schemas.ToErased + SCHEMA = schemas.DataWipe class AllocateDef(ActionDef): diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 30a91890..e29c37a2 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1327,7 +1327,7 @@ class ToPrepare(ActionWithMultipleDevices): pass -class ToErased(JoinedTableMixin, ActionWithMultipleDevices): +class DataWipe(JoinedTableMixin, ActionWithMultipleDevices): """The device has been selected for insert one proof of erease disk. """ document_comment = """The user that gets the device due this deal.""" @@ -1338,7 +1338,7 @@ class ToErased(JoinedTableMixin, ActionWithMultipleDevices): backref=backref('actions', lazy=True, cascade=CASCADE_OWN), - primaryjoin='ToErased.document_id == Document.id') + primaryjoin='DataWipe.document_id == Document.id') class Prepare(ActionWithMultipleDevices): diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 1a498a36..f0a2e895 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -431,11 +431,9 @@ class Prepare(ActionWithMultipleDevices): __doc__ = m.Prepare.__doc__ -class ToErased(ActionWithMultipleDevices): - __doc__ = m.ToErased.__doc__ +class DataWipe(ActionWithMultipleDevices): + __doc__ = m.DataWipe.__doc__ document = NestedOn(s_generic_document.Document, only_query='id') - # document = NestedOn('EraseDocument') - # device = NestedOn(s_device.Device, only_query='id') class Live(ActionWithOneDevice): diff --git a/ereuse_devicehub/resources/action/views/documents.py b/ereuse_devicehub/resources/action/views/documents.py index c21f9d42..18030fad 100644 --- a/ereuse_devicehub/resources/action/views/documents.py +++ b/ereuse_devicehub/resources/action/views/documents.py @@ -9,7 +9,7 @@ from ereuse_devicehub.resources.action.models import (Trade, Confirm, ConfirmRev Revoke, RevokeDocument, ConfirmDocument, ConfirmRevokeDocument) 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.device.models import DataStorage from ereuse_devicehub.resources.documents.schemas import Document as sh_document @@ -37,7 +37,7 @@ class ErasedView(): schema = sh_document() [data.pop(x, None) for x in ['severity', 'devices', 'name', 'description']] doc_data = schema.load(data) - doc_data['type'] = 'ToErased' + doc_data['type'] = 'DataWipe' self.document = Document(**doc_data) db.session.add(self.document) @@ -57,5 +57,5 @@ class ErasedView(): self.data['devices'].add(component) self.data['document'] = self.document - self.erased = ToErased(**self.data) + self.erased = DataWipe(**self.data) db.session.add(self.erased) diff --git a/ereuse_devicehub/resources/action/views/views.py b/ereuse_devicehub/resources/action/views/views.py index c42089a2..415effb8 100644 --- a/ereuse_devicehub/resources/action/views/views.py +++ b/ereuse_devicehub/resources/action/views/views.py @@ -251,7 +251,7 @@ class ActionView(View): confirm_revoke = trade_view.ConfirmRevokeDocumentView(json, resource_def, self.schema) return confirm_revoke.post() - if json['type'] == 'ToErased': + if json['type'] == 'DataWipe': erased = ErasedView(json, resource_def.schema) return erased.post() diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 35937101..a0917bef 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -700,10 +700,10 @@ class Computer(Device): def external_document_erasure(self): """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() try: - ev = self.last_action_of(ToErased) + ev = self.last_action_of(DataWipe) urls.add(ev.document.url.to_text()) except LookupError: pass @@ -902,9 +902,9 @@ class DataStorage(JoinedComponentTableMixin, Component): def external_document_erasure(self): """Returns the external ``DataStorage`` proof of erasure. """ - from ereuse_devicehub.resources.action.models import ToErased + from ereuse_devicehub.resources.action.models import DataWipe try: - ev = self.last_action_of(ToErased) + ev = self.last_action_of(DataWipe) return ev.document.url.to_text() except LookupError: return None diff --git a/tests/test_action.py b/tests/test_action.py index bfdcebd2..5b5dc877 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -2419,10 +2419,10 @@ def test_action_web_erase(user: UserClient, client: Client): bfile = BytesIO(b'abc') hash3 = hashlib.sha3_256(bfile.read()).hexdigest() 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) - action = models.ToErased.query.one() + action = models.DataWipe.query.one() for dev in action.devices: assert action in dev.actions