Skip to content

Commit

Permalink
changing controlled for registered
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Nov 8, 2023
1 parent 8c03e2e commit 8ac158e
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 108 deletions.
2 changes: 1 addition & 1 deletion deploy/data/individuals_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id" : "NCIT:C42331",
"label" : "African"
},
"id" : "HG00096",
"id" : "AV0101",
"info" : {
"eid" : "fake1"
},
Expand Down
5 changes: 4 additions & 1 deletion permissions/controlled_datasets.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
controlled_datasets:
app-user3:
- CINECA_synthetic_cohort_EUROPE_UK1
- AV_Dataset
hola:
- CINECA_synthetic_cohort_EUROPE_UK1
4 changes: 2 additions & 2 deletions permissions/permissions-ui/bash/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
83 changes: 40 additions & 43 deletions permissions/permissions-ui/bash/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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



Expand All @@ -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):
Expand All @@ -143,39 +142,37 @@ 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,
}
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}

Expand All @@ -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
}
Expand Down
54 changes: 43 additions & 11 deletions permissions/permissions-ui/templates/controlled.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1 class="bi bi-kanban display-6 mx-auto p-2 fw-bold ms-5" style="color: #76050

<a class="text" href="/">Back</a>
</button>

<div class="container pt-3 " style="font-size: 14px; ">
<div class="col">
<div class="containerfirst">
Expand All @@ -74,34 +75,64 @@ <h1 class="bi bi-kanban display-6 mx-auto p-2 fw-bold ms-5" style="color: #76050
<div class="second-tittle">
<h2 style="color: #760509;">Controlled datasets manager</h2>
</div>
<form class="form-datasets" method="post">
{% csrf_token %}
{% if not users %}
<form class="form-datasets" method="get">
<div class="divPublicForm">
<label for="framework">Add a new user to the list:</label>
<input type="text" id="framework" placeholder="Enter a new user" autocomplete="off">

<button id="btnAdd"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
</div>
<div class="divPublicForm">
<label for="datasets">Dataset:</label>
<label for="userslist">Select one user from the list:</label>
<select id="userslist" name="userslist" size="3">
{% for item in bash_out %}
<option value="{{item}}" selected="selected">{{item}}</option>
{% endfor %}
</select>
</div>
<div class="col-5">
<button type="submit" class="btn btn-success mb-3">Add dataset to user(s) permissions</button>
</div>

</form>
{% else %}
{% for user in users %}
<form method="post">
{% csrf_token %}
<label for="users">User:</label>
<select id="users" name="users" multiple>
<option value="{{user}}" selected="selected">{{user}}</option>
</select>
<label for="datasets">Datasets:</label>
<select id="datasets" name="datasets" multiple>
{% for dataset in datasets %}
<option value="{{dataset}}" selected="selected">{{dataset}}</option>
{% endfor %}
</select>
<button id="btnAdd2"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
</div>

<button id="btnAdd2"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
<div class="divPublicForm">
<label for="list">Public Datasets List:</label>
</div>
<label for="list">{{user}} Datasets List:</label>
<select id="list" name="list" multiple>
{% for item in bash_out %}
<option value="{{item}}" selected="selected">{{item}}</option>
{% for rdataset in controlled_datasets %}
<option value="{{rdataset}}" selected="selected">{{rdataset}}</option>
{% endfor %}
</select>
<button id="btnRemove"><img class="deleteIcon" src="media/delete.png" alt="deleteIcon" height="20px">
<img class="deleteIconHover" src="media/delete-hover.png" alt="deleteIconHover"
height="23px"></button>
</div>
<div class="col-5">
<button type="submit" class="btn btn-success mb-3">Add datasets</button>
<button type="submit" class="btn btn-success mb-3">Add datasets to user {{user}}</button>
</div>
</form>
</div>
{% endfor %}
{% endif %}
</div>



Expand Down Expand Up @@ -157,6 +188,7 @@ <h2 style="color: #760509;">Controlled datasets manager</h2>
}

</script>
<script src="media/app.js"></script>
<script src="media/app2.js"></script>
</body>

