Skip to content

Commit e58f1a1

Browse files
authored
Merge pull request #203 from HFragnaud/master
#201, #168
2 parents 53256e8 + f7f3b43 commit e58f1a1

File tree

17 files changed

+197
-86
lines changed

17 files changed

+197
-86
lines changed

model_validation_api/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
IsCollabMemberRest,
2424
Results,
2525
CollabAppID,
26-
26+
IsSuperUserRest,
2727
)
2828

2929
# from django.contrib.auth.decorators import login_required
@@ -45,6 +45,10 @@
4545
url(r'^appidrest/$',
4646
AppIDRest.as_view(),
4747
),
48+
url(r'^issuperuser/$',
49+
IsSuperUserRest.as_view(),
50+
),
51+
4852
# url(r'^notificationrest/$',
4953
# NotificationRest.as_view(),
5054
# ),

model_validation_api/validation_framework_toolbox/user_auth_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
stream_handler.setLevel(logging.DEBUG)
1919
logger.addHandler(stream_handler)
2020

21-
21+
admin_id='13947'
2222

2323

2424
def get_authorization_header(request):
@@ -217,11 +217,12 @@ def is_authorised(request, collab_id):
217217
if request.META.get("HTTP_AUTHORIZATION", None) == None :
218218
return False
219219
else:
220-
221-
return _is_collaborator_token(request, collab_id)
220+
auth = _is_collaborator_token(request, collab_id)
221+
auth = _is_collaborator_token(request, admin_id)
222+
return auth
222223

223224
else :
224-
if not _is_collaborator(request, collab_id):
225+
if not (_is_collaborator(request, collab_id) or _is_collaborator(request,admin_id)):
225226
return False
226227
else:
227228
return True

model_validation_api/views.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,12 @@ def put(self, request, format=None):
618618

619619
if param_web_app==True:
620620
original_instance = ScientificModelInstance.objects.get(id=instance.get('id'))
621-
#check if version is editable
622-
if not _are_model_instance_editable(instance):
623-
return Response("This version is no longer editable as there is at least one result associated with it.", status=status.HTTP_400_BAD_REQUEST)
624-
621+
#check if version is editable - only if you are not super user
622+
if not is_authorised(request,settings.ADMIN_COLLAB_ID):
623+
if not _are_model_instance_editable(instance):
624+
return Response("This version is no longer editable as there is at least one result associated with it.", status=status.HTTP_400_BAD_REQUEST)
625+
626+
625627
#check if versions are unique
626628
if not _are_model_instance_version_unique(instance) :
627629
return Response("Oh no... The specified version name already exists for this model. Please, give me a new name", status=status.HTTP_400_BAD_REQUEST)
@@ -669,8 +671,9 @@ def put(self, request, format=None):
669671
return HttpResponseForbidden()
670672

671673
#check if version is editable
672-
if not _are_model_instance_editable(instance):
673-
return Response("This version is no longer editable as there is at least one result associated with it.", status=status.HTTP_400_BAD_REQUEST)
674+
if not is_authorised(request, settings.ADMIN_COLLAB_ID):
675+
if not _are_model_instance_editable(instance):
676+
return Response("This version is no longer editable as there is at least one result associated with it.", status=status.HTTP_400_BAD_REQUEST)
674677

675678
#check if versions are unique
676679
if not _are_model_instance_version_unique(instance) :
@@ -925,16 +928,7 @@ def get(self, request, format=None, **kwargs):
925928

926929
collab_params = CollabParameters.objects.get(id = app_id )
927930

928-
collab_ids = list(CollabParameters.objects.all().values_list('collab_id', flat=True).distinct())
929-
930-
collab_ids_new = []
931-
for collab in collab_ids:
932-
if is_authorised(request, collab):
933-
collab_ids_new.append(collab)
934-
935-
all_ctx_from_collab = CollabParameters.objects.filter(collab_id__in=collab_ids_new).distinct()
936-
937-
931+
938932
species_filter = collab_params.species.split(",")
939933
if species_filter==[u'']:
940934
species_filter = list(Param_Species.objects.all().values_list('authorized_value', flat=True))+[u'']
@@ -965,14 +959,24 @@ def get(self, request, format=None, **kwargs):
965959

966960

