diff options
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index bd179cd..1203ffd 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -35,6 +35,7 @@ import hashlib import json import os import re +from collections import deque FS_CODES = { 0: 'DISK', @@ -990,6 +991,54 @@ def action_client_update(): return render_template('actions/client_details.html', form=form, parent="scopes.html", scopes=scopes) +def find_folder(folder_id, scopes): + scopes = deque([scopes['scope']]) + while scopes: + scope_ls = scopes.popleft() + if not scope_ls: + continue + else: + for scope in scope_ls: + if scope['type'] == 'folder' and scope['id'] == folder_id: + return scope + else: + scopes.append(scope['scope']) + return None + +@app.route('/action/folder/delete', methods=['GET', 'POST']) +@login_required +def action_folder_delete(): + form = FolderForm(request.form) + if request.method == 'POST': + payload = {"id": int(form.folder_id.data)} + server = get_server_from_ip_port(form.server.data) + r = server.post('/folder/delete', payload) + if r.status_code != requests.codes.ok: + flash(('ogServer: error deleting folder'), + category='error') + else: + flash(('Folder deleted successfully'), category='info') + return redirect(url_for("scopes")) + else: + params = request.args.to_dict() + folder_id = params.get('folder') + if not folder_id: + flash(('Please, select a folder'), category='error') + return redirect(url_for('scopes')) + form.folder_id.data = folder_id + form.server.data = params['scope-server'] + form.submit.render_kw = {"formaction": url_for('action_folder_delete')} + + scopes, _ = get_scopes() + folder = find_folder(int(folder_id), scopes) + if not folder: + flash(('Folder was not found'), category='info') + return redirect(url_for("scopes")) + form.name.data = folder['name'] + form.name.render_kw = {'readonly': True} + return render_template('actions/folder_delete.html', form=form, + parent="scopes.html", scopes=scopes, folder_content=folder['scope']) + @app.route('/action/folder/add', methods=['GET']) @login_required def action_folder_add(): |