Expand Down
53 changes: 10 additions & 43 deletions permissions/permissions-ui/templates/registered.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ <h1 class="bi bi-kanban display-6 mx-auto p-2 fw-bold ms-5" style="color: #76050

<a class="text" href="/">Back</a>
</button>

<div class="container pt-3 " style="font-size: 14px; ">
<div class="col">
<div class="containerfirst">
Expand All @@ -75,65 +74,34 @@ <h1 class="bi bi-kanban display-6 mx-auto p-2 fw-bold ms-5" style="color: #76050
<div class="second-tittle">
<h2 style="color: #760509;">Registered datasets manager</h2>
</div>
{% if not users %}
<form class="form-datasets" method="get">
<form class="form-datasets" method="post">
{% csrf_token %}
<div class="divPublicForm">
<label for="framework">Add a new user to the list:</label>
<input type="text" id="framework" placeholder="Enter a new user" autocomplete="off">

<button id="btnAdd"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
</div>
<div class="divPublicForm">
<label for="userslist">Select one user from the list:</label>
<select id="userslist" name="userslist" size="3">
{% for item in bash_out %}
<option value="{{item}}" selected="selected">{{item}}</option>
{% endfor %}
</select>
</div>
<div class="col-5">
<button type="submit" class="btn btn-success mb-3">Add dataset to user(s) permissions</button>
</div>

</form>
{% else %}
{% for user in users %}
<form method="post">
{% csrf_token %}
<label for="users">User:</label>
<select id="users" name="users" multiple>
<option value="{{user}}" selected="selected">{{user}}</option>
</select>
<label for="datasets">Datasets:</label>
<label for="datasets">Dataset:</label>
<select id="datasets" name="datasets" multiple>
{% for dataset in datasets %}
<option value="{{dataset}}" selected="selected">{{dataset}}</option>
{% endfor %}
</select>

<button id="btnAdd2"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
<div class="divPublicForm">
<button id="btnAdd2"><img class="plusIcon" src="media/plus.png" alt="plusIcon" height="22px">
<img class="plusIconHover" src="media/plus-hover.png" alt="plusIconHover" height="22px"></button>
</div>
<label for="list">{{user}} Datasets List:</label>
<div class="divPublicForm">
<label for="list">Public Datasets List:</label>
<select id="list" name="list" multiple>
{% for rdataset in registered_datasets %}
<option value="{{rdataset}}" selected="selected">{{rdataset}}</option>
{% for item in bash_out %}
<option value="{{item}}" selected="selected">{{item}}</option>
{% endfor %}
</select>
<button id="btnRemove"><img class="deleteIcon" src="media/delete.png" alt="deleteIcon" height="20px">
<img class="deleteIconHover" src="media/delete-hover.png" alt="deleteIconHover"
height="23px"></button>
</div>
<div class="col-5">
<button type="submit" class="btn btn-success mb-3">Add datasets to user {{user}}</button>
<button type="submit" class="btn btn-success mb-3">Add datasets</button>
</div>
</form>
{% endfor %}
{% endif %}
</div>
</div>



Expand Down Expand Up @@ -189,7 +157,6 @@ <h2 style="color: #760509;">Registered datasets manager</h2>
}

</script>
<script src="media/app.js"></script>
<script src="media/app2.js"></script>
</body>

Expand Down
2 changes: 1 addition & 1 deletion permissions/permissions-ui/web/forms.py
Original file line number Diff line number Diff line change
@@ -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="<span class='hovertext' data-hover='Choose what type of datasets you want to manage'>Datasets type:</span>", label="")
3 changes: 1 addition & 2 deletions permissions/public_datasets.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
public_datasets:
- AV_Dataset
public_datasets: false
5 changes: 1 addition & 4 deletions permissions/registered_datasets.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
app-user3:
- CINECA_synthetic_cohort_EUROPE_UK1
- AV_Dataset
hola:
registered_datasets:
- CINECA_synthetic_cohort_EUROPE_UK1
- AV_Dataset

0 comments on commit 8ac158e

Please sign in to comment.