Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #192,#176, #138,#154 #195

Merged
merged 4 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 47 additions & 23 deletions model_validation_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import math
import json
import logging
import time
from urlparse import urlparse, parse_qs
from datetime import date
from django.shortcuts import render
Expand All @@ -25,9 +26,10 @@
HttpResponseNotAllowed, # 405
HttpResponseNotModified, # 304
HttpResponseRedirect) # 302
from django.db.models import Max, Count
from django.db.models import Max, Count, CASCADE
from django.conf import settings
from django.template import loader
from django.db import connection
import requests
from hbp_app_python_auth.auth import get_access_token, get_auth_header

Expand Down Expand Up @@ -190,29 +192,29 @@ def get(self, request, format=None, **kwargs):

serializer_context = {'request': request,}

data_modalities = Param_DataModalities.objects.all()
data_modalities = Param_DataModalities.objects.all().order_by('authorized_value')
data_modalities_serializer = Param_DataModalitiesSerializer(data_modalities, context=serializer_context, many=True)

test_type = Param_TestType.objects.all()
test_type = Param_TestType.objects.all().order_by('authorized_value')
test_type_serializer = Param_TestTypeSerializer(test_type, context=serializer_context, many=True)

species = Param_Species.objects.all()
species = Param_Species.objects.all().order_by('authorized_value')
species_serializer = Param_SpeciesSerializer(species, context=serializer_context, many=True)

brain_region = Param_BrainRegion.objects.all()
brain_region = Param_BrainRegion.objects.all().order_by('authorized_value')
brain_region_serializer = Param_BrainRegionSerializer(brain_region, context=serializer_context, many=True)

cell_type = Param_CellType.objects.all()
cell_type = Param_CellType.objects.all().order_by('authorized_value')
cell_type_serializer = Param_CellTypeSerializer(cell_type, context=serializer_context, many=True)

model_type = Param_ModelType.objects.all()
model_type_serializer = Param_ModelTypeSerializer(model_type, context=serializer_context, many=True)
model_type = Param_ModelType.objects.all().order_by('authorized_value')
model_type_serializer = Param_ModelTypeSerializer(model_type, context=serializer_context, many=True)

score_type = Param_ScoreType.objects.all()
score_type = Param_ScoreType.objects.all().order_by('authorized_value')
score_type_serializer = Param_ScoreTypeSerializer(score_type, context=serializer_context, many=True)

organization = Param_organizations.objects.all()
organization_serializer = Param_OrganizationsSerializer(organization, context=serializer_context, many=True)
organization = Param_organizations.objects.all().order_by('authorized_value')
organization_serializer = Param_OrganizationsSerializer(organization, context=serializer_context, many=True)

##for python client #'python_client=True' 'parameters= list()'
if python_client == 'true':
Expand Down Expand Up @@ -245,7 +247,7 @@ def get(self, request, format=None, **kwargs):
if (param == 'test_type'):
res['test_type'] = test_type.values_list('authorized_value', flat=True)
if (param == 'brain_region'):
res['brain_region'] = brain_region.values_list('authorized_value', flat=True)
res['brain_region'] = brain_region.values_list('authorized_value', flat=True)
if (param == 'cell_type'):
res['cell_type'] = cell_type.values_list('authorized_value', flat=True)
if (param == 'model_type'):
Expand Down Expand Up @@ -901,34 +903,47 @@ def get(self, request, format=None, **kwargs):
serializer_context = {
'request': request,
}

id = request.GET.getlist('id')
# time_spent=time.time()
# id = request.GET.getlist('id')
if check_list_uuid_validity(id) is False :
return Response("Badly formed uuid in : id", status=status.HTTP_400_BAD_REQUEST)


#if model id not specifiedorresponding to this alias.
if(len(id) == 0):


# print("after going in first loop :", time.time()-time_spent)
# time_spent=time.time()
web_app = request.GET.getlist('web_app')


#if the request comes from the webapp : uses collab_parameters
if len(web_app) > 0 and web_app[0] == 'True' :


# print("after going in first if :", time.time()-time_spent)
# time_spent=time.time()
app_id = request.GET.getlist('app_id')[0]
# print("after getting app_id:", time.time()-time_spent)
# time_spent=time.time()
collab_id = get_collab_id_from_app_id(app_id)

# print("after getting collab_id :", time.time()-time_spent)
# time_spent=time.time()
collab_params = CollabParameters.objects.get(id = app_id )

collab_ids = list(CollabParameters.objects.all().values_list('collab_id', flat=True).distinct())
# print("after getting collab_ids_list :", time.time()-time_spent)
# collab_ids = ["2180"] #######don't forget to erase it!!!!
# time_spent=time.time()
collab_ids_new = []
for collab in collab_ids:
if is_authorised(request, collab):
collab_ids_new.append(collab)

# print("after checking permissions :", time.time()-time_spent)
# time_spent=time.time()
all_ctx_from_collab = CollabParameters.objects.filter(collab_id__in=collab_ids_new).distinct()


