drop all ethereum_address in the system

This commit is contained in:
Cayo Puigdefabregas 2021-02-10 13:05:43 +01:00
parent 6b7571fe86
commit 72466003d0
12 changed files with 30 additions and 30 deletions

View File

@ -188,8 +188,8 @@ class Dummy:
# For netbook: to preapre -> torepair -> to dispose -> disposed # For netbook: to preapre -> torepair -> to dispose -> disposed
print('⭐ Done.') print('⭐ Done.')
def user_client(self, email: str, password: str, name: str, ethereum_address: str): def user_client(self, email: str, password: str, name: str:
user = User(email=email, password=password, ethereum_address=ethereum_address) user = User(email=email, password=password)
user.individuals.add(Person(name=name)) user.individuals.add(Person(name=name))
db.session.add(user) db.session.add(user)

View File

@ -31,7 +31,14 @@ def upgrade():
op.alter_column('computer', 'deposit', new_column_name='amount', schema=f'{get_inv()}') 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.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', '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', '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_function', schema=f'{get_inv()}')
op.drop_table('proof_data_wipe', schema=f'{get_inv()}') op.drop_table('proof_data_wipe', schema=f'{get_inv()}')
op.drop_table('proof_transfer', schema=f'{get_inv()}') op.drop_table('proof_transfer', schema=f'{get_inv()}')
@ -45,10 +52,20 @@ def upgrade():
def downgrade(): def downgrade():
op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') 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('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('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.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', op.create_table('proof',
sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False, nullable=False,

View File

@ -35,13 +35,6 @@ class DeliverynoteView(View):
# computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)] # computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)]
for key, value in d.items(): for key, value in d.items():
setattr(dlvnote, key, value) 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() db.session.commit()
return Response(status=204) return Response(status=204)

View File

@ -471,7 +471,6 @@ class Computer(Device):
It is a subset of the Linux definition of DMI / DMI decode. 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) amount = Column(Integer, check_range('amount', min=0, max=100), default=0)
owner_id = db.Column(UUID(as_uuid=True), owner_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id), db.ForeignKey(User.id),

View File

@ -144,7 +144,7 @@ class Computer(DisplayMixin, Device):
amount = ... # type: Column amount = ... # type: Column
owner_address = ... # type: Column owner_address = ... # type: Column
transfer_state = ... # type: Column transfer_state = ... # type: Column
receiver_address = ... # type: Column receiver_id = ... # uuid: Column
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
super().__init__(**kwargs) super().__init__(**kwargs)

View File

@ -123,7 +123,6 @@ class Computer(Device):
dump_only=True, dump_only=True,
collection_class=set, collection_class=set,
description=m.Computer.privacy.__doc__) description=m.Computer.privacy.__doc__)
ethereum_address = SanitizedStr(validate=f.validate.Length(max=42))
amount = Integer(validate=f.validate.Range(min=0, max=100), amount = Integer(validate=f.validate.Range(min=0, max=100),
description=m.Computer.amount.__doc__) description=m.Computer.amount.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id') # author_id = NestedOn(s_user.User,only_query='author_id')

View File

@ -106,7 +106,7 @@ class DeviceView(View):
resource_def = app.resources['Computer'] resource_def = app.resources['Computer']
# TODO check how to handle the 'actions_one' # TODO check how to handle the 'actions_one'
patch_schema = resource_def.SCHEMA( 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) json = request.get_json(schema=patch_schema)
# TODO check how to handle the 'actions_one' # TODO check how to handle the 'actions_one'
json.pop('actions_one') json.pop('actions_one')

View File

@ -72,9 +72,10 @@ class Lot(Thing):
transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False)
transfer_state.comment = TransferState.__doc__ transfer_state.comment = TransferState.__doc__
receiver_address = db.Column(CIText(), receiver_address = db.Column(CIText(),
db.ForeignKey(User.ethereum_address), db.ForeignKey(User.email),
nullable=True) nullable=False,
receiver = db.relationship(User, primaryjoin=receiver_address == User.ethereum_address) default=lambda: g.user.email)
receiver = db.relationship(User, primaryjoin=receiver_address == User.email)
def __init__(self, name: str, closed: bool = closed.default.arg, def __init__(self, name: str, closed: bool = closed.default.arg,
description: str = None) -> None: description: str = None) -> None:

View File

@ -25,11 +25,10 @@ class User(Thing):
backref=db.backref('users', lazy=True, collection_class=set), backref=db.backref('users', lazy=True, collection_class=set),
secondary=lambda: UserInventory.__table__, secondary=lambda: UserInventory.__table__,
collection_class=set) collection_class=set)
ethereum_address = Column(CIText(), unique=True, default=None)
# todo set restriction that user has, at least, one active db # 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. """Creates an user.
:param email: :param email:
:param password: :param password:
@ -38,7 +37,7 @@ class User(Thing):
inventory. inventory.
""" """
inventories = inventories or {Inventory.current} 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: def __repr__(self) -> str:
return '<User {0.email}>'.format(self) return '<User {0.email}>'.format(self)
@ -52,11 +51,6 @@ class User(Thing):
"""The individual associated for this database, or None.""" """The individual associated for this database, or None."""
return next(iter(self.individuals), 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): class UserInventory(db.Model):
"""Relationship between users and their inventories.""" """Relationship between users and their inventories."""

View File

@ -17,7 +17,6 @@ class User(Thing):
password = ... # type: Column password = ... # type: Column
token = ... # type: Column token = ... # type: Column
inventories = ... # type: relationship inventories = ... # type: relationship
ethereum_address = ... # type: Column
def __init__(self, email: str, password: str = None, def __init__(self, email: str, password: str = None,
inventories: Set[Inventory] = None) -> None: inventories: Set[Inventory] = None) -> None:
@ -28,7 +27,6 @@ class User(Thing):
self.individuals = ... # type: Set[Individual] self.individuals = ... # type: Set[Individual]
self.token = ... # type: UUID self.token = ... # type: UUID
self.inventories = ... # type: Set[Inventory] self.inventories = ... # type: Set[Inventory]
self.ethereum_address = ... # type: str
@property @property
def individual(self) -> Union[Individual, None]: def individual(self) -> Union[Individual, None]:

View File

@ -19,7 +19,6 @@ class User(Thing):
description='Use this token in an Authorization header to access the app.' description='Use this token in an Authorization header to access the app.'
'The token can change overtime.') 'The token can change overtime.')
inventories = NestedOn(Inventory, many=True, dump_only=True) inventories = NestedOn(Inventory, many=True, dump_only=True)
ethereum_address = String(description='User identifier address inside the Blockchain')
def __init__(self, def __init__(self,
only=None, only=None,

View File

@ -15,7 +15,7 @@ class UserView(View):
def login(): def login():
# We use custom schema as we only want to parse a subset of user # 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 # noinspection PyArgumentList
u = request.get_json(schema=user_s) u = request.get_json(schema=user_s)
user = User.query.filter_by(email=u['email']).one_or_none() user = User.query.filter_by(email=u['email']).one_or_none()