external document erase
This commit is contained in:
parent
c5e62914b6
commit
833b55aefc
|
@ -59,7 +59,7 @@ def upgrade():
|
||||||
|
|
||||||
# ToErased table
|
# ToErased table
|
||||||
op.create_table('to_erased',
|
op.create_table('to_erased',
|
||||||
sa.Column('document_id', sa.BigInteger(), nullable=False),
|
sa.Column('document_id', sa.BigInteger(), nullable=True),
|
||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
|
sa.ForeignKeyConstraint(['document_id'], [f'{get_inv()}.document.id'], ),
|
||||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
|
|
|
@ -1327,26 +1327,15 @@ class ToPrepare(ActionWithMultipleDevices):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ToErased(ActionWithMultipleDevices):
|
class ToErased(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
"""The device has been selected for insert one proof of erease disk.
|
"""The device has been selected for insert one proof of erease disk.
|
||||||
"""
|
"""
|
||||||
document_comment = """The user that gets the device due this deal."""
|
document_comment = """The user that gets the device due this deal."""
|
||||||
# document_id = db.Column(BigInteger,
|
document_id = db.Column(BigInteger,
|
||||||
# db.ForeignKey('document.id'),
|
db.ForeignKey('document.id'),
|
||||||
# nullable=False)
|
nullable=False)
|
||||||
# document = db.relationship('EraseDocument',
|
document = db.relationship('Document',
|
||||||
# backref=backref('actions',
|
backref=backref('actions',
|
||||||
# # lazy=True,
|
|
||||||
# # uselist=False,
|
|
||||||
# # cascade=CASCADE_OWN),
|
|
||||||
# uselist=True,
|
|
||||||
# lazy=True,
|
|
||||||
# order_by=lambda: Action.end_time,
|
|
||||||
# collection_class=list),
|
|
||||||
# primaryjoin='ToErased.document_id == EraseDocument.id')
|
|
||||||
document_id = Column(BigInteger, ForeignKey('document.id'), nullable=False)
|
|
||||||
document = relationship('Document',
|
|
||||||
backref=backref('document_one',
|
|
||||||
lazy=True,
|
lazy=True,
|
||||||
cascade=CASCADE_OWN),
|
cascade=CASCADE_OWN),
|
||||||
primaryjoin='ToErased.document_id == Document.id')
|
primaryjoin='ToErased.document_id == Document.id')
|
||||||
|
|
|
@ -17,6 +17,7 @@ from ereuse_devicehub.resources.action import models as m
|
||||||
from ereuse_devicehub.resources.agent import schemas as s_agent
|
from ereuse_devicehub.resources.agent import schemas as s_agent
|
||||||
from ereuse_devicehub.resources.device import schemas as s_device
|
from ereuse_devicehub.resources.device import schemas as s_device
|
||||||
from ereuse_devicehub.resources.tradedocument import schemas as s_document
|
from ereuse_devicehub.resources.tradedocument import schemas as s_document
|
||||||
|
from ereuse_devicehub.resources.documents import schemas as s_generic_document
|
||||||
from ereuse_devicehub.resources.enums import AppearanceRange, BiosAccessRange, FunctionalityRange, \
|
from ereuse_devicehub.resources.enums import AppearanceRange, BiosAccessRange, FunctionalityRange, \
|
||||||
PhysicalErasureMethod, R_POSITIVE, RatingRange, \
|
PhysicalErasureMethod, R_POSITIVE, RatingRange, \
|
||||||
Severity, SnapshotSoftware, TestDataStorageLength
|
Severity, SnapshotSoftware, TestDataStorageLength
|
||||||
|
@ -432,7 +433,8 @@ class Prepare(ActionWithMultipleDevices):
|
||||||
|
|
||||||
class ToErased(ActionWithMultipleDevices):
|
class ToErased(ActionWithMultipleDevices):
|
||||||
__doc__ = m.ToErased.__doc__
|
__doc__ = m.ToErased.__doc__
|
||||||
document = NestedOn('Document', only_query='id')
|
document = NestedOn(s_generic_document.Document, only_query='id')
|
||||||
|
# document = NestedOn('EraseDocument')
|
||||||
# device = NestedOn(s_device.Device, only_query='id')
|
# device = NestedOn(s_device.Device, only_query='id')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,25 +10,13 @@ from ereuse_devicehub.resources.action.models import (Trade, Confirm, ConfirmRev
|
||||||
ConfirmRevokeDocument)
|
ConfirmRevokeDocument)
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
from ereuse_devicehub.resources.action.models import ToErased
|
from ereuse_devicehub.resources.action.models import ToErased
|
||||||
from ereuse_devicehub.resources.documents.models import EraseDocument
|
from ereuse_devicehub.resources.documents.models import Document
|
||||||
from ereuse_devicehub.resources.documents.schemas import EraseDocument as sh_document
|
from ereuse_devicehub.resources.device.models import DataStorage
|
||||||
|
from ereuse_devicehub.resources.documents.schemas import Document as sh_document
|
||||||
|
|
||||||
|
|
||||||
class ErasedView():
|
class ErasedView():
|
||||||
"""Handler for manager the trade action register from post
|
"""Handler for manager the action register for add to a device one proof of erase
|
||||||
|
|
||||||
request_post = {
|
|
||||||
'type': 'Trade',
|
|
||||||
'devices': [device_id],
|
|
||||||
'documents': [document_id],
|
|
||||||
'userFrom': user2.email,
|
|
||||||
'userTo': user.email,
|
|
||||||
'price': 10,
|
|
||||||
'date': "2020-12-01T02:00:00+00:00",
|
|
||||||
'lot': lot['id'],
|
|
||||||
'confirm': True,
|
|
||||||
}
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, data, schema):
|
def __init__(self, data, schema):
|
||||||
|
@ -37,30 +25,33 @@ class ErasedView():
|
||||||
self.insert_action(copy.copy(data))
|
self.insert_action(copy.copy(data))
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
db.session().final_flush()
|
db.session().final_flush()
|
||||||
ret = self.schema.jsonify(self.erased)
|
from flask import jsonify
|
||||||
|
ret = jsonify(self.erased)
|
||||||
ret.status_code = 201
|
ret.status_code = 201
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def insert_document(self, data):
|
def insert_document(self, data):
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
schema = sh_document()
|
schema = sh_document()
|
||||||
[data.pop(x) for x in ['severity', 'devices', 'name', 'description']]
|
[data.pop(x, None) for x in ['severity', 'devices', 'name', 'description']]
|
||||||
doc_data = schema.load(data)
|
doc_data = schema.load(data)
|
||||||
doc_data['type'] = 'ToErased'
|
doc_data['type'] = 'ToErased'
|
||||||
self.document = EraseDocument(**doc_data)
|
self.document = Document(**doc_data)
|
||||||
db.session.add(self.document)
|
db.session.add(self.document)
|
||||||
# db.session.commit()
|
|
||||||
|
|
||||||
def insert_action(self, data):
|
def insert_action(self, data):
|
||||||
import pdb; pdb.set_trace()
|
|
||||||
[data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash']]
|
[data.pop(x, None) for x in ['url', 'documentId', 'filename', 'hash']]
|
||||||
# self.data = self.schema.load(data)
|
self.data = self.schema.load(data)
|
||||||
# self.data['document_id'] = self.document.id
|
|
||||||
# self.data['document'] = self.document
|
for dev in self.data['devices']:
|
||||||
# data['document_id'] = self.document.id
|
if not hasattr(dev, 'components'):
|
||||||
data['document'] = self.document
|
continue
|
||||||
self.erased = ToErased(**data)
|
|
||||||
|
for component in dev.components:
|
||||||
|
if isinstance(component, DataStorage):
|
||||||
|
self.data['devices'].add(component)
|
||||||
|
|
||||||
|
self.data['document'] = self.document
|
||||||
|
self.erased = ToErased(**self.data)
|
||||||
db.session.add(self.erased)
|
db.session.add(self.erased)
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
from citext import CIText
|
from citext import CIText
|
||||||
from flask import g
|
from flask import g
|
||||||
|
from sqlalchemy import BigInteger, Column, Sequence, Unicode
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from teal.db import URL
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
from ereuse_devicehub.resources.models import Thing, STR_SM_SIZE
|
from ereuse_devicehub.resources.models import Thing, STR_SM_SIZE
|
||||||
|
|
||||||
from sqlalchemy import BigInteger, Column, Sequence, Unicode
|
|
||||||
from teal.db import URL
|
|
||||||
|
|
||||||
|
|
||||||
class Document(Thing):
|
class Document(Thing):
|
||||||
"""This represent a generic document."""
|
"""This represent a generic document."""
|
||||||
|
@ -37,11 +35,3 @@ class Document(Thing):
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return '{0.file_name}'.format(self)
|
return '{0.file_name}'.format(self)
|
||||||
|
|
||||||
|
|
||||||
class EraseDocument(Document):
|
|
||||||
"""This represent a document involved in a erase manual action.
|
|
||||||
This represent the proof.
|
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
|
@ -5,22 +5,22 @@ from ereuse_devicehub.resources.documents import models as m
|
||||||
# from marshmallow import ValidationError, validates_schema
|
# from marshmallow import ValidationError, validates_schema
|
||||||
|
|
||||||
|
|
||||||
class EraseDocument(Thing):
|
class Document(Thing):
|
||||||
__doc__ = m.EraseDocument.__doc__
|
__doc__ = m.Document.__doc__
|
||||||
id = Integer(description=m.EraseDocument.id.comment, dump_only=True)
|
id = Integer(description=m.Document.id.comment, dump_only=True)
|
||||||
type = SanitizedStr(default='EraseDocument')
|
type = SanitizedStr(default='Document')
|
||||||
date = DateTime(data_key='endTime',
|
date = DateTime(data_key='endTime',
|
||||||
required=False,
|
required=False,
|
||||||
description=m.EraseDocument.date.comment)
|
description=m.Document.date.comment)
|
||||||
id_document = SanitizedStr(data_key='documentId',
|
id_document = SanitizedStr(data_key='documentId',
|
||||||
default='',
|
default='',
|
||||||
description=m.EraseDocument.id_document.comment)
|
description=m.Document.id_document.comment)
|
||||||
file_name = SanitizedStr(data_key='filename',
|
file_name = SanitizedStr(data_key='filename',
|
||||||
default='',
|
default='',
|
||||||
description=m.EraseDocument.file_name.comment,
|
description=m.Document.file_name.comment,
|
||||||
validate=validate.Length(max=100))
|
validate=validate.Length(max=100))
|
||||||
file_hash = SanitizedStr(data_key='hash',
|
file_hash = SanitizedStr(data_key='hash',
|
||||||
default='',
|
default='',
|
||||||
description=m.EraseDocument.file_hash.comment,
|
description=m.Document.file_hash.comment,
|
||||||
validate=validate.Length(max=64))
|
validate=validate.Length(max=64))
|
||||||
url = URL(description=m.EraseDocument.url.comment)
|
url = URL(description=m.Document.url.comment)
|
||||||
|
|
Reference in New Issue