summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-01-10 11:23:37 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-01-10 11:31:15 +0100
commit2509cacc005832b37e181f6a6a4795f5c7e1fff9 (patch)
treea8ccc3610fa773e4ea0d34a6af6cfc0be0483216 /ogcp/views.py
parent695fcfe6255fd53b19b416e8375b48d2dc5595e4 (diff)
views: Add delete folder
Add functionality to allow the user to delete a folder. Show a confirmation page to the user listing the content of the folder that is about to delete
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py49
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():