From 8ac158ee1178152da3fbd074d40bc4ad80f787a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20L=C3=B3pez-Doriga?= Date: Wed, 8 Nov 2023 20:33:01 +0100 Subject: [PATCH] changing controlled for registered --- deploy/data/individuals_test.json | 2 +- permissions/controlled_datasets.yml | 5 +- permissions/permissions-ui/bash/urls.py | 4 +- permissions/permissions-ui/bash/views.py | 83 +++++++++---------- .../permissions-ui/templates/controlled.html | 54 +++++++++--- .../permissions-ui/templates/registered.html | 53 +++--------- permissions/permissions-ui/web/forms.py | 2 +- permissions/public_datasets.yml | 3 +- permissions/registered_datasets.yml | 5 +- 9 files changed, 103 insertions(+), 108 deletions(-) diff --git a/deploy/data/individuals_test.json b/deploy/data/individuals_test.json index 2e8b5ed7..26227f0a 100644 --- a/deploy/data/individuals_test.json +++ b/deploy/data/individuals_test.json @@ -4,7 +4,7 @@ "id" : "NCIT:C42331", "label" : "African" }, - "id" : "HG00096", + "id" : "AV0101", "info" : { "eid" : "fake1" }, diff --git a/permissions/controlled_datasets.yml b/permissions/controlled_datasets.yml index e84d0dec..f9f6ba3d 100644 --- a/permissions/controlled_datasets.yml +++ b/permissions/controlled_datasets.yml @@ -1,2 +1,5 @@ -controlled_datasets: +app-user3: +- CINECA_synthetic_cohort_EUROPE_UK1 +- AV_Dataset +hola: - CINECA_synthetic_cohort_EUROPE_UK1 diff --git a/permissions/permissions-ui/bash/urls.py b/permissions/permissions-ui/bash/urls.py index b50e254d..8930a8b2 100644 --- a/permissions/permissions-ui/bash/urls.py +++ b/permissions/permissions-ui/bash/urls.py @@ -6,6 +6,6 @@ urlpatterns = [ path('', views.bash_view, name='index'), path('public', views.public_view, name='public'), - path('controlled', views.controlled_view, name='controlled'), - path('registered', views.registered_view, name='registered') + path('registered', views.registered_view, name='registered'), + path('controlled', views.controlled_view, name='controlled') ] \ No newline at end of file diff --git a/permissions/permissions-ui/bash/views.py b/permissions/permissions-ui/bash/views.py index 7d2d196f..3da48c0b 100644 --- a/permissions/permissions-ui/bash/views.py +++ b/permissions/permissions-ui/bash/views.py @@ -42,27 +42,26 @@ def add_public_datasets(list_datasets): yaml.dump(public_datasets, pfile) pfile.close -def add_controlled_datasets(list_datasets): - with open("../beacon/permissions/controlled_datasets.yml", 'r') as pfile: - controlled_datasets = yaml.safe_load(pfile) +def add_registered_datasets(list_datasets): + with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: + registered_datasets = yaml.safe_load(pfile) pfile.close - controlled_datasets['controlled_datasets']=list_datasets - with open("../beacon/permissions/controlled_datasets.yml", 'w') as pfile: - yaml.dump(controlled_datasets, pfile) + registered_datasets['registered_datasets']=list_datasets + with open("../beacon/permissions/registered_datasets.yml", 'w') as pfile: + yaml.dump(registered_datasets, pfile) pfile.close -def add_registered_datasets(list_users, list_datasets): - with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: - registered_datasets = yaml.safe_load(pfile) +def add_controlled_datasets(list_users, list_datasets): + with open("../beacon/permissions/controlled_datasets.yml", 'r') as pfile: + controlled_datasets = yaml.safe_load(pfile) pfile.close for user in list_users: - print(user) - registered_datasets[user]=[] + controlled_datasets[user]=[] for dataset in list_datasets: - if dataset not in registered_datasets[user]: - registered_datasets[user].append(dataset) - with open("../beacon/permissions/registered_datasets.yml", 'w') as pfile: - yaml.dump(registered_datasets, pfile) + if dataset not in controlled_datasets[user]: + controlled_datasets[user].append(dataset) + with open("../beacon/permissions/controlled_datasets.yml", 'w') as pfile: + yaml.dump(controlled_datasets, pfile) pfile.close def load_datasets(): @@ -84,39 +83,39 @@ def load_public_datasets(): return list_of_public_datasets -def load_controlled_datasets(): - with open("../beacon/permissions/controlled_datasets.yml", 'r') as pfile: - controlled_datasets = yaml.safe_load(pfile) +def load_registered_datasets(): + with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: + registered_datasets = yaml.safe_load(pfile) pfile.close() - list_of_controlled_datasets = controlled_datasets['controlled_datasets'] + list_of_registered_datasets = registered_datasets['registered_datasets'] - return list_of_controlled_datasets + return list_of_registered_datasets def load_users(): - with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: - registered_datasets = yaml.safe_load(pfile) + with open("../beacon/permissions/controlled_datasets.yml", 'r') as pfile: + controlled_datasets = yaml.safe_load(pfile) pfile.close() list_users=[] - for k, v in registered_datasets.items(): + for k, v in controlled_datasets.items(): list_users.append(k) return list_users -def load_registered_datasets(user): - with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: - registered_datasets = yaml.safe_load(pfile) +def load_controlled_datasets(user): + with open("../beacon/permissions/controlled_datasets.yml", 'r') as pfile: + controlled_datasets = yaml.safe_load(pfile) pfile.close() - list_registered_datasets=[] + list_controlled_datasets=[] - for k, v in registered_datasets.items(): + for k, v in controlled_datasets.items(): if k == user: - list_registered_datasets = v + list_controlled_datasets = v - return list_registered_datasets + return list_controlled_datasets @@ -130,10 +129,10 @@ def bash_view(request): reference = form.cleaned_data['Datasets'] if reference == 'PUBLIC': return redirect("bash:public") - elif reference == 'CONTROLLED': - return redirect("bash:controlled") elif reference == 'REGISTERED': return redirect("bash:registered") + elif reference == 'CONTROLLED': + return redirect("bash:controlled") return render(request, template, context) def public_view(request): @@ -143,7 +142,6 @@ def public_view(request): context={'bash_out': bash_out, 'datasets': datasets} if request.method == 'POST': answer = request.POST.getlist('list', False) - print(answer) add_public_datasets(answer) context = { 'answer': answer, @@ -151,31 +149,30 @@ def public_view(request): return redirect("bash:index") return render(request, template, context) -def controlled_view(request): - template = "controlled.html" +def registered_view(request): + template = "registered.html" datasets=load_datasets() - bash_out=load_controlled_datasets() + bash_out=load_registered_datasets() context={'bash_out': bash_out, 'datasets': datasets} if request.method == 'POST': answer = request.POST.getlist('list', False) - print(answer) - add_controlled_datasets(answer) + add_registered_datasets(answer) context = { 'answer': answer, } return redirect("bash:index") return render(request, template, context) -def registered_view(request): - template = "registered.html" +def controlled_view(request): + template = "controlled.html" bash_out=load_users() datasets=load_datasets() context={} if request.method == 'GET': users = request.GET.getlist('userslist', False) if users != False: - registered_datasets = load_registered_datasets(users[0]) - context={'bash_out': bash_out, 'datasets': datasets, 'users': users, 'registered_datasets': registered_datasets} + controlled_datasets = load_controlled_datasets(users[0]) + context={'bash_out': bash_out, 'datasets': datasets, 'users': users, 'controlled_datasets': controlled_datasets} else: context={'bash_out': bash_out, 'datasets': datasets, 'users': users} @@ -185,7 +182,7 @@ def registered_view(request): if request.method == 'POST': user = request.POST.getlist('users', False) datasets_list = request.POST.getlist('list', False) - add_registered_datasets(user, datasets_list) + add_controlled_datasets(user, datasets_list) context = { 'answer': user, 'datasets_list': datasets_list } diff --git a/permissions/permissions-ui/templates/controlled.html b/permissions/permissions-ui/templates/controlled.html index c3b3d088..f5c53db9 100644 --- a/permissions/permissions-ui/templates/controlled.html +++ b/permissions/permissions-ui/templates/controlled.html @@ -48,6 +48,7 @@

Back +
@@ -74,23 +75,51 @@

Controlled datasets manager

-
- {% csrf_token %} + {% if not users %} + +
+ + + + +
- + + +
+
+ +
+ +
+ {% else %} + {% for user in users %} +
+ {% csrf_token %} + + + - -
+ +
- +
+
- +
- + {% endfor %} + {% endif %} + @@ -157,6 +188,7 @@

Controlled datasets manager

} + diff --git a/permissions/permissions-ui/templates/registered.html b/permissions/permissions-ui/templates/registered.html index 6fc531f1..a0696def 100644 --- a/permissions/permissions-ui/templates/registered.html +++ b/permissions/permissions-ui/templates/registered.html @@ -48,7 +48,6 @@

