diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index ed402141..162ccf56 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -188,8 +188,8 @@ class Dummy: # For netbook: to preapre -> torepair -> to dispose -> disposed print('⭐ Done.') - def user_client(self, email: str, password: str, name: str, ethereum_address: str): - user = User(email=email, password=password, ethereum_address=ethereum_address) + def user_client(self, email: str, password: str, name: str: + user = User(email=email, password=password) user.individuals.add(Person(name=name)) db.session.add(user) diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index 24f4a161..e8bcc663 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -31,7 +31,14 @@ def upgrade(): op.alter_column('computer', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.alter_column('lot', 'deposit', new_column_name='amount', schema=f'{get_inv()}') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') + op.drop_column('computer', 'ethereum_address', schema=f'{get_inv()}') + op.drop_column('user', 'ethereum_address', schema='common') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') + + op.drop_column('lot', 'receiver_address', schema=f'{get_inv()}') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.email'],), schema=f'{get_inv()}') + op.drop_table('proof_function', schema=f'{get_inv()}') op.drop_table('proof_data_wipe', schema=f'{get_inv()}') op.drop_table('proof_transfer', schema=f'{get_inv()}') @@ -45,10 +52,20 @@ def upgrade(): def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.alter_column('deliverynote', 'amount', new_column_name='deposit', schema=f'{get_inv()}') - op.alter_column('computer', 'amount', new_column_name='deposit', schema=f'{get_inv()}') - op.alter_column('lot', 'amount', new_column_name='deposit', schema=f'{get_inv()}') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + + # ===== + op.alter_column('computer', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + op.alter_column('lot', 'amount', new_column_name='deposit', schema=f'{get_inv()}') + + # ===== + op.add_column('computer', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('user', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema='common') + op.add_column('lot', sa.Column('receiver_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.add_column('lot', sa.ForeignKeyConstraint(['receiver_address'], ['common.user.ethereum_address'],), schema=f'{get_inv()}') + + # ===== op.create_table('proof', sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index 321f7ad9..15ceaa4b 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -35,13 +35,6 @@ class DeliverynoteView(View): # computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)] for key, value in d.items(): setattr(dlvnote, key, value) - # Transalate ethereum_address attribute - # devKey = key - # if key == 'ethereum_address': - # devKey = 'deliverynote_address' - # if devKey in device_fields: - # for dev in computers: - # setattr(dev, devKey, value) db.session.commit() return Response(status=204) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index d5503d13..a9efc105 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -471,7 +471,6 @@ class Computer(Device): It is a subset of the Linux definition of DMI / DMI decode. """ - ethereum_address = Column(CIText(), unique=True, default=None) amount = Column(Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index ba1e2fd8..837a737f 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -144,7 +144,7 @@ class Computer(DisplayMixin, Device): amount = ... # type: Column owner_address = ... # type: Column transfer_state = ... # type: Column - receiver_address = ... # type: Column + receiver_id = ... # uuid: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index ac2d117d..706b7e03 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -123,7 +123,6 @@ class Computer(Device): dump_only=True, collection_class=set, description=m.Computer.privacy.__doc__) - ethereum_address = SanitizedStr(validate=f.validate.Length(max=42)) amount = Integer(validate=f.validate.Range(min=0, max=100), description=m.Computer.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 83e16de7..3dde5e3b 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -106,7 +106,7 @@ class DeviceView(View): resource_def = app.resources['Computer'] # TODO check how to handle the 'actions_one' patch_schema = resource_def.SCHEMA( - only=['ethereum_address', 'transfer_state', 'actions_one'], partial=True) + only=['transfer_state', 'actions_one'], partial=True) json = request.get_json(schema=patch_schema) # TODO check how to handle the 'actions_one' json.pop('actions_one') diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 5022b24e..f8a9066b 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -72,9 +72,10 @@ class Lot(Thing): transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ receiver_address = db.Column(CIText(), - db.ForeignKey(User.ethereum_address), - nullable=True) - receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) + db.ForeignKey(User.email), + nullable=False, + default=lambda: g.user.email) + receiver = db.relationship(User, primaryjoin=receiver_address == User.email) def __init__(self, name: str, closed: bool = closed.default.arg, description: str = None) -> None: diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 98a25598..0ab670c8 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -25,11 +25,10 @@ class User(Thing): backref=db.backref('users', lazy=True, collection_class=set), secondary=lambda: UserInventory.__table__, collection_class=set) - ethereum_address = Column(CIText(), unique=True, default=None) # todo set restriction that user has, at least, one active db - def __init__(self, email, password=None, ethereum_address=None, inventories=None) -> None: + def __init__(self, email, password=None, inventories=None) -> None: """Creates an user. :param email: :param password: @@ -38,7 +37,7 @@ class User(Thing): inventory. """ inventories = inventories or {Inventory.current} - super().__init__(email=email, password=password, ethereum_address=ethereum_address, inventories=inventories) + super().__init__(email=email, password=password, inventories=inventories) def __repr__(self) -> str: return ''.format(self) @@ -52,11 +51,6 @@ class User(Thing): """The individual associated for this database, or None.""" return next(iter(self.individuals), None) - @property - def get_ethereum_address(self): - """The ethereum address in Blockchain, or None.""" - return next(iter(self.ethereum_address), None) - class UserInventory(db.Model): """Relationship between users and their inventories.""" diff --git a/ereuse_devicehub/resources/user/models.pyi b/ereuse_devicehub/resources/user/models.pyi index 15874464..6e8d03b9 100644 --- a/ereuse_devicehub/resources/user/models.pyi +++ b/ereuse_devicehub/resources/user/models.pyi @@ -17,7 +17,6 @@ class User(Thing): password = ... # type: Column token = ... # type: Column inventories = ... # type: relationship - ethereum_address = ... # type: Column def __init__(self, email: str, password: str = None, inventories: Set[Inventory] = None) -> None: @@ -28,7 +27,6 @@ class User(Thing): self.individuals = ... # type: Set[Individual] self.token = ... # type: UUID self.inventories = ... # type: Set[Inventory] - self.ethereum_address = ... # type: str @property def individual(self) -> Union[Individual, None]: diff --git a/ereuse_devicehub/resources/user/schemas.py b/ereuse_devicehub/resources/user/schemas.py index 00d022ad..e8d0d768 100644 --- a/ereuse_devicehub/resources/user/schemas.py +++ b/ereuse_devicehub/resources/user/schemas.py @@ -19,7 +19,6 @@ class User(Thing): description='Use this token in an Authorization header to access the app.' 'The token can change overtime.') inventories = NestedOn(Inventory, many=True, dump_only=True) - ethereum_address = String(description='User identifier address inside the Blockchain') def __init__(self, only=None, diff --git a/ereuse_devicehub/resources/user/views.py b/ereuse_devicehub/resources/user/views.py index 19624b80..7053eea7 100644 --- a/ereuse_devicehub/resources/user/views.py +++ b/ereuse_devicehub/resources/user/views.py @@ -15,7 +15,7 @@ class UserView(View): def login(): # We use custom schema as we only want to parse a subset of user - user_s = g.resource_def.SCHEMA(only=('email', 'password', 'ethereum_address')) # type: UserS + user_s = g.resource_def.SCHEMA(only=('email', 'password')) # type: UserS # noinspection PyArgumentList u = request.get_json(schema=user_s) user = User.query.filter_by(email=u['email']).one_or_none()