summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-09-29 12:16:32 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2021-09-29 17:12:15 +0200
commit3e7801e4872ac81f67e746da89cda43fd00ff592 (patch)
tree40edbacb6b3184535253a59add6fe87222e72f18 /ogcp
parentf572643605f1337f9da8c451e2f79190b12bafa6 (diff)
Add "Delete image" action
Adds a new button in the images view. This action handles image deletion, one at a time for security. Users must select an image using the images tree.
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/templates/images.html2
-rw-r--r--ogcp/views.py17
2 files changed, 19 insertions, 0 deletions
diff --git a/ogcp/templates/images.html b/ogcp/templates/images.html
index 3faa029..e198e6c 100644
--- a/ogcp/templates/images.html
+++ b/ogcp/templates/images.html
@@ -27,5 +27,7 @@
{% block commands %}
<input class="btn btn-light" type="submit" value="{{ _('Image details') }}"
form="imagesForm" formaction="{{ url_for('action_image_info') }}" formmethod="get">
+ <input class="btn btn-light" type="submit" value="{{ _('Delete image') }}"
+ form="imagesForm" formaction="{{ url_for('action_image_delete') }}" formmethod="post">
{% endblock %}
diff --git a/ogcp/views.py b/ogcp/views.py
index 1999644..a42642f 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -801,3 +801,20 @@ def action_image_info():
form.software_id.data = image['software_id']
return render_template('actions/image_details.html', form=form)
+
+@app.route('/action/image/delete', methods=['POST'])
+@login_required
+def action_image_delete():
+ ids = parse_elements(request.form.to_dict())
+ if not validate_elements(ids, max_len=1):
+ return redirect(url_for('images'))
+
+ id = ids.pop()
+ payload = {'image': id}
+ r = g.server.post('/image/delete', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('OgServer replied with a non ok status code'), category='error')
+ else:
+ flash(_('Delete client request processed successfully'), category='info')
+ return redirect(url_for('images'))
+