diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 1f973841..26a4d6e1 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1,7 +1,9 @@ import copy import csv +import datetime import logging import os +import uuid from io import StringIO from pathlib import Path @@ -1043,7 +1045,7 @@ class ExportsView(View): return self.response_csv(data, "Erasures.csv") - def build_erasure_certificate(self): + def get_datastorages(self): erasures = [] for device in self.find_devices(): if device.placeholder and device.placeholder.binding: @@ -1054,11 +1056,66 @@ class ExportsView(View): elif isinstance(device, DataStorage): if device.privacy: erasures.append(device.privacy) + return erasures + + def get_custum_details(self): + my_data = None + customer_details = None + if hasattr(g.user, 'sanitization_entity'): + if g.user.sanitization_entity: + my_data = list(g.user.sanitization_entity)[0] + + if len(request.referrer.split('/lot/')) > 1: + try: + lot_id = request.referrer.split('/lot/')[-1].split('/')[0] + lot = Lot.query.filter_by(owner=g.user).filter_by(id=lot_id).first() + customer_details = lot.transfer.customer_details + except Exception: + pass + return my_data, customer_details + + def get_server_erasure_hosts(self, erasures): + erasures_host = [] + erasures_on_server = [] + for erase in erasures: + try: + if erase.parent.binding.kangaroo: + erasures_host.append(erase.parent) + erasures_on_server.append(erase) + except Exception: + pass + return erasures_host, erasures_on_server + + def build_erasure_certificate(self): + erasures = self.get_datastorages() + software = 'USODY DRIVE ERASURE' + if erasures and erasures[0].snapshot: + software += ' {}'.format( + erasures[0].snapshot.version, + ) + + my_data, customer_details = self.get_custum_details() + + a, b = self.get_server_erasure_hosts(erasures) + erasures_host, erasures_on_server = a, b + + result = 'Success' + if "Failed" in [e.severity.get_public_name() for e in erasures]: + result = 'Failed' params = { 'title': 'Erasure Certificate', 'erasures': tuple(erasures), 'url_pdf': '', + 'date_report': '{:%c}'.format(datetime.datetime.now()), + 'uuid_report': '{}'.format(uuid.uuid4()), + 'software': software, + 'my_data': my_data, + 'n_computers': len(set([x.parent for x in erasures])), + 'result': result, + 'customer_details': customer_details, + 'erasure_hosts': erasures_host, + 'erasures_normal': list(set(erasures) - set(erasures_on_server)), } return flask.render_template('inventory/erasure.html', **params) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 1f373962..f1bbb5dd 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -481,6 +481,9 @@ class EraseBasic(JoinedWithOneDeviceMixin, ActionWithOneDevice): return self.snapshot.device.phid() return '' + def get_public_name(self): + return "Basic" + def __str__(self) -> str: return '{} on {}.'.format(self.severity, self.date_str) @@ -510,12 +513,33 @@ class EraseSectors(EraseBasic): method = 'Badblocks' + def get_public_name(self): + # import pdb; pdb.set_trace() + steps_random = 0 + steps_zeros = 0 + for s in self.steps: + if s.type == 'StepRandom': + steps_random += 1 + if s.type == 'StepZero': + steps_zeros += 1 + if steps_zeros < 1: + return "Basic" + if 0 < steps_random < 3: + return "Baseline" + if steps_random > 2: + return "Enhanced" + + return "Basic" + class ErasePhysical(EraseBasic): """The act of physically destroying a data storage unit.""" method = Column(DBEnum(PhysicalErasureMethod)) + def get_public_name(self): + return "Physical" + class Step(db.Model): erasure_id = Column( diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index bbbcdc10..2d527802 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -334,6 +334,12 @@ class Severity(IntEnum): def __format__(self, format_spec): return str(self) + def get_public_name(self): + if self.value == 3: + return "Failed" + + return "Success" + class PhysicalErasureMethod(Enum): """Methods of physically erasing the data-storage, usually diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index 67bfa1ad..2ccd2ad1 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -68,16 +68,16 @@
- +
- +
@@ -101,7 +101,7 @@ Name: - ACME + {{ ustomer_details and customer_details.company_name or ''}} @@ -109,7 +109,7 @@ Location: - Paseo de Gracia, 2, 08007 Barcelona, España + {{ customer_details and customer_details.location or '' }} @@ -128,7 +128,7 @@ Name: - Your company + {{ my_data and my_data.company_name or '' }} @@ -136,7 +136,7 @@ Responsible Person - John Data + {{ my_data and my_data.responsable_person or '' }} @@ -144,7 +144,7 @@ Location: - Madrid, Gran Via 8, 28040 Madrid, España + {{ my_data and my_data.location or '' }} @@ -158,20 +158,35 @@
+ {% if erasure_hosts %} + {% for e in erasure_hosts %} + + + + + {% endfor %} + {% else %} + {% endif %} @@ -179,7 +194,7 @@ Sanitization result:
+ N° of sanitization server ({{ loop.index }}/{{ erasure_hosts|length }}): + + {% if e.serial_number %} + {{ e.serial_number.upper() }} + {% endif %} +
N° of computers: - 16 + {{ n_computers }}
N° of data storage unit(s): - 16 + {{ erasures | length }}
- Failed + {{ result }}
@@ -198,7 +213,7 @@ Report UUID: - 8bcef704-ba04-4320-8056-c8a5c401dbe3 + {{ uuid_report }} @@ -206,7 +221,7 @@ Report Date: - 2022-12-26 11:26:24 + {{ date_report }} @@ -214,7 +229,7 @@ Software Version: - Usody Drive Erasure 2022.03.0 + {{ software }} @@ -237,15 +252,67 @@ Data Responsable +
+ {{ my_data and my_data.responsable_person or '' }} Data Supervisor +
+ {{ my_data and my_data.supervisor_person or '' }}
+{% if erasures %} + {% if erasure_hosts %} + {% for server in erasure_hosts %} +
+
+

Server Summary

+
+
+

SN Server {{ server.serial_number and server.serial_number.upper() }}

+
+
+
+
+ + + + + + + + + + + {% for erasure in erasures %} + {% if erasure.parent == server %} + + + + + + + {% endif %} + {% endfor %} + +
SN StorageMethodResultDate
+ {{ erasure.device.serial_number.upper() }} + + {{ erasure.get_public_name() }} + + {{ erasure.severity.get_public_name() }} + + {{ erasure.date_str }} +
+
+
+ {% endfor %} + {% endif %} + {% if erasures_normal %}

Devices Summary

@@ -256,23 +323,23 @@ - - - - + + + + - {% for erasure in erasures %} + {% for erasure in erasures_normal %}
SN StorageMethodResultDateSN StorageMethodResultDate
{{ erasure.device.serial_number.upper() }} - {{ erasure.type }} + {{ erasure.get_public_name() }} - {{ erasure.severity }} + {{ erasure.severity.get_public_name() }} {{ erasure.date_str }} @@ -283,10 +350,11 @@
+ {% endif %} {% for erasure in erasures %}
-

{{ erasure.device.__format__('t') }}

+

{{ erasure.device.serial_number.upper() }}

Data storage:
{{ erasure.device.__format__('ts') }}
@@ -308,15 +376,21 @@ {% if erasure.steps %}
Erasure steps:
-
    - {% for step in erasure.steps %} -
  1. {{ step.__format__('') }}
  2. - {% endfor %} -
-
- {% endif %} -
+
    + {% for step in erasure.steps %} +
  1. {{ step.__format__('') }}
  2. + {% endfor %} +
+ + {% endif %} +
{% endfor %} +{% endif %} + \ No newline at end of file