From aee34e4989c59109454280d21f3f5636d3091315 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 7 Sep 2022 11:14:13 +0200 Subject: [PATCH 1/4] drop / of url --- ereuse_devicehub/templates/workbench/settings.html | 8 ++++---- ereuse_devicehub/workbench/__init__.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/templates/workbench/settings.html b/ereuse_devicehub/templates/workbench/settings.html index b1411100..6f5c08fc 100644 --- a/ereuse_devicehub/templates/workbench/settings.html +++ b/ereuse_devicehub/templates/workbench/settings.html @@ -46,11 +46,11 @@
Workbench 2022

- Download Checksum: SHA512SUMS | + Download Checksum: SHA512SUMS | Help

@@ -113,14 +113,14 @@

{{ v.iso }}

- Download Checksum: SHA512SUMS | + Download Checksum: SHA512SUMS | Help

diff --git a/ereuse_devicehub/workbench/__init__.py b/ereuse_devicehub/workbench/__init__.py index 9c52b02b..82baa31a 100644 --- a/ereuse_devicehub/workbench/__init__.py +++ b/ereuse_devicehub/workbench/__init__.py @@ -5,7 +5,7 @@ isos = { }, "2022": { 'iso': "USODY_2022.5.2-beta.iso", - 'url': 'http://releases.usody.com//2022/', + 'url': 'http://releases.usody.com/2022/', }, "v14": {'iso': "USODY_14.0.0.iso", 'url': 'http://releases.usody.com/v14/'}, } From f19046b2ef0ef06e62f6f4319fdeea667a7e845d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 7 Sep 2022 14:04:09 +0200 Subject: [PATCH 2/4] add backups for the abstract phid and dhid --- ereuse_devicehub/inventory/views.py | 16 ++++++++ .../versions/6b0880832b78_backup_dhid.py | 41 +++++++++++++++++++ ereuse_devicehub/resources/device/models.py | 2 + 3 files changed, 59 insertions(+) create mode 100644 ereuse_devicehub/migrations/versions/6b0880832b78_backup_dhid.py diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 8b65e37a..4c1b38dd 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -279,6 +279,11 @@ class BindingView(GenericMixin): self.abstract_dhid = self.old_device.devicehub_id self.abstract_phid = self.old_placeholder.phid + # to do a backup of abstract_dhid and abstract_phid in + # workbench device + self.abstract_device.dhid_bk = self.abstract_dhid + self.abstract_device.phid_bk = self.abstract_phid + def post(self): for plog in PlaceholdersLog.query.filter_by( placeholder_id=self.old_placeholder.id @@ -379,6 +384,17 @@ class UnBindingView(GenericMixin): c.binding.device.parent = new_device placeholder = Placeholder(device=new_device, binding=device, is_abstract=True) + if ( + device.dhid_bk + and not Device.query.filter_by(devicehub_id=device.dhid_bk).first() + ): + new_device.devicehub_id = device.dhid_bk + if ( + device.phid_bk + and not Placeholder.query.filter_by(phid=device.phid_bk).first() + ): + placeholder.phid = device.phid_bk + db.session.add(placeholder) db.session.commit() diff --git a/ereuse_devicehub/migrations/versions/6b0880832b78_backup_dhid.py b/ereuse_devicehub/migrations/versions/6b0880832b78_backup_dhid.py new file mode 100644 index 00000000..f79085f4 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/6b0880832b78_backup_dhid.py @@ -0,0 +1,41 @@ +"""backup dhid + +Revision ID: 6b0880832b78 +Revises: d7ea9a3b2da1 +Create Date: 2022-09-07 12:53:25.827186 + +""" +import citext +import sqlalchemy as sa +from alembic import context, op + +# revision identifiers, used by Alembic. +revision = '6b0880832b78' +down_revision = 'd7ea9a3b2da1' +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.add_column( + 'device', + sa.Column('dhid_bk', citext.CIText(), unique=False, nullable=True), + schema=f'{get_inv()}', + ) + op.add_column( + 'device', + sa.Column('phid_bk', citext.CIText(), unique=False, nullable=True), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_column('device', 'dhid_bk', schema=f'{get_inv()}') + op.drop_column('device', 'phid_bk', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index f37ef586..01845ca7 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -173,6 +173,8 @@ class Device(Thing): db.CIText(), nullable=True, unique=True, default=create_code ) devicehub_id.comment = "device have a unique code." + dhid_bk = db.Column(db.CIText(), nullable=True, unique=False) + phid_bk = db.Column(db.CIText(), nullable=True, unique=False) active = db.Column(Boolean, default=True) _NON_PHYSICAL_PROPS = { From e7a772dee75583f98c7e44d49052e1ae724ef8c0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 7 Sep 2022 14:04:54 +0200 Subject: [PATCH 3/4] drop S of SHA512SUMS in Template settings workbench --- ereuse_devicehub/templates/workbench/settings.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/templates/workbench/settings.html b/ereuse_devicehub/templates/workbench/settings.html index 6f5c08fc..4cf2e1cc 100644 --- a/ereuse_devicehub/templates/workbench/settings.html +++ b/ereuse_devicehub/templates/workbench/settings.html @@ -50,7 +50,7 @@

- Download Checksum: SHA512SUMS | + Download Checksum: SHA512SUM | Help

@@ -120,7 +120,7 @@ {{ v.iso }}

- Download Checksum: SHA512SUMS | + Download Checksum: SHA512SUM | Help

From 59137334042a88c0e913f2315c20d3603cd2f6f3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 7 Sep 2022 16:23:31 +0200 Subject: [PATCH 4/4] fix tests --- ereuse_devicehub/resources/device/models.py | 2 ++ tests/test_render_2_0.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 01845ca7..7735c817 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -202,6 +202,8 @@ class Device(Thing): 'devicehub_id', 'system_uuid', 'active', + 'phid_bk', + 'dhid_bk', } __table_args__ = ( diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index fc62572d..0c1615a5 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -2148,6 +2148,8 @@ def test_unbinding(user3: UserClientFlask): user3.get(uri) old_placeholder = dev_wb.binding + old_phid = old_placeholder.phid + old_dhid = dev_wb.dhid # page binding dhid = dev_wb.dhid @@ -2171,7 +2173,8 @@ def test_unbinding(user3: UserClientFlask): # check new structure assert dev.placeholder.binding is None - assert dev_wb.binding.phid == '2' + assert dev_wb.binding.phid == old_phid + assert dev_wb.dhid == old_dhid assert old_placeholder.device.model == dev_wb.binding.device.model assert old_placeholder.device != dev_wb.binding.device assert Placeholder.query.filter_by(id=old_placeholder.id).first() is None