967961
rq1 = ScientificModel.objects.filter(
968-
private=1,
969-
app__in=all_ctx_from_collab.values("id"),
962+
private=1,
970963
species__in=species_filter,
971964
brain_region__in=brain_region_filter,
972965
cell_type__in=cell_type_filter,
973966
model_type__in=model_type_filter,
974967
organization__in=organization_filter).prefetch_related()
975-
968+
969+
##check permissions for Collabs
970+
collab_ids = list(rq1.prefetch_related().values_list('app__collab_id', flat=True).distinct())
971+
collab_ids_new = []
972+
for collab in collab_ids:
973+
if is_authorised(request, collab):
974+
collab_ids_new.append(collab)
975+
976+
all_ctx_from_collab = CollabParameters.objects.filter(collab_id__in=collab_ids_new).distinct()
977+
rq1 = rq1.filter(app__in = all_ctx_from_collab.values("id"))
978+
979+
976980
rq2 = ScientificModel.objects.filter (
977981
private=0,
978982
species__in=species_filter,
@@ -1495,8 +1499,9 @@ def put(self, request, format=None):
14951499
return Response("To edit a test instance, you need to give an id, or a test_definition_id with a version, or a test_definition_alias with a version ", status=status.HTTP_400_BAD_REQUEST)
14961500

14971501
#check if version is editable
1498-
if not _are_test_code_editable(test_code):
1499-
return Response("This version is no longer editable as there is at least one result associated with it", status=status.HTTP_400_BAD_REQUEST)
1502+
if not is_authorised(request,settings.ADMIN_COLLAB_ID):
1503+
if not _are_test_code_editable(test_code):
1504+
return Response("This version is no longer editable as there is at least one result associated with it", status=status.HTTP_400_BAD_REQUEST)
15001505

15011506
#check if versions are unique
15021507
if not _are_test_code_version_unique(test_code) :
@@ -1512,7 +1517,7 @@ def put(self, request, format=None):
15121517
serializer.save()
15131518
list_updated.append(serializer.data)
15141519

1515-
return Response({'uuid':list_updated}, status=status.HTTP_202_ACCEPTED)
1520+
return Response({'uuid':list_updated.id}, status=status.HTTP_202_ACCEPTED)
15161521

15171522

15181523
def get_serializer_class(self): #############not used???? TO delete?
@@ -1977,6 +1982,21 @@ def get(self, request, format=None, **kwargs):
19771982
})
19781983

19791984

1985+
class IsSuperUserRest (APIView):
1986+
"""
1987+
Class to check if user is an admin
1988+
"""
1989+
def get(self, request, format=None, **kwargs):
1990+
"""
1991+
:param app_id: id of the application
1992+
:type app_id: int
1993+
:return: bool: is_member
1994+
"""
1995+
1996+
is_superuser = is_authorised(request, settings.ADMIN_COLLAB_ID)
1997+
return Response({
1998+
'is_superuser': is_superuser,
1999+
})
19802000

