new datawipe

This commit is contained in:
Cayo Puigdefabregas 2023-05-23 13:45:32 +02:00
parent ebdb6949c9
commit 39b04f3709
5 changed files with 87 additions and 7 deletions

View File

@ -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

View File

@ -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'),
]

View File

@ -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()}')

View File

@ -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."""

View File

@ -209,7 +209,7 @@
</a>
</li>
<li>
<a href="javascript:newDataWipe('DataWipe')" class="dropdown-item">
<a href="javascript:newDataWipe('EraseDataWipe')" class="dropdown-item">
<i class="bi bi-eraser-fill"></i>
DataWipe
</a>