diff --git a/beacon/conf.py b/beacon/conf.py index 7e7a5dd2..7d1eda19 100644 --- a/beacon/conf.py +++ b/beacon/conf.py @@ -78,7 +78,7 @@ # # Database connection # -database_host = '127.0.0.1' +database_host = 'mongo' database_port = 27017 database_user = 'root' database_password = 'example' diff --git a/permissions/permissions-ui/bash/views.py b/permissions/permissions-ui/bash/views.py index 11e5f905..7d2d196f 100644 --- a/permissions/permissions-ui/bash/views.py +++ b/permissions/permissions-ui/bash/views.py @@ -5,13 +5,34 @@ import time from django.http import HttpResponseRedirect, HttpResponseBadRequest import logging - import json import yaml +from pymongo.mongo_client import MongoClient +import imp +from django.urls import resolve + +# load a source module from a file +file, pathname, description = imp.find_module('beacon', ['']) +my_module = imp.load_module('beacon', file, pathname, description) + +from beacon import conf + +client = MongoClient( + "mongodb://{}:{}@{}:{}/{}?authSource={}".format( + conf.database_user, + conf.database_password, + conf.database_host, + conf.database_port, + conf.database_name, + conf.database_auth_source, + ) + ) -LOG = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) + def add_public_datasets(list_datasets): with open("../beacon/permissions/public_datasets.yml", 'r') as pfile: public_datasets = yaml.safe_load(pfile) @@ -35,6 +56,7 @@ def add_registered_datasets(list_users, list_datasets): registered_datasets = yaml.safe_load(pfile) pfile.close for user in list_users: + print(user) registered_datasets[user]=[] for dataset in list_datasets: if dataset not in registered_datasets[user]: @@ -43,6 +65,16 @@ def add_registered_datasets(list_users, list_datasets): yaml.dump(registered_datasets, pfile) pfile.close +def load_datasets(): + results = client.beacon.get_collection('datasets').find({}, {"id": 1}) + results = list(results) + list_of_datasets=[] + for object in results: + for k,v in object.items(): + if k == 'id': + list_of_datasets.append(v) + return list_of_datasets + def load_public_datasets(): with open("../beacon/permissions/public_datasets.yml", 'r') as pfile: public_datasets = yaml.safe_load(pfile) @@ -73,12 +105,19 @@ def load_users(): return list_users -def load_registered_datasets(): - with open("../beacon/permissions/public_datasets.yml", 'r') as pfile: +def load_registered_datasets(user): + with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile: registered_datasets = yaml.safe_load(pfile) pfile.close() - return registered_datasets + list_registered_datasets=[] + + for k, v in registered_datasets.items(): + if k == user: + list_registered_datasets = v + + return list_registered_datasets + def bash_view(request): @@ -99,8 +138,9 @@ def bash_view(request): def public_view(request): template = "public.html" + datasets=load_datasets() bash_out=load_public_datasets() - context={'bash_out': bash_out} + context={'bash_out': bash_out, 'datasets': datasets} if request.method == 'POST': answer = request.POST.getlist('list', False) print(answer) @@ -113,8 +153,9 @@ def public_view(request): def controlled_view(request): template = "controlled.html" + datasets=load_datasets() bash_out=load_controlled_datasets() - context={'bash_out': bash_out} + context={'bash_out': bash_out, 'datasets': datasets} if request.method == 'POST': answer = request.POST.getlist('list', False) print(answer) @@ -128,14 +169,25 @@ def controlled_view(request): def registered_view(request): template = "registered.html" bash_out=load_users() - registered_datasets=load_registered_datasets() - context={'bash_out': bash_out, 'registered_datasets': registered_datasets['public_datasets']} + 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} + else: + context={'bash_out': bash_out, 'datasets': datasets, 'users': users} + + return render(request, template, context) + + if request.method == 'POST': - answer = request.POST.getlist('list', False) - datasets_list = request.POST.getlist('list_datasets', False) - add_registered_datasets(answer, datasets_list) + user = request.POST.getlist('users', False) + datasets_list = request.POST.getlist('list', False) + add_registered_datasets(user, datasets_list) context = { - 'answer': answer, 'datasets_list': datasets_list + 'answer': user, 'datasets_list': datasets_list } return redirect("bash:index") return render(request, template, context) \ No newline at end of file diff --git a/permissions/permissions-ui/media/app.js b/permissions/permissions-ui/media/app.js index bd497e44..5b2f935a 100644 --- a/permissions/permissions-ui/media/app.js +++ b/permissions/permissions-ui/media/app.js @@ -1,6 +1,5 @@ const btnAdd = document.querySelector('#btnAdd'); -const btnRemove = document.querySelector('#btnRemove'); -const listbox = document.querySelector('#list'); +const listbox = document.querySelector('#userslist'); const framework = document.querySelector('#framework'); btnAdd.onclick = (e) => { @@ -22,23 +21,3 @@ btnAdd.onclick = (e) => { framework.value = ''; framework.focus(); }; - -// remove selected option -btnRemove.onclick = (e) => { - e.preventDefault(); - - // save the selected options - let selected = []; - - for (let i = 0; i < listbox.options.length; i++) { - selected[i] = listbox.options[i].selected; - } - - // remove all selected option - let index = listbox.options.length; - while (index--) { - if (selected[index]) { - listbox.remove(index); - } - } -}; \ No newline at end of file diff --git a/permissions/permissions-ui/media/app2.js b/permissions/permissions-ui/media/app2.js index 90dcf34d..add83fe1 100644 --- a/permissions/permissions-ui/media/app2.js +++ b/permissions/permissions-ui/media/app2.js @@ -1,7 +1,7 @@ const btnAdd2 = document.querySelector('#btnAdd2'); const btnRemove = document.querySelector('#btnRemove'); const datasets = document.querySelector('#datasets'); -const listbox = document.querySelector('#list'); +const listbox2 = document.querySelector('#list'); btnAdd2.onclick = (e) => { e.preventDefault(); @@ -18,10 +18,12 @@ btnAdd2.onclick = (e) => { for (let i = 0; i < selected.length; i++) { console.log(selected[i]) + if (!selected[i] == false){ const option = new Option(selected[i], selected[i]); option.setAttribute('selected', 'selected'); // add it to the list - listbox.add(option, undefined); + listbox2.add(option, undefined); + } } // create a new option @@ -36,15 +38,15 @@ btnRemove.onclick = (e) => { // save the selected options let selected = []; - for (let i = 0; i < listbox.options.length; i++) { - selected[i] = listbox.options[i].selected; + for (let i = 0; i < listbox2.options.length; i++) { + selected[i] = listbox2.options[i].selected; } // remove all selected option - let index = listbox.options.length; + let index = listbox2.options.length; while (index--) { if (selected[index]) { - listbox.remove(index); + listbox2.remove(index); } } }; \ No newline at end of file diff --git a/permissions/permissions-ui/templates/controlled.html b/permissions/permissions-ui/templates/controlled.html index 3d16fff6..ab505cdf 100644 --- a/permissions/permissions-ui/templates/controlled.html +++ b/permissions/permissions-ui/templates/controlled.html @@ -67,6 +67,7 @@

