Skip to content

Commit b6cd7f9

Browse files
committed
Add superuser
1 parent 3cc0bf3 commit b6cd7f9

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
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/views.py

Lines changed: 24 additions & 6 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) :
@@ -1978,6 +1981,21 @@ def get(self, request, format=None, **kwargs):
19781981
})
19791982

19801983

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

19822000
"""
19832001
Model of table model_validation_api_validationtestresult

validation_service/app/js/controller.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,9 +1415,10 @@ ModelCatalogApp.controller('ModelCatalogDetailCtrl', ['$scope', '$rootScope', '$
14151415
}
14161416
]);
14171417

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

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

14221423
$scope.change_collab_url_to_real_url = function() {
14231424
//COULD BE IN A SERVICE
@@ -1523,7 +1524,6 @@ ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$ht
15231524
return array.indexOf(value) > -1;
15241525
}
15251526

1526-
15271527
Context.setService().then(function() {
15281528

15291529
$scope.Context = Context;
@@ -1534,6 +1534,8 @@ ModelCatalogApp.controller('ModelCatalogEditCtrl', ['$scope', '$rootScope', '$ht
15341534
// $scope.models = data
15351535
// $scope.$apply()
15361536
// });
1537+
$scope.isSuperUser = IsSuperUserRest.get({ app_id: $scope.app_id })
1538+
15371539

15381540
CollabParameters.setService($scope.ctx).then(function() {
15391541

validation_service/app/js/model.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,12 @@ ApiCommunicationServices.factory('collabAppID', ['$resource',
194194
get: { method: 'GET', params: { format: 'json', ctx: 'ctx' }, isArray: false },
195195
});
196196
}
197+
]);
198+
199+
ApiCommunicationServices.factory('IsSuperUserRest', ['$resource',
200+
function($resource) {
201+
return $resource('issuperuser/', {}, {
202+
get: { method: 'GET', params: { format: 'json', ctx: 'ctx' }, isArray: false },
203+
});
204+
}
197205
]);

validation_service/app/templates/model_catalog/model-catalog-edit.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ <h2>
230230
<td><input type="text" ng-model=model_instance.code_format /></td>
231231
<td><button ng-if="isInArray(model_instance.id, version_is_editable)" type="submit" class="btn btn-primary" ng-click=saveModelInstance(model_instance)>Save changes</button>
232232
<button ng-if="!isInArray(model_instance.id, version_is_editable)" type="" class="btn btn-danger">Not editable</button></td>
233+
<td><button ng-if="isSuperUser.is_superuser" type="submit" class="btn btn-primary" ng-click=saveModelInstance(model_instance)>SuperUser Edit</button></td>
233234
</tr>
234235
</tbody>
235236
</table>

validation_service/validation_service/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
HBP_ENV_URL = 'https://collab.humanbrainproject.eu/config.json'
171171
HBP_IDENTITY_SERVICE_URL = 'https://services.humanbrainproject.eu/idm/v1/api'
172172
HBP_STORAGE_SERVICE_URL = 'https://services.humanbrainproject.eu/storage/v1/api/entity/'
173-
173+
ADMIN_COLLAB_ID = "13947"
174174

175175

176176
# SECURITY WARNING: keep the secret key used in production secret!

0 commit comments

Comments
 (0)