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.
multi-ogserver
Javier Sánchez Parra 2021-09-29 12:16:32 +02:00
parent f572643605
commit 3e7801e487
2 changed files with 19 additions and 0 deletions

View File

@ -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 %}

View File

@ -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'))