Controlled datasets manager

{% csrf_token %} +
- + {% for dataset in datasets %} + + {% endfor %} diff --git a/permissions/permissions-ui/templates/registered.html b/permissions/permissions-ui/templates/registered.html index 6edd0f26..ba570b9f 100644 --- a/permissions/permissions-ui/templates/registered.html +++ b/permissions/permissions-ui/templates/registered.html @@ -62,46 +62,77 @@

+

Registered datasets manager

+ {% if not users %} +

Registered datasets manager

+ + {% csrf_token %}
+
- - + {% for item in bash_out %} {% endfor %} - + + + + + +
+ +
+ + {% else %} + {% for user in users %} +
+ {% csrf_token %} + + + +
- - + + +
-
- -
+
+ +
-

- - - - + {% endfor %} + {% endif %} + + @@ -154,6 +185,7 @@

Registered datasets manager

+ \ No newline at end of file diff --git a/permissions/permissions-ui/web/forms.py b/permissions/permissions-ui/web/forms.py index ba834b7f..aff983ed 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"), ("REGISTERED", "REGISTERED"), ("CONTROLLED", "CONTROLLED")] + choices = [("PUBLIC", "PUBLIC"), ("CONTROLLED", "CONTROLLED"), ("REGISTERED", "REGISTERED")] Datasets = forms.ChoiceField(choices=choices, help_text="Datasets type:", label="") diff --git a/permissions/public_datasets.yml b/permissions/public_datasets.yml index 2f3c35df..d40a005b 100644 --- a/permissions/public_datasets.yml +++ b/permissions/public_datasets.yml @@ -1,3 +1,2 @@ public_datasets: - CINECA_synthetic_cohort_EUROPE_UK1 -- dataset1 diff --git a/permissions/registered_datasets.yml b/permissions/registered_datasets.yml index ad7bf4d2..73511f75 100644 --- a/permissions/registered_datasets.yml +++ b/permissions/registered_datasets.yml @@ -1,4 +1,7 @@ app-user3: - CINECA_synthetic_cohort_EUROPE_UK1 +gemma: +- CINECA_synthetic_cohort_EUROPE_UK1 +- AV_Dataset hola: - CINECA_synthetic_cohort_EUROPE_UK1