Back -
@@ -75,52 +74,23 @@

Registered datasets manager

- {% if not users %} -
+ {% csrf_token %}
- - - - -
-
- - -
-
- -
- -
- {% else %} - {% for user in users %} -
- {% csrf_token %} - - - + - - -
+
- +
+
- +
- {% endfor %} - {% endif %} -
+
@@ -189,7 +157,6 @@

Registered datasets manager

} - diff --git a/permissions/permissions-ui/web/forms.py b/permissions/permissions-ui/web/forms.py index dac201fe..ba834b7f 100644 --- a/permissions/permissions-ui/web/forms.py +++ b/permissions/permissions-ui/web/forms.py @@ -1,5 +1,5 @@ from django import forms class BamForm(forms.Form): - choices = [("PUBLIC", "PUBLIC"), ("CONTROLLED", "CONTROLLED"), ("REGISTERED", "REGISTERED")] + choices = [("PUBLIC", "PUBLIC"), ("REGISTERED", "REGISTERED"), ("CONTROLLED", "CONTROLLED")] Datasets = forms.ChoiceField(choices=choices, help_text="Datasets type:", label="") diff --git a/permissions/public_datasets.yml b/permissions/public_datasets.yml index e27c4f7b..1be88c54 100644 --- a/permissions/public_datasets.yml +++ b/permissions/public_datasets.yml @@ -1,2 +1 @@ -public_datasets: -- AV_Dataset +public_datasets: false diff --git a/permissions/registered_datasets.yml b/permissions/registered_datasets.yml index 44dbdafd..a3c72737 100644 --- a/permissions/registered_datasets.yml +++ b/permissions/registered_datasets.yml @@ -1,6 +1,3 @@ -app-user3: -- CINECA_synthetic_cohort_EUROPE_UK1 -- AV_Dataset -hola: +registered_datasets: - CINECA_synthetic_cohort_EUROPE_UK1 - AV_Dataset