# print("after getting all ctx :", time.time()-time_spent)
# time_spent=time.time()
#if one of the collab_param is empty, don't filter on it.
species_filter = collab_params.species.split(",")
if species_filter==[u'']:
Expand Down Expand Up @@ -958,8 +973,9 @@ def get(self, request, format=None, **kwargs):
if organization_filter==[u'']:
organization_filter = list(Param_organizations.objects.all().values_list('authorized_value', flat=True)) #+[u'']




# print("after filtering with config :", time.time()-time_spent)
# time_spent=time.time()
rq1 = ScientificModel.objects.filter(
private=1,
app__in=all_ctx_from_collab.values("id"),
Expand All @@ -981,8 +997,13 @@ def get(self, request, format=None, **kwargs):
models = (rq1 | rq2).distinct().order_by('-creation_date')
else:
models = rq2.distinct().order_by('-creation_date')

model_serializer = ScientificModelReadOnlyForHomeSerializer(models, context=serializer_context, many=True )

# print("after getting queries :", time.time()-time_spent)
# print("get models requests:")
# for query in connection.queries:
# print(query)
return Response({
'models': model_serializer.data,
})
Expand Down Expand Up @@ -1104,6 +1125,7 @@ def post(self, request, format=None):

collab_id = get_collab_id_from_app_id(app_id)
if not is_authorised(request, collab_id):
return HttpResponse('Unauthorized', status=401)
return HttpResponseForbidden()

serializer_context = {'request': request,}
Expand Down Expand Up @@ -1198,9 +1220,11 @@ def put(self, request, format=None):
app_id = model.app_id
collab_id = get_collab_id_from_app_id(app_id)
if not is_authorised(request, collab_id):
return HttpResponse('Unauthorized', status=401)
return HttpResponseForbidden()

app_id = value['app_id']

collab_id = get_collab_id_from_app_id(app_id)
if not is_authorised(request, collab_id):
return HttpResponseForbidden()
Expand All @@ -1221,7 +1245,7 @@ def put(self, request, format=None):
if model_serializer.is_valid() :
check_param = check_param_of_model_json(value)
if check_param is True :
model = model_serializer.save()
model = model_serializer.save(app_id=app_id)
else :
return Response(check_param, status=status.HTTP_400_BAD_REQUEST)

Expand Down
17 changes: 17 additions & 0 deletions validation_service/app/css/Model_catalog.css
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,24 @@
overflow: auto;
}

.permissions-panel {
/*height:10px;
width: 320px;*/
padding: 5px;
border: 2px solid #dfe7ef;
float: right;
margin-right: 7%;
margin-left: 2%;
margin-bottom: 1%;
margin-top: 1%;
overflow: auto;
}

.text-justify {
text-align: justify;
text-justify: inter-word;
}

.text-centered {
text-align: center;
}
10 changes: 9 additions & 1 deletion validation_service/app/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ ParametersConfigurationServices.service('CollabParameters', ['$rootScope', 'Coll
var param = getParametersByType(type);

if (param.length > 0) {
param = _move_element_at_the_end_of_array("Other", param)
return param;
} else {
return default_parameters[type];
param = _move_element_at_the_end_of_array("Other", default_parameters[type])
return param;
}
};

Expand Down Expand Up @@ -662,6 +664,12 @@ ParametersConfigurationServices.service('CollabParameters', ['$rootScope', 'Coll
parameters.param[0]['organization'] = string_tab[6];
};

var _move_element_at_the_end_of_array = function(elem, array) {
array.splice(array.indexOf(elem), 1)
array.push(elem)
return array;
}

var setService = function(ctx_param) {
return new Promise(function(resolve, reject) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,48 @@
<body>
<br>
<nav class="navbar ">

<panel id="panel-permissions" class=permissions-panel>
<table class="table-create text-centered">
<thead>
<th>
<div align=center> Permissions </div>
</th>
</thead>
<tbody>
<tr>
<td>
<div ng-if="is_collab_member == true"> Read and Write</div>
<div ng-if="is_collab_member == false"> Read only</div>
</td>
</tr>
</tbody>
</table>
</panel>

<h1 align=center> {{ model.models[0].name}}
</h1>
<h3 ng-if="model.models[0].owner && model.models[0].owner!=''" align=center> Owner: {{ model.models[0].owner }} </h3>
<h3 align=center> Author(s): {{ model.models[0].author }} </h3>

</nav>
<nav>

<button class="button-MC" ng-click="Context.modelCatalog_goToHomeView();">Home</button>&ensp;

<a ng-href="#/model-catalog/edit/{{model.models[0].id}}" ng-if="is_collab_member == true" class="button-MC">Edit</a>&ensp;
<a ng-href="#/model-catalog/version/{{model.models[0].id}}" class="button-MC">New version</a>&ensp;

</nav>
<br>
<br>

<br>
<h4 style="margin-left:33%"> <b>Model Description</b> </h4>
<br>



<panel class=caracteristics-panel>
<h4 align=center> <b> Model information </b></h4>
<br>
Expand Down
Loading