diff --git a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py index 730e8f8a..88d9ebe8 100644 --- a/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py +++ b/ereuse_devicehub/migrations/versions/7ecb8ff7abad_documents.py @@ -42,6 +42,8 @@ def upgrade(): sa.Column('type', sa.Unicode(), nullable=False), sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True), sa.Column('id_document', sa.Unicode(), nullable=True), + sa.Column('software', sa.Unicode(), nullable=True), + sa.Column('success', sa.Boolean(), nullable=False), sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('file_name', sa.Unicode(), nullable=False), sa.Column('file_hash', sa.Unicode(), nullable=False), diff --git a/ereuse_devicehub/resources/action/views/documents.py b/ereuse_devicehub/resources/action/views/documents.py index 18030fad..19d40bb8 100644 --- a/ereuse_devicehub/resources/action/views/documents.py +++ b/ereuse_devicehub/resources/action/views/documents.py @@ -45,7 +45,7 @@ class ErasedView(): db.session.add(db_hash) def insert_action(self, data): - [data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash']] + [data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash', 'software', 'success']] self.data = self.schema.load(data) for dev in self.data['devices']: diff --git a/ereuse_devicehub/resources/documents/models.py b/ereuse_devicehub/resources/documents/models.py index 7ee5eb99..46be23e8 100644 --- a/ereuse_devicehub/resources/documents/models.py +++ b/ereuse_devicehub/resources/documents/models.py @@ -1,6 +1,6 @@ -from citext import CIText +from citext import CIText from flask import g -from sqlalchemy import BigInteger, Column, Sequence, Unicode +from sqlalchemy import BigInteger, Column, Sequence, Unicode, Boolean from sqlalchemy.dialects.postgresql import UUID from teal.db import URL from ereuse_devicehub.db import db @@ -19,6 +19,10 @@ class Document(Thing): date = Column(db.DateTime, nullable=True) date.comment = """The date of document, some documents need to have one date """ + software = Column(CIText(), nullable=False) + software.comment = """Which software is used""" + success = Column(Boolean) + success.comment = """If the erase was success""" id_document = Column(CIText(), nullable=False) id_document.comment = """The id of one document like invoice so they can be linked.""" owner_id = db.Column(UUID(as_uuid=True), diff --git a/ereuse_devicehub/resources/documents/schemas.py b/ereuse_devicehub/resources/documents/schemas.py index 21b7017e..7b15103a 100644 --- a/ereuse_devicehub/resources/documents/schemas.py +++ b/ereuse_devicehub/resources/documents/schemas.py @@ -1,4 +1,4 @@ -from marshmallow.fields import DateTime, Integer, validate +from marshmallow.fields import DateTime, Integer, validate, Boolean from teal.marshmallow import SanitizedStr, URL from ereuse_devicehub.resources.schemas import Thing from ereuse_devicehub.resources.documents import models as m @@ -9,6 +9,9 @@ class Document(Thing): __doc__ = m.Document.__doc__ id = Integer(description=m.Document.id.comment, dump_only=True) type = SanitizedStr(default='Document') + url = URL(description=m.Document.url.comment) + success = Boolean(description=m.Document.success.comment) + software = SanitizedStr(description=m.Document.software.comment) date = DateTime(data_key='endTime', required=False, description=m.Document.date.comment) @@ -23,4 +26,3 @@ class Document(Thing): default='', description=m.Document.file_hash.comment, validate=validate.Length(max=64)) - url = URL(description=m.Document.url.comment) diff --git a/tests/test_action.py b/tests/test_action.py index 5b5dc877..03868c3c 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -2419,7 +2419,7 @@ 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': '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} + 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, 'success': 1, 'software': "Blanco"} user.post(res=models.Action, data=request) action = models.DataWipe.query.one()