summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-01-14 15:04:58 +0100
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-01-19 15:36:58 +0100
commit73963a0273b64cb3fb8dedcd0886dcfaf92dfc20 (patch)
treeccc4bae8de4b4bf433ca8def7c1070eb6e4cf35c /ogcp/views.py
parent96d2797ec3dd4e37b668c58c43dce26ce24968d6 (diff)
Ask twice to delete clients
This commit adds an extra view to ensure users do not clients accidentally. It also includes Spanish translation of the new strings.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index c309003..bccd4f9 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -11,7 +11,8 @@ from flask import (
from ogcp.forms.action_forms import (
WOLForm, SetupForm, ClientDetailsForm, ImageDetailsForm, HardwareForm,
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
- RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm
+ RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
+ GenericForm
)
from flask_login import (
current_user, LoginManager,
@@ -630,20 +631,33 @@ def action_client_add():
form.create.render_kw = {"formaction": url_for('action_client_add')}
return render_template('actions/client_details.html', form=form)
-@app.route('/action/client/delete', methods=['POST'])
+@app.route('/action/client/delete', methods=['GET', 'POST'])
@login_required
def action_client_delete():
- ips = parse_elements(request.form.to_dict())
- if not validate_elements(ips):
- return redirect(url_for('scopes'))
+ form = GenericForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ if not validate_elements(ips):
+ return redirect(url_for('scopes'))
- payload = {'clients': list(ips)}
- r = g.server.post('/client/delete', payload)
- if r.status_code != requests.codes.ok:
- flash(_('OgServer replied with a non ok status code'), category='error')
+ payload = {'clients': ips}
+ r = g.server.post('/client/delete', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error deleting client'),
+ category='error')
+ else:
+ flash(_('Client deleted successfully'),
+ category='info')
+ return redirect(url_for('scopes'))
else:
- flash(_('Delete client request processed successfully'), category='info')
- return redirect(url_for('scopes'))
+ ips = parse_elements(request.args.to_dict())
+ form.ips.data = " ".join(ips)
+ if validate_elements(ips):
+ scopes, clients = get_scopes(set(ips))
+ return render_template('actions/delete_client.html', form=form,
+ scopes=scopes)
+ else:
+ return redirect(url_for('scopes'))
@app.route('/action/mode', methods=['GET', 'POST'])
@login_required