Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions migrations/V001.032__soft_delete_tools.sql
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 20 additions & 1 deletion web/src/p2k16/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__ = {}

Expand Down
15 changes: 15 additions & 0 deletions web/src/p2k16/web/static/admin-tool-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ <h1>
ng-model="ctrl.tool.circle"/>
</div>
</div>
<div class="form-group" ng-if="ctrl.tool.id">
<label for="disabled" class="col-sm-2">
Disabled
</label>
<div class="col-sm-10">
<input type="checkbox" name="disabled" id="disabled"
ng-model="ctrl.tool.disabled"/>
<span ng-if="ctrl.tool.disabled" class="label label-warning">Disabled</span>
<span ng-if="!ctrl.tool.disabled" class="label label-success">Active</span>
<span class="help-block">Check to disable this tool</span>
<p ng-if="ctrl.tool.updatedBy" class="text-muted">
Last updated by {{ ctrl.tool.updatedBy }} at {{ ctrl.tool.updatedAt | date:'short' }}
</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 text-right">
<button class="btn btn-success" ng-click="ctrl.save()">
Expand Down
15 changes: 12 additions & 3 deletions web/src/p2k16/web/static/admin-tool-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ <h1>Tools</h1>
<thead>
<tr>
<th class="col-sm-2">Name</th>
<th class="col-sm-4">Description</th>
<th class="col-sm-3">Circle</th>
<th class="col-sm-3">Description</th>
<th class="col-sm-2">Circle</th>
<th class="col-sm-2">Status</th>
<th class="col-sm-3">Last Edit</th>
<th class="col-sm-1">Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in ctrl.tools">
<tr ng-repeat="c in ctrl.tools" ng-class="{'text-muted': c.disabled}">
<td>{{ c.name }}</td>
<td>{{ c.description }}</td>
<td>{{ c.circle }}</td>
<td style="vertical-align: middle;">
<span ng-if="c.disabled" class="label label-warning">Disabled</span>
<span ng-if="!c.disabled" class="label label-success">Active</span>
</td>
<td class="text-muted small">
{{ c.updatedBy }} at {{ c.updatedAt | date:'short' }}
</td>
<td>
<a href="#!/admin/tool/{{ c.id }}">edit</a>
</td>
Expand Down
2 changes: 1 addition & 1 deletion web/src/p2k16/web/static/p2k16/p2k16.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
controllerAs: 'ctrl',
templateUrl: p2k16_resources.admin_tool_list_html,
resolve: {
tools: ToolDataServiceResolvers.data_tool_list
tools: ToolDataServiceResolvers.data_tool_list_all
}
}).when("/admin/tool/new", {
controller: AdminToolDetailController,
Expand Down
17 changes: 16 additions & 1 deletion web/src/p2k16/web/tool_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ def tool_to_json(tool: ToolDescription):
"description": tool.description,
"circle": tool.circle.name,
"checkout": checkout_model,
"disabled": tool.is_disabled(),
}}

@registry.route('/data/tool')
def data_tool_list():
tools = ToolDescription.query.all()
tools = ToolDescription.get_active()

return jsonify([tool_to_json(tool) for tool in tools])


@registry.route('/data/tool/all')
@require_circle_membership("despot")
def data_tool_list_all():
tools = ToolDescription.get_all_including_disabled()

return jsonify([tool_to_json(tool) for tool in tools])

Expand Down Expand Up @@ -129,6 +138,12 @@ def _data_tool_save():
tool.name = request.json["name"]
tool.circle = circle
tool.description = request.json["description"]

if request.json.get("disabled", False):
tool.mark_disabled()
else:
if tool.is_disabled():
tool.mark_active()
else:
logger.info("Creating new tooldescription: {}".format(request.json["name"]))
tool = ToolDescription(request.json["name"], request.json["description"], circle)
Expand Down