refuse to add/remove slivers for readonly user
authorScott Baker <smbaker@gmail.com>
Thu, 22 May 2014 16:29:06 +0000 (09:29 -0700)
committerScott Baker <smbaker@gmail.com>
Thu, 22 May 2014 16:29:06 +0000 (09:29 -0700)
planetstack/core/plus/views.py
planetstack/templates/admin/dashboard/cdnoperations.html

index 4dcca79..2b7bf38 100644 (file)
@@ -699,6 +699,9 @@ class DashboardAddOrRemoveSliverView(View):
         siteList = [Site.objects.get(name=siteName)]
         slice = Slice.objects.get(name="HyperCache")
 
+        if request.user.isReadOnlyUser():
+            return HttpResponseForbidden("User is in read-only mode")
+
         if (actionToDo == "add"):
             user_ip = request.GET.get("ip", get_ip(request))
             slice_increase_slivers(request.user, user_ip, siteList, slice, 1)
@@ -707,7 +710,7 @@ class DashboardAddOrRemoveSliverView(View):
 
         print '*' * 50
         print 'Ask for site: ' + siteName + ' to ' + actionToDo + ' another HPC Sliver'
-        return HttpResponse('This is POST request ')
+        return HttpResponse(json.dumps("Success"), mimetype='application/javascript')
 
 class DashboardAjaxView(View):
     def get(self, request, **kwargs):
index 31ff746..167b558 100644 (file)
@@ -96,16 +96,12 @@ $('#map-us').on('click', '#remHPCSliver', function() {
                csrfmiddlewaretoken: "{{ csrf_token }}",   // < here
                state:"inactive" },
         type : 'POST',
-        //success: function(response)
-        //{
-         //   alert("Successfully posted request to REMOVE sliver");
-        //},
-        complete:function(){
+        success:function(){
             confirmDialog("Info","Removed an HPC Sliver from Site ");
         },
-        //error:function (xhr, textStatus, thrownError){
-         //   alert("Could not request to remove HPC Sliver");
-        //}
+        error:function (xhr, textStatus, thrownError){
+            errorDialog("Error", textStatus + " " + xhr.responseText);
+        }
     });
 });
 
@@ -120,18 +116,13 @@ $('#map-us').on('click', '#addHPCSliver', function() {
                state:"inactive" },
         type : 'POST',
         success: function(response)
-        {
-            //alert("Successfully posted request to add sliver");
-        },
-        complete:function()
         {
             confirmDialog("Info","Added an HPC Sliver to Site ");
         },
-        //error:function (xhr, textStatus, thrownError){
-         //   alert("error doing something");
-        //}
+        error:function (xhr, textStatus, thrownError){
+            errorDialog("Error", textStatus + " " + xhr.responseText);
+        }
     });
-  //  confirmDialog("Add HPC Slivers","Add some HPC Slivers to site " + $(this).data('site'));
 });
 
 function getIcon(numNodes, numHPCSlivers, currentBW, hot) {