From c2b0e6341fbf376bd85807fe574a0bfde5170bb4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 24 Sep 2021 12:37:33 +0200 Subject: [PATCH] adding new models for Use, Recycling, Refurbish and Management actions --- .../a0978ac6cf4a_adding_state_actions.py | 38 +++++++++++++++++++ ereuse_devicehub/resources/action/__init__.py | 14 ++++++- ereuse_devicehub/resources/action/models.py | 27 +++++++++++-- ereuse_devicehub/resources/action/schemas.py | 18 +++++++-- 4 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 ereuse_devicehub/migrations/versions/a0978ac6cf4a_adding_state_actions.py diff --git a/ereuse_devicehub/migrations/versions/a0978ac6cf4a_adding_state_actions.py b/ereuse_devicehub/migrations/versions/a0978ac6cf4a_adding_state_actions.py new file mode 100644 index 00000000..02422946 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/a0978ac6cf4a_adding_state_actions.py @@ -0,0 +1,38 @@ +"""adding state actions + +Revision ID: a0978ac6cf4a +Revises: 7ecb8ff7abad +Create Date: 2021-09-24 12:03:01.661679 + +""" +from alembic import op, context +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + + +# revision identifiers, used by Alembic. +revision = 'a0978ac6cf4a' +down_revision = '7ecb8ff7abad' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + +def upgrade(): + op.create_table('action_status', + sa.Column('rol_user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ), + sa.ForeignKeyConstraint(['rol_user_id'], ['common.user.id'], ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}' + ) + + +def downgrade(): + op.drop_table('action_status', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/action/__init__.py b/ereuse_devicehub/resources/action/__init__.py index 341d5640..09e27245 100644 --- a/ereuse_devicehub/resources/action/__init__.py +++ b/ereuse_devicehub/resources/action/__init__.py @@ -199,9 +199,19 @@ class RecyclingDef(ActionDef): SCHEMA = schemas.Recycling -class ReuseDef(ActionDef): +class UseDef(ActionDef): VIEW = None - SCHEMA = schemas.Reuse + SCHEMA = schemas.Use + + +class RefurbishDef(ActionDef): + VIEW = None + SCHEMA = schemas.Refurbish + + +class ManagementDef(ActionDef): + VIEW = None + SCHEMA = schemas.Management class ToPrepareDef(ActionDef): diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 7529b513..f0722803 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1341,12 +1341,31 @@ class DataWipe(JoinedTableMixin, ActionWithMultipleDevices): primaryjoin='DataWipe.document_id == DataWipeDocument.id') -class Recycling(ActionWithMultipleDevices): - """This action mark one devices or container as recycled""" +class ActionStatus(JoinedTableMixin, ActionWithMultipleDevices): + """This is a meta-action than mark the status of the devices""" + + rol_user_id = db.Column(UUID(as_uuid=True), + db.ForeignKey(User.id), + nullable=False, + default=lambda: g.user.id) + rol_user = db.relationship(User, primaryjoin=rol_user_id == User.id) + rol_user_comment = """The user that .""" -class Reuse(ActionWithMultipleDevices): - """This action mark one devices or container as reuse""" +class Recycling(ActionStatus): + """This action mark one devices or container as recycling""" + + +class Use(ActionStatus): + """This action mark one devices or container as use""" + + +class Refurbish(ActionStatus): + """This action mark one devices or container as refurbish""" + + +class Management(ActionStatus): + """This action mark one devices or container as management""" class Prepare(ActionWithMultipleDevices): diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 22ff595c..6f18de75 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -423,12 +423,24 @@ class Ready(ActionWithMultipleDevices): __doc__ = m.Ready.__doc__ -class Recycling(ActionWithMultipleDevices): +class ActionStatus(ActionWithMultipleDevices): + rol_user = NestedOn(s_user.User, dump_only=True, exclude=('token',)) + + +class Recycling(ActionStatus): __doc__ = m.Recycling.__doc__ -class Reuse(ActionWithMultipleDevices): - __doc__ = m.Reuse.__doc__ +class Use(ActionStatus): + __doc__ = m.Use.__doc__ + + +class Refurbish(ActionStatus): + __doc__ = m.Refurbish.__doc__ + + +class Management(ActionStatus): + __doc__ = m.Management.__doc__ class ToPrepare(ActionWithMultipleDevices):