From 39b04f370932185068b6e921a68228ffb676726a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 23 May 2023 13:45:32 +0200 Subject: [PATCH] new datawipe --- ereuse_devicehub/inventory/forms.py | 24 ++++++++-- ereuse_devicehub/inventory/views.py | 4 +- .../5169765e2653_add_new_erase_data_wipe.py | 45 +++++++++++++++++++ ereuse_devicehub/resources/action/models.py | 19 ++++++++ .../templates/inventory/device_list.html | 2 +- 5 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 ereuse_devicehub/migrations/versions/5169765e2653_add_new_erase_data_wipe.py diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 78c9ebfe..3036aaae 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -52,6 +52,7 @@ from ereuse_devicehub.resources.device.models import ( Cellphone, Computer, ComputerMonitor, + DataStorage, Desktop, Device, Keyboard, @@ -851,7 +852,13 @@ class NewActionForm(ActionFormMixin): if not is_valid: return False - if self.type.data in ['Allocate', 'Deallocate', 'Trade', 'DataWipe']: + if self.type.data in [ + 'Allocate', + 'Deallocate', + 'Trade', + 'DataWipe', + 'EraseDataWipe', + ]: return False return True @@ -1073,9 +1080,18 @@ class DataWipeForm(ActionFormMixin): document = copy.copy(self.document) del self.document - self.populate_obj(self.instance) - self.instance.document = document.form._obj - db.session.add(self.instance) + for dev in self._devices: + ac = None + for hd in dev.components: + if not isinstance(hd, DataStorage): + continue + ac = Model() + self.populate_obj(ac) + ac.parent = dev + ac.device = hd + ac.device_id = hd.id + ac.document = document.form._obj + db.session.add(ac) db.session.commit() self.devices.data = devices diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 7e5a7999..166dc14f 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1176,9 +1176,9 @@ class ExportsView(View): row = [ ac.device.serial_number.upper(), ac.device.dhid, - ac.snapshot.uuid, + ac.snapshot.uuid if ac.snapshot else '', ac.type, - ac.get_phid(), + ac.parent.phid() if ac.parent else '', ac.severity, ac.created.strftime('%Y-%m-%d %H:%M:%S'), ] diff --git a/ereuse_devicehub/migrations/versions/5169765e2653_add_new_erase_data_wipe.py b/ereuse_devicehub/migrations/versions/5169765e2653_add_new_erase_data_wipe.py new file mode 100644 index 00000000..1621a547 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/5169765e2653_add_new_erase_data_wipe.py @@ -0,0 +1,45 @@ +"""add new erase_data_wipe + +Revision ID: 5169765e2653 +Revises: 2f2ef041483a +Create Date: 2023-05-23 10:34:46.312074 + +""" +import sqlalchemy as sa +from alembic import context, op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '5169765e2653' +down_revision = '2f2ef041483a' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + + +def upgrade(): + op.create_table( + 'erase_data_wipe', + sa.Column('document_id', sa.BigInteger(), nullable=False), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint( + ['document_id'], + [f'{get_inv()}.document.id'], + ), + sa.ForeignKeyConstraint( + ['id'], + [f'{get_inv()}.erase_basic.id'], + ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_table('erase_data_wipe', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 41a65265..95708a34 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -544,6 +544,24 @@ class ErasePhysical(EraseBasic): return "Physical" +class EraseDataWipe(EraseBasic): + """The device has been selected for insert one proof of erease disk.""" + + id = Column(UUID(as_uuid=True), ForeignKey(EraseBasic.id), primary_key=True) + document_comment = """The user that gets the device due this deal.""" + document_id = db.Column( + BigInteger, db.ForeignKey('data_wipe_document.id'), nullable=False + ) + document = db.relationship( + 'DataWipeDocument', + backref=backref('erase_actions', lazy=True, cascade=CASCADE_OWN), + primaryjoin='EraseDataWipe.document_id == DataWipeDocument.id', + ) + + def get_public_name(self): + return "EraseDataWipe" + + class Step(db.Model): erasure_id = Column( UUID(as_uuid=True), @@ -1539,6 +1557,7 @@ class ToPrepare(ActionWithMultipleDevices): class DataWipe(JoinedTableMixin, ActionWithMultipleDevices): + # class DataWipe(JoinedWithOneDeviceMixin, ActionWithOneDevice): """The device has been selected for insert one proof of erease disk.""" document_comment = """The user that gets the device due this deal.""" diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 82976a38..344e9f66 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -209,7 +209,7 @@
  • - + DataWipe