Manage Requests: authority startswith the list of auth_hrn the user manages
authorLoic Baron <loic.baron@lip6.fr>
Tue, 6 Jan 2015 18:06:52 +0000 (19:06 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Tue, 6 Jan 2015 18:06:52 +0000 (19:06 +0100)
portal/actions.py
portal/managementtabrequests.py
portal/templates/fed4fire/fed4fire_management-tab-requests.html [deleted file]
portal/templates/management-tab-requests.html
portal/templates/onelab/onelab_management-tab-requests.html [deleted file]
portal/templates/slice-tab-experiment.html

index 31e4bcb..e8a4d01 100644 (file)
@@ -323,9 +323,23 @@ def get_requests(authority_hrns=None):
         pending_slices = PendingSlice.objects.all()
         pending_authorities = PendingAuthority.objects.all()
     else:
-        pending_users  = PendingUser.objects.filter(authority_hrn__in=authority_hrns).all()
-        pending_slices = PendingSlice.objects.filter(authority_hrn__in=authority_hrns).all()
-        pending_authorities = PendingAuthority.objects.filter(authority_hrn__in=authority_hrns).all()
+        pending_users  = PendingUser.objects
+        pending_slices = PendingSlice.objects
+        pending_authorities = PendingAuthority.objects
+        from django.db.models import Q
+        list_user_Q = list()
+        list_slice_Q = list()
+        list_auth_Q = list()
+        for hrn in authority_hrns:
+            list_user_Q.append(Q(authority_hrn__startswith=hrn, status__iexact = 'True'))
+            list_slice_Q.append(Q(authority_hrn__startswith=hrn))
+            list_auth_Q.append(Q(site_authority__startswith=hrn))
+            print "startswith hrn = ",hrn
+        from operator import __or__ as OR
+        pending_users        = pending_users.filter(reduce(OR, list_user_Q))
+        pending_slices       = pending_slices.filter(reduce(OR, list_slice_Q))
+        pending_authorities  = pending_authorities.filter(reduce(OR, list_auth_Q))
+        #pending_authorities  = pending_authorities.all() #filter(reduce(OR, list_Q))
 
     return make_requests(pending_users, pending_slices, pending_authorities)
 
index 31cbb0d..7c0b222 100644 (file)
@@ -73,25 +73,18 @@ class ManagementRequestsView (LoginRequiredView, ThemeView):
             
             for user_account in user_accounts:
 
-                print "USER ACCOUNT", user_account
                 if user_account['auth_type'] == 'reference':
                     continue # we hardcoded the myslice platform...
 
                 config = json.loads(user_account['config'])
                 creds = []
-                print "CONFIG KEYS", config.keys()
                 if 'authority_credentials' in config:
-                    print "***", config['authority_credentials'].keys()
                     for authority_hrn, credential in config['authority_credentials'].items():
                         credential_authorities.add(authority_hrn)
                 if 'delegated_authority_credentials' in config:
-                    print "***", config['delegated_authority_credentials'].keys()
                     for authority_hrn, credential in config['delegated_authority_credentials'].items():
                         credential_authorities.add(authority_hrn)
 
-            print 'credential_authorities =', credential_authorities
-            print 'credential_authorities_expired =', credential_authorities_expired
-
             # ** Where am I a PI **
             # For this we need to ask SFA (of all authorities) = PI function
             pi_authorities_query = Query.get('user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
@@ -119,17 +112,21 @@ class ManagementRequestsView (LoginRequiredView, ThemeView):
 
             # iterate on the requests and check if the authority matches a prefix 
             # startswith an authority on which the user is PI
-            requests = get_requests()
+            if len(pi_my_authorities)>0:
+                requests = get_requests(pi_my_authorities)
+            else:
+                requests = get_requests()
             for r in requests:
                 auth_hrn = r['authority_hrn']
                 for my_auth in pi_my_authorities: 
                     if auth_hrn.startswith(my_auth):
                         dest = ctx_my_authorities
                         r['allowed'] = 'allowed'
-                for my_auth in pi_delegation_authorities:
-                    if auth_hrn.startswith(my_auth):
-                        dest = ctx_delegation_authorities
-                        r['allowed'] = 'allowed'
+
+                #for my_auth in pi_delegation_authorities:
+                #    if auth_hrn.startswith(my_auth):
+                #        dest = ctx_delegation_authorities
+                #        r['allowed'] = 'allowed'
                 if auth_hrn in pi_expired_credential_authorities:
                     r['allowed'] = 'expired'
                 if 'allowed' not in r:
diff --git a/portal/templates/fed4fire/fed4fire_management-tab-requests.html b/portal/templates/fed4fire/fed4fire_management-tab-requests.html
deleted file mode 100644 (file)
index e255779..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-<script type="text/javascript">
-       $(document).ready(function() {
-               $("li#nav-request").addClass("active");
-       });
-       function on_click_event() {
-               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/validate_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);
-
-
-                                       });
-                               }
-                       );
-               }
-       }
-</script>
-
-<div class="col-md-12">
-       <h2>From your authorities</h2>
-</div>
-{% if my_authorities %}
-       
-       {% for authority, requests in my_authorities.items %}
-       
-       <div class="col-md-12">
-               <h2>{{authority}}</h2>
-       </div>
-       
-    <table class="table">
-      <th>
-        <td>Type</td>
-        <td>Id</td>
-        <td>Details</td>
-        <td>Timestamp</td>
-        <td>Status</td>
-      </th>
-    {% for request in requests %}
-
-         <tr>
-               <td>
-               {% if request.allowed == 'allowed' %}
-               <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-               {% else %}
-                       {% if request.allowed == 'expired' %}
-                               expired
-                       {% else %} {# denied #}
-                               denied
-                       {% endif %}
-               {% endif %}
-               </td>
-               <td>{{ request.type }}</td>
-               <td>{{ request.id }}</td>
-               <td>
-        {% if request.type == 'user' %}
-            <b>{{request.first_name}} {{request.last_name}}</b> <a href="mailto:{{request.email}}">{{request.email}}</a>
-        {% else %}
-            {% if request.type == 'slice' %}
-            <b>{{request.slice_name}}</b> -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-            {% else %} {# authority #}
-            <b>{{request.site_name}}</b> ({{request.site_authority}}) -- {{request.address_city}}, {{request.address_country}}
-            {% endif %}
-        {% endif %}
-               </td>
-               <td>{{ request.timestamp }}</td>
-               
-               <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-
-    <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-         </tr>
-
-    {% endfor %}
-       </table>
-       {% endfor %}
-
-{% else %}
-       <div class="col-md-12">
-               <i>There is no pending request waiting for validation.</i>
-       </div>
-{% endif %}
-<div>nnllknjkn<br /><br /></div>
-<div class="col-md-12">
-       <h2>From your sub-authorities</h2>
-</div>
-{% if sub_authorities %}
-       
-       {% for authority, requests in sub_authorities.items %}
-       <div class="col-md-12">
-               <h2>{{authority}}</h2>
-       </div>
-       
-       <table class="table">
-             <th>
-               <td>Type</td>
-               <td>Id</td>
-               <td>Details</td>
-               <td>Timestamp</td>
-               <td>Status</td>
-             </th>
-           {% for request in requests %}
-                 <tr>
-                       <td>
-                       {% if request.allowed == 'allowed' %}
-                       <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-                       {% else %}
-                               {% if request.allowed == 'expired' %}
-                                       expired
-                               {% else %} {# denied #}
-                                       denied
-                               {% endif %}
-                       {% endif %}
-                       </td>
-                       <td>{{ request.type }}</td>
-                       <td>{{ request.id }}</td>
-                       <td>
-               {% if request.type == 'user' %}
-               Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-               {% else %}
-                   {% if request.type == 'slice' %}
-               Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-                   {% else %} {# authority #}
-               Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-                   {% endif %}
-               {% endif %}
-                       </td>
-                       <td>{{ request.timestamp }}</td>
-                       
-                       <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-       
-           <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-                 </tr>
-           {% endfor %}
-       </table>
-       {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
-{% endif %}
-
-<div class="col-md-12">
-       <h2>From your authorities with delegation</h2>
-</div>
-
-{% if delegation_authorities %}
-       
-       {% for authority, requests in delegation_authorities.items %}
-       <div class="col-md-12">
-               <h3>{{authority}}</h3>
-       </div>
-       <table class="table">
-                     <th>
-                       <td>Type</td>
-                       <td>Id</td>
-                       <td>Details</td>
-                       <td>Timestamp</td>
-                       <td>Status</td>
-                     </th>
-                   {% for request in requests %}
-                         <tr>
-                               <td>
-                               {% if request.allowed == 'allowed' %}
-                               <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-                               {% else %}
-                                       {% if request.allowed == 'expired' %}
-                                               expired
-                                       {% else %} {# denied #}
-                                               denied
-                                       {% endif %}
-                               {% endif %}
-                               </td>
-                               <td>{{ request.type }}</td>
-                               <td>{{ request.id }}</td>
-                               <td>
-                       {% if request.type == 'user' %}
-                       Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-                       {% else %}
-                           {% if request.type == 'slice' %}
-                       Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-                           {% else %} {# authority #}
-                       Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-                           {% endif %}
-                      {% endif %}
-                               </td>
-                               <td>{{ request.timestamp }}</td>
-                               
-                               <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-               
-                   <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-                         </tr>
-                   {% endfor %}
-       </table>
-               {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
-{% endif %}
-<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>
-</div>
index ddac594..dad0e6e 100644 (file)
 {% endif %}
 </div>
 
-
+{% if sub_authorities %}
 <br />
 <div class="col-md-12">
        <h2>From your sub-authorities</h2>
 </div>
-{% if sub_authorities %}
-       
+
        {% for authority, requests in sub_authorities.items %}
        <div class="col-md-12">
        <h3>{{authority}}</h3>
            </table>
        </div>
        {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
 {% endif %}
+{% if delegation_authorities %}
 <br />
 <div class="col-md-12">
        <h2>From your authorities with delegation</h2>
 </div>
 
-{% if delegation_authorities %}
-       
        {% for authority, requests in delegation_authorities.items %}
        <div class="col-md-12">
                <h3>{{authority}}</h3>
                    </table>
                </div>
                {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
 {% endif %}
 <br />
 <div class="col-md-12">
diff --git a/portal/templates/onelab/onelab_management-tab-requests.html b/portal/templates/onelab/onelab_management-tab-requests.html
deleted file mode 100644 (file)
index e255779..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-<script type="text/javascript">
-       $(document).ready(function() {
-               $("li#nav-request").addClass("active");
-       });
-       function on_click_event() {
-               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/validate_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);
-
-
-                                       });
-                               }
-                       );
-               }
-       }
-</script>
-
-<div class="col-md-12">
-       <h2>From your authorities</h2>
-</div>
-{% if my_authorities %}
-       
-       {% for authority, requests in my_authorities.items %}
-       
-       <div class="col-md-12">
-               <h2>{{authority}}</h2>
-       </div>
-       
-    <table class="table">
-      <th>
-        <td>Type</td>
-        <td>Id</td>
-        <td>Details</td>
-        <td>Timestamp</td>
-        <td>Status</td>
-      </th>
-    {% for request in requests %}
-
-         <tr>
-               <td>
-               {% if request.allowed == 'allowed' %}
-               <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-               {% else %}
-                       {% if request.allowed == 'expired' %}
-                               expired
-                       {% else %} {# denied #}
-                               denied
-                       {% endif %}
-               {% endif %}
-               </td>
-               <td>{{ request.type }}</td>
-               <td>{{ request.id }}</td>
-               <td>
-        {% if request.type == 'user' %}
-            <b>{{request.first_name}} {{request.last_name}}</b> <a href="mailto:{{request.email}}">{{request.email}}</a>
-        {% else %}
-            {% if request.type == 'slice' %}
-            <b>{{request.slice_name}}</b> -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-            {% else %} {# authority #}
-            <b>{{request.site_name}}</b> ({{request.site_authority}}) -- {{request.address_city}}, {{request.address_country}}
-            {% endif %}
-        {% endif %}
-               </td>
-               <td>{{ request.timestamp }}</td>
-               
-               <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-
-    <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-         </tr>
-
-    {% endfor %}
-       </table>
-       {% endfor %}
-
-{% else %}
-       <div class="col-md-12">
-               <i>There is no pending request waiting for validation.</i>
-       </div>
-{% endif %}
-<div>nnllknjkn<br /><br /></div>
-<div class="col-md-12">
-       <h2>From your sub-authorities</h2>
-</div>
-{% if sub_authorities %}
-       
-       {% for authority, requests in sub_authorities.items %}
-       <div class="col-md-12">
-               <h2>{{authority}}</h2>
-       </div>
-       
-       <table class="table">
-             <th>
-               <td>Type</td>
-               <td>Id</td>
-               <td>Details</td>
-               <td>Timestamp</td>
-               <td>Status</td>
-             </th>
-           {% for request in requests %}
-                 <tr>
-                       <td>
-                       {% if request.allowed == 'allowed' %}
-                       <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-                       {% else %}
-                               {% if request.allowed == 'expired' %}
-                                       expired
-                               {% else %} {# denied #}
-                                       denied
-                               {% endif %}
-                       {% endif %}
-                       </td>
-                       <td>{{ request.type }}</td>
-                       <td>{{ request.id }}</td>
-                       <td>
-               {% if request.type == 'user' %}
-               Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-               {% else %}
-                   {% if request.type == 'slice' %}
-               Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-                   {% else %} {# authority #}
-               Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-                   {% endif %}
-               {% endif %}
-                       </td>
-                       <td>{{ request.timestamp }}</td>
-                       
-                       <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-       
-           <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-                 </tr>
-           {% endfor %}
-       </table>
-       {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
-{% endif %}
-
-<div class="col-md-12">
-       <h2>From your authorities with delegation</h2>
-</div>
-
-{% if delegation_authorities %}
-       
-       {% for authority, requests in delegation_authorities.items %}
-       <div class="col-md-12">
-               <h3>{{authority}}</h3>
-       </div>
-       <table class="table">
-                     <th>
-                       <td>Type</td>
-                       <td>Id</td>
-                       <td>Details</td>
-                       <td>Timestamp</td>
-                       <td>Status</td>
-                     </th>
-                   {% for request in requests %}
-                         <tr>
-                               <td>
-                               {% if request.allowed == 'allowed' %}
-                               <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-                               {% else %}
-                                       {% if request.allowed == 'expired' %}
-                                               expired
-                                       {% else %} {# denied #}
-                                               denied
-                                       {% endif %}
-                               {% endif %}
-                               </td>
-                               <td>{{ request.type }}</td>
-                               <td>{{ request.id }}</td>
-                               <td>
-                       {% if request.type == 'user' %}
-                       Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-                       {% else %}
-                           {% if request.type == 'slice' %}
-                       Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-                           {% else %} {# authority #}
-                       Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-                           {% endif %}
-                      {% endif %}
-                               </td>
-                               <td>{{ request.timestamp }}</td>
-                               
-                               <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-               
-                   <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-                         </tr>
-                   {% endfor %}
-       </table>
-               {% endfor %}
-{% else %}
-<div class="col-md-12">
-       <i>There is no pending request waiting for validation.</i>
-</div>
-{% endif %}
-<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>
-</div>
index eb9a4ec..ce97efa 100644 (file)
                Be aware that after you reserve a PlanetLab Europe resource your slice will be deployed with a delay of about 15 minutes, 
                after witch you will be able to access the resource.
        </p>
+    <div id="initscript">
+        <div>
+            <h4>Init Script on PLE</h4>
+            <i>This bash script will be deployed on all PLE nodes of your slice</i>
+        </div>
+        <textarea style="width:100%; height:100px;" id="initscript_code"></textarea><br>
+        <button name="deploy" class="btn btn-success btn-sm" onclick="deploy('{{slicename}}');">Deploy</button>
+        <button name="delete" class="btn btn-danger btn-xs" onclick="del('{{slicename}}');">Delete</button>
+    </div>
+    <script type="text/javascript">
+    $(document).ready(function() {
+        $.post("/initscript/get/",{'slice_hrn':'onelab.upmc.express'}, function( data ) {
+            console.log(data);
+            jQuery('#initscript_code').val(data['initscript_code']);
+        });
+    });
+    function deploy(slice_hrn){
+        console.log("deploy = "+slice_hrn);
+        var initscript_code = jQuery('#initscript_code').val()
+        $.post("/initscript/update/",{'slice_hrn':slice_hrn, 'initscript_code':initscript_code}, function( data ) {
+            console.log(data);
+            if (data['ret'] == 0) {
+                mysliceAlert('Success: initscript deployed','success', true);
+            }else{
+                mysliceAlert('Rest Error for: '+data.error,'warning', true);
+            }
+            //jQuery('#initscript_code').val(data['initscript_code']);
+        });
+    }
+    function del(slice_hrn){
+        console.log("delete");
+        $.post("/initscript/delete/",{'slice_hrn':slice_hrn}, function( data ) {
+            console.log(data);
+            if (data['ret'] == 0) {
+                mysliceAlert('Success: initscript deleted','success', true);
+                jQuery('#initscript_code').val('');
+            }else{
+                mysliceAlert('Rest Error for: '+data.error,'warning', true);
+            }
+
+        });
+    }
+    </script>
+    <br>
        {% endif %}
 
        {% if iotlab_resources %}