19812001
"""
19822002
Model of table model_validation_api_validationtestresult
@@ -2149,7 +2169,7 @@ def get(self, request, format=None, **kwargs):
21492169
for result in results:
21502170
if not math.isnan(float(result.score)) and not math.isnan(float(result.normalized_score)) and not math.isinf(float(result.score)) and not math.isinf(float(result.normalized_score)):
21512171
new_results.append(result)
2152-
2172+
21532173
data_to_return = organise_results_dict(detailed_view, param_order, new_results, serializer_context)
21542174

21552175
# file = get_storage_file_by_id(request)

tests/karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ module.exports = function(config) {
178178
'../validation_service/app/static/angular-moment-1.1.0/angular-moment.js',
179179

180180
'../validation_service/app/static/palette.js-master/palette.js',
181+
182+
'../validation_service/app/static/angularUtils-pagination/dirPagination.js',
181183
//.js | files
182184
'./environment.js',
183185
'../validation_service/app/js/*.js',

tests/test_framework/test_services/test_ParametersConfigurationServices.spec.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,22 @@ describe('Testing service: Collab Parameters', function() {
159159
expect(CollabParameters.getParametersByType('model_type')).toEqual([]);
160160
});
161161

162+
it('should move an element at the end of an array', function() {
163+
var array = ["a", "b", "f", "c", "d", "e"]
164+
var res = CollabParameters._move_element_at_the_end_of_array("f", array)
165+
expect(res).toEqual(["a", "b", "c", "d", "e", "f"])
166+
});
167+
162168
it('should get the parameters if they are set and not the defaults parameters', function() {
169+
spyOn(CollabParameters, '_move_element_at_the_end_of_array').and.returnValue(["fMRI", 'electrophysiology', 'Other'])
170+
163171
CollabParameters.initConfiguration();
164-
CollabParameters.addParameter('data_modalities', {
165-
"id": "4631f734-1661-4e16-94f6-5aeeec8ce5c3",
166-
"authorized_value": "electrophysiology"
167-
})
168-
var res = CollabParameters.getParametersOrDefaultByType('data_modalities');
172+
CollabParameters.addParameter('data_modalities', "fMRI")
173+
CollabParameters.addParameter('data_modalities', "Other")
174+
CollabParameters.addParameter('data_modalities', "electrophysiology")
169175

170-
var expected_answer = [Object({ id: '4631f734-1661-4e16-94f6-5aeeec8ce5c3', authorized_value: 'electrophysiology' })];
176+
var res = CollabParameters.getParametersOrDefaultByType('data_modalities');
177+
var expected_answer = ['fMRI', 'electrophysiology', 'Other'];
171178
expect(res).toEqual(expected_answer)
172179
});
173180

validation_service/app/css/Model_catalog.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@
3030
background-color: #e1ebf0;
3131
}
3232

33+
.superuser-button {
34+
white-space: nowrap;
35+
padding: 2px 10px;
36+
cursor: pointer;
37+
background-color: #c43427;
38+
border: 2px solid #c43427;
39+
color: white;
40+
text-align: center;
41+
text-decoration: none;
42+
font-weight: bold;
43+
outline: none;
44+
border-radius: 6px;
45+
}
46+
47+
.superuser-button:hover {
48+
background-color: #c43427;
49+
color: white;
50+
}
51+
52+
.superuser-button:active {
53+
background-color: #c43427;
54+
transform: translateY(1px);
55+
}
56+
3357
.button-MC {
3458
white-space: nowrap;
3559
padding: 2px 10px;

validation_service/app/css/app.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
overflow: auto;
5656
}
5757

58+
#VF-model-table-all-data,
59+
table {
60+
min-width: 50%;
61+
max-width: 90%;
62+
}
63+
5864
#VF-model-table-all-results-not-more-than-three {
5965
display: block;
6066
margin-left: auto;
@@ -319,6 +325,10 @@
319325
overflow: auto;
320326
}
321327

328+
.th-td-limited-size {
329+
width: 8%;
330+
}
331+
322332

323333
/* Preloader */
324334

@@ -332,6 +342,26 @@
332342
z-index: 99;
333343
}
334344

345+
#preloader-models {
346+
position: fixed;
347+
top: 70%;
348+
left: 0;
349+
right: 50%;
350+
bottom: 0;
351+
background-color: #fff;
352+
z-index: 99;
353+
}
354+
355+
#preloader-tests {
356+
position: fixed;
357+
top: 70%;
358+
left: 50%;
359+
right: 0;
360+
bottom: 0;
361+
background-color: #fff;
362+
z-index: 99;
363+
}
364+
335365
#status {
336366
width: 200px;
337367
height: 200px;

validation_service/app/js/controller.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@ testApp.controller('HomeCtrl', ['$scope', '$rootScope', '$http', '$location', "S
5555
$scope.models = data;
5656
$scope.$apply();
5757

58+
$('#status').fadeOut(); // will first fade out the loading animation
59+
$('#preloader-models').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
60+
$('#models-panel').delay(350).css({ 'overflow': 'visible' });
61+
5862
$scope._load_other_models();
5963
});
6064

6165
DataHandler.loadTests({ app_id: $scope.app_id }).then(function(data) {
6266
$scope.tests = data;
6367
$scope.$apply()
68+
69+
$('#status-tests').fadeOut(); // will first fade out the loading animation
70+
$('#preloader-tests').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
71+
$('#tests-panel').delay(350).css({ 'overflow': 'visible' });
72+
6473
});
6574
});
6675
} else {
@@ -117,10 +126,6 @@ testApp.controller('ValTestCtrl', ['$scope', '$rootScope', '$http', '$location',
117126
$scope.is_collab_member = $scope.is_collab_member.is_member;
118127
});
119128

120-
// $scope.test_list = ValidationTestDefinitionRest.get({ app_id: app_id }, function(data) {});
121-
122-
// $scope.tests = ValidationTestDefinitionRest.get({ app_id: app_id }, function(data) {});
123-
124129
});
125130
});
126131

@@ -234,7 +239,6 @@ testApp.controller('ValModelDetailCtrl', ['$scope', '$rootScope', '$http', '$loc
234239
$scope.$apply();
235240
});
236241
$scope.init_graph = init_graph.values;
237-
console.log("init graph", $scope.init_graph, $scope.init_graph.length)
238242
});
239243

240244
DataHandler.loadModels({ app_id: $scope.app_id }).then(function(data) {
@@ -301,9 +305,9 @@ testApp.directive("precision", function() {
301305
};
302306
});
303307

304-
testApp.controller('ValTestDetailCtrl', ['$scope', '$rootScope', '$http', '$location', '$stateParams', '$state', 'ValidationTestDefinitionRest', 'ValidationTestCodeRest', 'CollabParameters', 'TestCommentRest', "IsCollabMemberRest", "Graphics", "Context", 'TestTicketRest', 'AuthorizedCollabParameterRest', 'ValidationTestAliasRest', 'NotificationRest', 'AreVersionsEditableRest', 'DataHandler',
308+
testApp.controller('ValTestDetailCtrl', ['$scope', '$rootScope', '$http', '$location', '$stateParams', '$state', 'ValidationTestDefinitionRest', 'ValidationTestCodeRest', 'CollabParameters', 'TestCommentRest', "IsCollabMemberRest", "Graphics", "Context", 'TestTicketRest', 'AuthorizedCollabParameterRest', 'ValidationTestAliasRest', 'NotificationRest', 'AreVersionsEditableRest', 'DataHandler', 'IsSuperUserRest',
305309

306-
function($scope, $rootScope, $http, $location, $stateParams, $state, ValidationTestDefinitionRest, ValidationTestCodeRest, CollabParameters, TestCommentRest, IsCollabMemberRest, Graphics, Context, TestTicketRest, AuthorizedCollabParameterRest, ValidationTestAliasRest, NotificationRest, AreVersionsEditableRest, DataHandler) {
310+
function($scope, $rootScope, $http, $location, $stateParams, $state, ValidationTestDefinitionRest, ValidationTestCodeRest, CollabParameters, TestCommentRest, IsCollabMemberRest, Graphics, Context, TestTicketRest, AuthorizedCollabParameterRest, ValidationTestAliasRest, NotificationRest, AreVersionsEditableRest, DataHandler, IsSuperUserRest) {
307311

308312
$scope.init_graph, $scope.graphic_data, $scope.init_checkbox, $scope.graphic_options;
309313
$scope.data_for_table;
@@ -640,6 +644,8 @@ testApp.controller('ValTestDetailCtrl', ['$scope', '$rootScope', '$http', '$loca
640644
$scope.ctx = Context.getCtx();
641645
$scope.app_id = Context.getAppID();
642646

647+
$scope.isSuperUser = IsSuperUserRest.get({ app_id: $scope.app_id })
648+
643649
CollabParameters.setService($scope.ctx).then(function() {
644650

645651
$scope.detail_test = ValidationTestDefinitionRest.get({ app_id: $scope.app_id, id: $stateParams.uuid });
@@ -1411,9 +1417,10 @@ ModelCatalogApp.controller('ModelCatalogDetailCtrl', ['$scope', '$rootScope', '$
14111417
}
14121418
]);
14131419

1414-
ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$http', '$location', '$state', '$stateParams', 'ScientificModelRest', 'ScientificModelInstanceRest', 'ScientificModelImageRest', 'CollabParameters', 'Context', 'ScientificModelAliasRest', 'AreVersionsEditableRest', 'DataHandler', 'clbStorage',
1420+
ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$http', '$location', '$state', '$stateParams', 'ScientificModelRest', 'ScientificModelInstanceRest', 'ScientificModelImageRest', 'CollabParameters', 'Context', 'ScientificModelAliasRest', 'AreVersionsEditableRest', 'DataHandler', 'clbStorage', 'IsSuperUserRest',
1421+
1422+
function($scope, $rootScope, $http, $location, $state, $stateParams, ScientificModelRest, ScientificModelInstanceRest, ScientificModelImageRest, CollabParameters, Context, ScientificModelAliasRest, AreVersionsEditableRest, DataHandler, clbStorage, IsSuperUserRest) {
14151423

1416-
function($scope, $rootScope, $http, $location, $state, $stateParams, ScientificModelRest, ScientificModelInstanceRest, ScientificModelImageRest, CollabParameters, Context, ScientificModelAliasRest, AreVersionsEditableRest, DataHandler, clbStorage) {
14171424

14181425
$scope.change_collab_url_to_real_url = function() {
14191426
//COULD BE IN A SERVICE
@@ -1519,7 +1526,6 @@ ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$ht
15191526
return array.indexOf(value) > -1;
15201527
}
15211528

1522-
15231529
Context.setService().then(function() {
15241530

15251531
$scope.Context = Context;
@@ -1530,6 +1536,8 @@ ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$ht
15301536
// $scope.models = data
15311537
// $scope.$apply()
15321538
// });
1539+
$scope.isSuperUser = IsSuperUserRest.get({ app_id: $scope.app_id })
1540+
15331541

15341542
CollabParameters.setService($scope.ctx).then(function() {
15351543

@@ -1543,7 +1551,7 @@ ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$ht
15431551

15441552
$scope.version_is_editable = [];
15451553
$scope.model = ScientificModelRest.get({ app_id: $scope.app_id, id: $stateParams.uuid });
1546-
console.log("model", $scope.model)
1554+
15471555
$scope.model.$promise.then(function(model) {
15481556
$scope.change_collab_url_to_real_url();
15491557
});

0 commit comments

Comments
 (0)