requests: reject button added & functional (todo: send email)
authorYasin <mohammed-yasin.rahman@lip6.fr>
Tue, 26 Aug 2014 14:18:19 +0000 (16:18 +0200)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Tue, 26 Aug 2014 14:18:19 +0000 (16:18 +0200)
portal/actions.py
portal/templates/management-tab-requests.html
portal/urls.py

index 38af28c..03f1c3a 100644 (file)
@@ -383,13 +383,49 @@ def portal_validate_request(wsgi_request, request_ids):
 
     return status
 
-
 def validate_action(request, **kwargs):
     ids = filter(None, kwargs['id'].split('/'))
     status = portal_validate_request(request, ids)
     json_answer = json.dumps(status)
     return HttpResponse (json_answer, mimetype="application/json")
 
+
+def reject_action(request, **kwargs):
+    ids = filter(None, kwargs['id'].split('/'))
+    status = portal_reject_request(request, ids)
+    json_answer = json.dumps(status)
+    return HttpResponse (json_answer, mimetype="application/json")
+
+
+def portal_reject_request(wsgi_request, request_ids):
+    status = {}
+
+    if not isinstance(request_ids, list):
+        request_ids = [request_ids]
+
+    requests = get_request_by_id(request_ids)
+    for request in requests:
+        # type, id, timestamp, details, allowed -- MISSING: authority_hrn
+        # CAREFUL about details
+        # user  : first name, last name, email, password, keypair
+        # slice : number of nodes, type of nodes, purpose
+        
+        request_status = {}
+
+        if request['type'] == 'user':
+            request_status['SFA user'] = {'status': True }
+            PendingUser.objects.get(id=request['id']).delete()
+        elif request['type'] == 'slice':
+            request_status['SFA slice'] = {'status': True }           
+            PendingSlice.objects.get(id=request['id']).delete()
+        elif request['type'] == 'authority':
+            request_status['SFA authority'] = {'status': True }           
+            PendingAuthority.objects.get(id=request['id']).delete()
+
+        status['%s__%s' % (request['type'], request['id'])] = request_status
+
+    return status
+
 # Django and ajax
 # http://djangosnippets.org/snippets/942/
 
index 2270a3b..d36027b 100644 (file)
                                                $('#portal__status__' + request_type__id).html(status_str);
 
 
+                                       });
+                               }
+                       );
+               }
+       }
+       function on_click_reject() {
+               var ids = []; 
+               $('.portal__validate__checkbox').each(function(i, el) {
+                       if ($(el).prop('checked')) {
+                               // portal__validate__checkbox__slice__2
+                               var id_array = $(el).attr('id').split('__');
+                               // push(slice__2)
+                               ids.push(id_array[3] + '__' + id_array[4]);
+                       }
+               });
+               if (ids.length > 0) {
+                       var id_str = ids.join('/');
+
+                       // XXX spinner
+
+                       $.getJSON('/portal/reject_action/' + id_str,
+                               function(status) {
+                                       $.each(status, function(request_type__id, request_status) {
+                                               // request_status: NAME -> dict (status, description)
+                                               var status_str = '';
+                                               $.each(request_status, function(name, result) {
+                                                       if (status_str != '')
+                                                               status_str += ' -- ';
+
+                                                       if (result.status) {
+                                                               status_str += '<font color="green">OK</font>';
+                                                               $('#portal__validate__checkbox__' + request_type__id).hide();
+                                                       } else {
+                                                               status_str += '<font color="red">ERROR: ' + result.description + '</font>';
+                                                       }
+                                               });
+                                               $('#portal__status__' + request_type__id).html(status_str);
+
+
                                        });
                                }
                        );
 <br />
 <div class="col-md-12">
        <button class="btn btn-onelab" type="button" id="portal__validate" onclick="on_click_event();"><span class="glyphicon glyphicon-ok"></span> Validate</button>
+       <button class="btn btn-onelab" type="button" id="portal__reject" onclick="on_click_reject();"><span class="glyphicon glyphicon-remove"></span> Reject</button>
 </div>
index e6e63e6..8bcdaf2 100644 (file)
@@ -99,7 +99,7 @@ urlpatterns = patterns('',
     # http://stackoverflow.com/questions/2360179/django-urls-how-to-pass-a-list-of-items-via-clean-urls
     # (r'^validate_action/(?P<constraints>[^/]+)/(?P<id>\w+)/?$', 'portal.views.pres_view_static'),
     url(r'^validate_action(?P<id>(?:/\w+)+)/?$', 'portal.actions.validate_action'),
-
+    url(r'^reject_action(?P<id>(?:/\w+)+)/?$', 'portal.actions.reject_action'),
     url(r'^pres_view/?$', PresViewView.as_view(), name='pres_view'),
     (r'^methods/(?P<type>\w+)/?$', 'portal.views.pres_view_methods'),
     (r'^animation/(?P<constraints>[^/]+)/(?P<id>\w+)/?$', 'portal.views.pres_view_animation'),