- PIs can add/remove tech and user roles
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Mon, 5 Oct 2009 15:16:52 +0000 (15:16 +0000)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Mon, 5 Oct 2009 15:16:52 +0000 (15:16 +0000)
planetlab/persons/person.php
plekit/php/form.php

index ef4534a..7268311 100644 (file)
@@ -318,7 +318,8 @@ if ($local_peer) {
 
   if (! $roles) plc_warning ("This user has no role !");
 
-  $can_manage_roles= ($local_peer && plc_is_admin());
+  $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
+  $can_manage_roles= ( $local_peer && plc_is_admin() || $is_pi_of_the_site );
   $table_options=array("search_area"=>false,"notes_area"=>false);
 
   $headers=array("Role"=>"string");
@@ -352,7 +353,15 @@ if ($local_peer) {
     }
 
     $table->row_start();
-    $selectors=$form->role_selectors_excluding($api,$role_ids);
+    if ($is_pi_of_the_site) {
+      // pi's can only add/remove tech (40) and user (30) roles.
+        $role_ids_to_add = array_diff(array(30, 40), $role_ids);
+        if ($role_ids_to_add) {
+            $selectors=$form->role_selectors($api, $role_ids_to_add);
+        }
+    } else {
+      $selectors=$form->role_selectors_excluding($api,$role_ids);
+    }
     $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
     // add a role : the button
     $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
index 0f67002..d4ee499 100644 (file)
@@ -112,13 +112,15 @@ class PlekitForm {
       $encoded=htmlentities($options['label'],ENT_QUOTES);
       $html.="<option selected=selected value=''>$encoded</option>";
     }
-    foreach ($selectors as $selector) {
-      $display=htmlentities($selector['display'],ENT_QUOTES);
-      $value=$selector['value'];
-      $html .= "<option value='$value'";
-      if ($selector['selected']) $html .= " selected=selected";
-      if ($selector['disabled']) $html .= " disabled=disabled";
-      $html .= ">$display</option>\n";
+    if ($selectors) {
+      foreach ($selectors as $selector) {
+        $display=htmlentities($selector['display'],ENT_QUOTES);
+        $value=$selector['value'];
+        $html .= "<option value='$value'";
+        if ($selector['selected']) $html .= " selected=selected";
+        if ($selector['disabled']) $html .= " disabled=disabled";
+        $html .= ">$display</option>\n";
+      }
     }
     $html .= "</select>";
     return $html;