From 8b07554ef762da09c43fc9a7c076b12735f4f0b4 Mon Sep 17 00:00:00 2001 From: Christoffer Lehre Date: Fri, 17 Oct 2025 09:24:49 +0200 Subject: [PATCH] feat: soft-delete-tools --- migrations/V001.032__soft_delete_tools.sql | 5 +++++ web/src/p2k16/core/models.py | 21 ++++++++++++++++++- .../p2k16/web/static/admin-tool-detail.html | 15 +++++++++++++ web/src/p2k16/web/static/admin-tool-list.html | 15 ++++++++++--- web/src/p2k16/web/static/p2k16/p2k16.js | 2 +- web/src/p2k16/web/tool_blueprint.py | 17 ++++++++++++++- 6 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 migrations/V001.032__soft_delete_tools.sql diff --git a/migrations/V001.032__soft_delete_tools.sql b/migrations/V001.032__soft_delete_tools.sql new file mode 100644 index 00000000..bef8199f --- /dev/null +++ b/migrations/V001.032__soft_delete_tools.sql @@ -0,0 +1,5 @@ +ALTER TABLE tool_description + ADD COLUMN disabled BOOLEAN DEFAULT FALSE NOT NULL; + +ALTER TABLE tool_description_version + ADD COLUMN disabled BOOLEAN DEFAULT FALSE NOT NULL; diff --git a/web/src/p2k16/core/models.py b/web/src/p2k16/core/models.py index f57d5a19..4807d30d 100644 --- a/web/src/p2k16/core/models.py +++ b/web/src/p2k16/core/models.py @@ -130,6 +130,25 @@ def __init__(self): super().__init__() self.updated_by_id = None +class DisabledMixin(object): + disabled = Column(Boolean, nullable=False, default=False) + + def mark_disabled(self): + self.disabled = True + + def mark_active(self): + self.disabled = False + + def is_disabled(self) -> bool: + return self.disabled + + @classmethod + def get_active(cls): + return cls.query.filter(cls.disabled == False).all() + + @classmethod + def get_all_including_disabled(cls): + return cls.query.all() # This is probably the mixin you should use class DefaultMixin(P2k16Mixin, CreatedAtMixin, CreatedByMixin, UpdatedAtMixin, UpdatedByMixin): @@ -582,7 +601,7 @@ def __init__(self, account: Account, awarded_by: Account, description: BadgeDesc # # Tools # -class ToolDescription(DefaultMixin, db.Model): +class ToolDescription(DefaultMixin, DisabledMixin, db.Model): __tablename__ = 'tool_description' __versioned__ = {} diff --git a/web/src/p2k16/web/static/admin-tool-detail.html b/web/src/p2k16/web/static/admin-tool-detail.html index 9d4f7fc8..c35e24af 100644 --- a/web/src/p2k16/web/static/admin-tool-detail.html +++ b/web/src/p2k16/web/static/admin-tool-detail.html @@ -36,6 +36,21 @@

ng-model="ctrl.tool.circle"/> +
+ +
+ + Disabled + Active + Check to disable this tool +

+ Last updated by {{ ctrl.tool.updatedBy }} at {{ ctrl.tool.updatedAt | date:'short' }} +

+
+