review the registration process to mark with ext_consortium_id=0 the pending sites
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 16 Oct 2009 17:13:01 +0000 (17:13 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 16 Oct 2009 17:13:01 +0000 (17:13 +0000)
this in turn will be used by monitor to avoid sending actions to those sites
also made the address block optional
pending sites rendering nicer

planetlab/common/actions.php
planetlab/css/plc_style.css
planetlab/includes/plc_functions.php
planetlab/includes/plc_header.php
planetlab/sites/join_request.php
planetlab/sites/register.php
planetlab/sites/site.php
planetlab/sites/site_form.php
planetlab/sites/sites.php

index 1600eb4..a2dfd11 100644 (file)
@@ -541,8 +541,6 @@ switch ($action) {
      drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
      plc_redirect(l_slice($slice_id));
    }
-   plc_debug('slice_id',$slice_id);
-   plc_debug('expires',$expires);
    if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
      drupal_set_message("Slice renewed");
    else
index 8df53c4..87657d1 100644 (file)
@@ -97,7 +97,7 @@ div.site-register {
     margin: 10px;
 }
 /* site registration */
-div.site-pending {
+div.site-pending, div.sites-pending {
     background-color: #eadbc8;
     padding: 5px;
     margin: 10px;
@@ -107,6 +107,11 @@ div.person-register {
     padding: 5px;
     margin: 10px;
 }
+div.person-register {
+    background-color: #e3d1cb;
+    padding: 5px;
+    margin: 10px;
+}
 
 /****************************************/
 /* slice creation page */
index c72c598..4f10e8c 100644 (file)
@@ -5,6 +5,13 @@
 // will trash this eventually
   //require_once 'plc_functions_trash.php';
 
+# note: this needs to be consistent with the value in Monitor/monitor/wrapper/plc.py
+global $PENDING_CONSORTIUM_ID;
+$PENDING_CONSORTIUM_ID = 0;
+# this one does not matter that much, just picking one
+global $APPROVED_CONSORTIUM_ID;
+$APPROVED_CONSORTIUM_ID = 999999;
+
 // utility
 function my_is_int ($x) {
     return (is_numeric($x) ? intval($x) == $x : false);
@@ -149,6 +156,7 @@ function l_reset_password()         { return "/db/persons/reset_password.php"; }
 function l_person_register()           { return "/db/persons/register.php"; }
 function l_site_register()             { return "/db/sites/register.php"; }
 function l_sites_pending()             { return "/db/sites/join_request.php"; }
+function l_site_review_pending($site_id){ return "/db/sites/join_request.php?review=t&site_id=$site_id"; }
 
 
 //////////////////////////////////////////////////////////// nav tabs
index ab710fc..c1f67a3 100644 (file)
@@ -11,9 +11,6 @@
 
 require_once 'plc_drupal.php';
 
-$PENDING_CONSORTIUM_ID = 0;
-$APPROVED_CONSORTIUM_ID = 999999;
-
 if (!function_exists('drupal_page_header')) {
   $title = drupal_get_title();
   $head = drupal_get_html_head();
index 0540bf1..ce7b309 100644 (file)
@@ -19,24 +19,46 @@ include 'plc_header.php';
 require_once 'plc_functions.php';
 require_once 'details.php';
 require_once 'nifty.php';
+require_once 'table.php';
+require_once 'nifty.php';
 
 include 'site_form.php';
 
 ////////////////////////////////////////
 function render_all_join_requests($api) {
-  $sites = $api->GetSites( array("enabled" => False, "peer_id" => NULL, "ext_consortium_id" => $PENDING_CONSORTIUM_ID));
-  if (!empty($sites)) {
-    print("<table width=100%>");
-    print("<tr><th>Site Name</th><th>site_id</th><th>Submitted</th></tr>");
-    foreach($sites as $site) {
-      printf("<tr><td><a href=/db/sites/join_request.php?review=t&site_id=%d> %s </a> </td>", $site['site_id'], $site['name']);
-      printf("<td><a href=/db/sites/join_request.php?review=t&site_id=%d> %d </a> </td>", $site['site_id'], $site['site_id']);
-      printf("<td> %s </td> </tr>", date("d F Y, G:i",$site['date_created']));
-    }
-    print("</table>");
-  } else {
+  global $PENDING_CONSORTIUM_ID;
+  $filter = array("peer_id" => NULL, "ext_consortium_id" => $PENDING_CONSORTIUM_ID);
+  $columns=array('site_id','name','enabled','date_created');
+  $sites = $api->GetSites( $filter, $columns);
+  if (empty($sites)) {
     print("<p> No open join requests </p>");
+    return;
   }
+  $headers = array();
+  $headers['id']='int';
+  $headers['Site Name']='string';
+  # trying the sortEnglishDateTime stuff - not too lucky so far
+  # http://www.frequency-decoder.com/demo/table-sort-revisited/custom-sort-functions/
+  $headers['submitted']='sortEnglishDateTime';
+  $headers['enabled']='string';
+  
+  $nifty=new PlekitNifty ('pending','sites-pending','medium');
+  $nifty->start();
+  $table=new PlekitTable ('pending',$headers,2,
+                         array('pagesize_area'=>FALSE,'pagesize'=>10000));
+  $table->start();
+  foreach($sites as $site) {
+    $site_id=$site['site_id'];
+    $link = $site['enabled'] ? l_site($site_id) : l_site_review_pending($site_id);
+    $table->row_start();
+    $table->cell(href($link,$site['site_id']));
+    $table->cell(href($link,$site['name']));
+    $table->cell(date("dS F Y",$site['date_created']) . " at " . date("G:i",$site['date_created']));
+    $table->cell( $site['enabled'] ? plc_warning_html('yes') : 'no');
+    $table->row_end();
+  }
+  $table->end();
+  $nifty->end();
 }
 
 function render_join_request_review($api, $site_id) {
@@ -52,11 +74,13 @@ function render_join_request_review($api, $site_id) {
   }
   $addresses = $api->GetAddresses ($site['address_ids']);
   if (empty ($addresses)) {
-      print("<p class='plc-warning'> No address found for site_id=$site_id</p> ");
-      return ;
+    drupal_set_message("Site $site_id has no address - never mind");
+    $address=array('line1'=>'');
+    $address_id=0;
+  } else {
+    $address = $addresses[0];
+    $address_id=$address['address_id'];
   }
-  $address = $addresses[0];
-  $address_id=$address['address_id'];
 # just in case there is no person attached yet
   if (empty ($site['person_ids'])) {
     $persons=array();
@@ -87,6 +111,7 @@ function render_join_request_review($api, $site_id) {
 <input type="hidden" name="site_id" value="$site_id">
 EOF;
 
+  // don't render the tech part if that was the same as the pi
   $site_form = build_site_form(FALSE);
   $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
   
@@ -215,9 +240,9 @@ else if ($_POST['submitted'] )
     case 'Update': {
       $api->begin();
       $api->UpdateSite($site_id,$site);
-      $api->UpdateAddress($address_id,$address);
+      if ($address_id) $api->UpdateAddress($address_id,$address);
       $api->UpdatePerson($pi_id,$pi);
-      $api->UpdatePerson($tech_id,$tech);
+      if ($tech_id != $pi_id) $api->UpdatePerson($tech_id,$tech);
       $api->commit();
       $api_error=$api->error();
       if (!empty($api_error)) {
@@ -234,6 +259,7 @@ else if ($_POST['submitted'] )
       // the PI's email address, which makes the whole thing *a lot* simpler
       // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
       $site['enabled'] = True;
+      global $APPROVED_CONSORTIUM_ID;
       $site['ext_consortium_id'] = $APPROVED_CONSORTIUM_ID;
       $api->UpdateSite ($site_id,$site);
       $api_error=$api->error();
@@ -241,10 +267,10 @@ else if ($_POST['submitted'] )
        $error .= $api->error();
        $messages [] = "Could not enable site";
       } else {
-       $messages[] = "Site " . $site['name'] . " enabled";
+       $messages[] = l_site_t ($site_id,"Site '" . $site['name'] . "' enabled");
       }
       
-      if (empty ($error)) {
+      if (empty ($error) && $address_id) {
        // Update Address
        $api->UpdateAddress($address_id,$address);
        $api_error=$api->error();
index 7a79eda..c9d59fc 100644 (file)
@@ -34,6 +34,11 @@ $pi=$input['pi'];
 $tech=$input['tech'];
 $address=$input['address'];
 
+# allow address to be left out
+function non_empty_address ($address) {
+  return !empty($address['line1']);
+}
+
 if (! $empty_form ) {
   // Look for missing/blank entries
   $error = form_check_required ($site_form, $input);
@@ -62,10 +67,12 @@ if (! $empty_form ) {
     
     // creating the site
     $site['enabled']=FALSE;
+    global $PENDING_CONSORTIUM_ID;
+    $site['ext_consortium_id']=$PENDING_CONSORTIUM_ID;
     $site_id=$adm->AddSite($site);
     $api_error .= $adm->error();
     if (empty($api_error)) {
-      $verboses [] = "Site created as disabled";
+      $verboses [] = "Site created as disabled, with ext_consortium_id=".$PENDING_CONSORTIUM_ID;
     } else {
       $error .= $api_error;
     }
@@ -93,12 +100,14 @@ EOF;
     $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
 
   // creating address
-    $adm->AddSiteAddress($site_id,$address);
-    $api_error = $adm->error();
-    if (empty($api_error)) {
-      $verboses [] = "Address created";
-    } else {
-      $error .= $api_error;
+    if (non_empty_address($address)) {
+      $adm->AddSiteAddress($site_id,$address);
+      $api_error = $adm->error();
+      if (empty($api_error)) {
+       $verboses [] = "Address created";
+      } else {
+       $error .= $api_error;
+      }
     }
 
     // creating PI
index ef5fe1e..807479d 100644 (file)
@@ -48,6 +48,7 @@ $max_slivers= $site['max_slivers'];
 $max_slices= $site['max_slices'];
 
 $enabled = $site['enabled'];
+$ext_consortium_id = $site ['ext_consortium_id'];
 
 // get peer 
 $peer_id= $site['peer_id'];
@@ -150,14 +151,21 @@ plekit_linetabs($tabs);
 // show gray background on foreign objects : start a <div> with proper class
 $peers->block_start ($peer_id);
 
-if ( $local_peer && ( ! $enabled ) ) {
-    if ($site['ext_consortium_id'] == $PENDING_CONSORTIUM_ID) {
-        plc_warning ("This site is not enabled - Please visit " . 
-                     href (l_sites_pending(),"this page") . 
-                     " to review pending applications.");
-    } else {
-        plc_warning ("This site is disabled.");
-    }
+// sanity checks
+if ( $local_peer ) {
+  // pending site
+  global $PENDING_CONSORTIUM_ID;
+  if ( $ext_consortium_id == $PENDING_CONSORTIUM_ID) {
+    if ( ! $enabled ) 
+      plc_warning ("This site is under pending registration - Please visit " . 
+                  href (l_sites_pending(),"this page") . 
+                  " to review pending applications.");
+    else 
+      plc_warning ("This site is pending but is also enabled - something is wrong. You should fix the issue with plcsh");
+  } else {
+    if ( ! $enabled) 
+      plc_warning ("This site is disabled.");
+  }
 }
 
 $can_update=(plc_is_admin ()  && $local_peer) || ( plc_in_site($site_id) && plc_is_pi());
index e77d781..b602b1d 100644 (file)
@@ -9,38 +9,21 @@ function build_site_form ($register_mode) {
   $form = array();
   $form['site:name'] = array('title' => 'Site name', 'required' => TRUE,
                             'maxlength' => 40, 'size' => 20,
-                            'comment' => '<strong>Site Information</strong>:');
+                            'comment' => '<strong>Site Information</strong>');
   $form['site:login_base'] = array('title' => 'Login base', 'required' => TRUE,
                                   'maxlength' => 16, 'size' => 10);
   $form['site:abbreviated_name'] = array('title' => 'Abbreviated name', 'required' => TRUE,
                                         'maxlength' => 20, 'size' => 12);
   $form['site:url'] = array('title' => 'URL', 'required' => TRUE,
                            'maxlength' => 30, 'size' => 30);
-  $form['site:latitude'] = array('title' => 'Latitude', 'required' => FALSE,
+  $form['site:latitude'] = array('title' => 'Latitude', 'required' => TRUE,
                                 'maxlength' => 10, 'size' => 10, 'type' => 'double');
-  $form['site:longitude'] = array('title' => 'Longitude', 'required' => FALSE,
+  $form['site:longitude'] = array('title' => 'Longitude', 'required' => TRUE,
                                  'maxlength' => 10, 'size' => 10, 'type' => 'double');
 
-  $form['address:line1'] = array('title' => 'Address', 'required' => TRUE,
-                                'maxlength' => 40, 'size' => 30,
-                                'comment' => '<strong>Postal address</strong>:');
-  $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE,
-                                'maxlength' => 40, 'size' => 30);
-  $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE,
-                                'maxlength' => 40, 'size' => 30);
-  $form['address:city'] = array('title' => 'City', 'required' => TRUE,
-                               'maxlength' => 20, 'size' => 20);
-  $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => TRUE,
-                                     'maxlength' => 10, 'size' => 10);
-# would have liked it *not* required but it is mandatory in the DB - sigh
-  $form['address:state'] = array('title' => 'State', 'required' => TRUE,
-                                'maxlength' => 20, 'size' => 20);
-  $form['address:country'] = array('title' => 'Country', 'required' => TRUE,
-                                  'maxlength' => 20, 'size' => 20);
-
   $form['pi:first_name'] = array('title' => 'PI First Name', 'required' => TRUE,
                                 'maxlength' => 20, 'size' => 20,
-                                'comment' => '<strong>Principal Investigator Information</strong>:');
+                                'comment' => '<strong>Principal Investigator Information</strong>');
   $form['pi:last_name'] = array('title' => 'PI Last Name', 'required' => TRUE,
                                'maxlength' => 20, 'size' => 20);
   $form['pi:title'] = array('title' => 'PI Title', 'required' => FALSE,
@@ -73,7 +56,7 @@ EOF;
 
   $form['tech:first_name'] = array('title' => 'Tech First Name', 'required' => TRUE,
                                   'maxlength' => 20, 'size' => 20,
-                                  'comment' => '<strong>Technical Contact Information</strong>:' . $fill_from_pi_button);
+                                  'comment' => '<strong>Technical Contact Information</strong>' . $fill_from_pi_button);
   $form['tech:last_name'] = array('title' => 'Tech Last Name', 'required' => TRUE,
                                  'maxlength' => 20, 'size' => 20);
   $form['tech:title'] = array('title' => 'Tech Title', 'required' => FALSE,
@@ -88,6 +71,23 @@ EOF;
     $form['tech:user-role'] = array('type' => 'boolean', 'title' => 'Need user role', 'default' => TRUE);
   }
 
+  $form['address:line1'] = array('title' => 'Address', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30,
+                                'comment' => '<strong>Postal address</strong> (can be left blank)');
+  $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30);
+  $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30);
+  $form['address:city'] = array('title' => 'City', 'required' => FALSE,
+                               'maxlength' => 20, 'size' => 20);
+  $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => FALSE,
+                                     'maxlength' => 10, 'size' => 10);
+# would have liked it *not* required but it is mandatory in the DB - sigh
+  $form['address:state'] = array('title' => 'State', 'required' => FALSE,
+                                'maxlength' => 20, 'size' => 20);
+  $form['address:country'] = array('title' => 'Country', 'required' => FALSE,
+                                  'maxlength' => 20, 'size' => 20);
+
   return $form;
 }
 
index 6b1c32d..8eb5a03 100644 (file)
@@ -50,6 +50,9 @@ function site_status ($site) {
     // check that site is enabled
     if ( ! $site['enabled']) 
       $messages [] = "Not enabled";
+    global $PENDING_CONSORTIUM_ID;
+    if ( $site['ext_consortium_id'] == $PENDING_CONSORTIUM_ID )
+      $messages [] = "Pending registration";
   
     // check that site has at least a PI and a tech
     global $api;
@@ -95,8 +98,9 @@ if (! plc_is_admin()) {
   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
   $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
  } else {
-  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "is_public",
-                       "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , 
+                       "is_public", "enabled", "ext_consortium_id",
+                       "person_ids", "max_slices", "slice_ids", "node_ids");
  }
 
 if (plc_is_admin())