diff --git a/migrations/V001.032__soft_delete_tools.sql b/migrations/V001.032__soft_delete_tools.sql new file mode 100644 index 0000000..bef8199 --- /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 f57d5a1..4807d30 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 9d4f7fc..c35e24a 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' }} +

+
+