Code

Added ACL handling to license managmenet
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 29 Sep 2009 13:28:25 +0000 (13:28 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 29 Sep 2009 13:28:25 +0000 (13:28 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14390 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc
gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc
gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl
gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl

index b2cc4d6e1c6dee04ee35aa4eb5450af89b315eb4..d37719ae8062f94a9abf49350dc985a521d0c832 100644 (file)
@@ -50,10 +50,12 @@ class licenseGeneric extends plugin
         "notificationDate","licenseModel","licenseKey","maximumInstallations",
         "licensePoolId", "usedByHost","boundToHost");
 
-  function __construct(&$config, $license, $hosts = array())
+  function __construct(&$config, $dn, $license, $hosts = array())
   {
+  
     $this->config = $config;
     $this->data = $license;
+    $this->dn = $dn;
     $this->si = new opsiLicenceHandler($this->config);
     $this->opsiHosts = $hosts;
 
@@ -120,6 +122,16 @@ class licenseGeneric extends plugin
     $smarty->assign("initially_was_account", $this->initially_was_account);
     $smarty->assign("hosts", $this->getHosts());
 
+    $ui = get_userinfo();
+
+    $acl_base = $this->dn;
+    if($acl_base == "new"){
+      $acl_base = $this->config->current['BASE'];
+    }
+
+    $smarty->assign("licenseACL", $ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses"));
+    $smarty->assign("writeable", preg_match("/w/",$ui->get_permissions($acl_base,"opsi/licensePoolGeneric","licenses")));
+
     $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
     $smarty->assign("boundToHost", $this->boundToHost[0]);
     $smarty->assign("licenseKey", $this->licenseKey[0]);
index 7b70dd492b9e7dd4b327e3c5189608a1d5ecbc57..ae4e6b01af6850222724a4d453d037dec21f8d61 100644 (file)
@@ -211,13 +211,14 @@ class licensePoolGeneric extends plugin
     if($this->dialog instanceOf plugin){
       $this->dialog->save_object();
       $display = $this->dialog->execute();
-      $display.= 
-        "<p style=\"text-align:right\">
-        <input type=submit name=\"license_finish\" style=\"width:80px\"
-        value=\"".msgPool::okButton(). "\">&nbsp;
-      <input type=submit name=\"license_cancel\"
-        value=\"".msgPool::cancelButton()."\">
-        </p>";
+      $display.= "<p style=\"text-align:right\">";
+  
+      if($this->acl_is_writeable("licenses")){
+        $display.="<input type=submit name=\"license_finish\" style=\"width:80px\"
+          value=\"".msgPool::okButton(). "\">&nbsp;";
+      }
+      
+      $display.="<input type=submit name=\"license_cancel\" value=\"".msgPool::cancelButton()."\"></p>";
       return($display);
     }
 
@@ -245,19 +246,22 @@ class licensePoolGeneric extends plugin
   {
     $list = new divSelectBox("test");
     $list->setHeight(100);
-    foreach($this->licenses as $i => $license){
-      $keys = implode($license['licenseKey'],", ");
-      $link = "<input type='image' class='center' src='images/lists/edit.png' name='editLicense_{$i}'>";
-      $link.= "<input type='image' class='center' src='images/lists/trash.png' name='removeLicense_{$i}'>";
-
-      $f1 = array("string" => $license['cn']);
-      $f2 = array("string" => $license['licenseModel']);
-      $f3 = array("string" => $license['expirationDate']);
-      $f4 = array("string" => $license['maximumInstallations']);
-      $f5 = array("string" => rtrim($keys,", "));
-      $f6 = array("string" => $link, "attach" => "style='border-right: 0px; width:32px;'");
-
-      $list->addEntry(array($f1,$f2,$f3,$f4,$f5,$f6));
+
+    if($this->acl_is_readable("licenses")){
+      foreach($this->licenses as $i => $license){
+        $keys = implode($license['licenseKey'],", ");
+        $link = "<input type='image' class='center' src='images/lists/edit.png' name='editLicense_{$i}'>";
+        if(preg_match("/w/", $this->getacl("licenses"))){
+          $link.= "<input type='image' class='center' src='images/lists/trash.png' name='removeLicense_{$i}'>";
+        }
+        $f1 = array("string" => $license['cn']);
+        $f2 = array("string" => $license['licenseModel']);
+        $f3 = array("string" => $license['expirationDate']);
+        $f4 = array("string" => $license['maximumInstallations']);
+        $f5 = array("string" => rtrim($keys,", "));
+        $f6 = array("string" => $link, "attach" => "style='border-right: 0px; width:32px;'");
+        $list->addEntry(array($f1,$f2,$f3,$f4,$f5,$f6));
+      }
     }
     return($list->DrawList());
   }
@@ -296,61 +300,73 @@ class licensePoolGeneric extends plugin
       if($this->initially_was_account) $this->cn = $this->orig_cn;
 
       // We've to add prodcuts here 
-      if(isset($_POST['availableProduct']) && isset($_POST['addProduct'])){
-        $pro = get_post('availableProduct');
-        if(isset($this->availableProductIds[$pro]) && !in_array($this->availableProductIds[$pro], $this->productIds)){
-          $this->productIds[] =$this->availableProductIds[$pro];
+      if(preg_match("/w/",$this->getacl("productIds"))){
+        if(isset($_POST['availableProduct']) && isset($_POST['addProduct'])){
+          $pro = get_post('availableProduct');
+          if(isset($this->availableProductIds[$pro]) && !in_array($this->availableProductIds[$pro], $this->productIds)){
+            $this->productIds[] =$this->availableProductIds[$pro];
+          }
         }
       }
 
       // We've to remove products here
-      if(isset($_POST['productIds']) && isset($_POST['removeProduct'])){
-        foreach($_POST['productIds'] as $key){
-          if(isset($this->productIds[$key])){
-            unset($this->productIds[$key]);
+      if(preg_match("/w/",$this->getacl("productIds"))){
+        if(isset($_POST['productIds']) && isset($_POST['removeProduct'])){
+          foreach($_POST['productIds'] as $key){
+            if(isset($this->productIds[$key])){
+              unset($this->productIds[$key]);
+            }
           }
         }
       }
 
       // We've to add software here 
-      if(isset($_POST['newSoftwareId']) && isset($_POST['addSoftware'])){
-        $soft = trim(get_post('newSoftwareId'));
-        if(!empty($soft) && !in_array($soft, $this->softwareIds)){
-          $this->softwareIds[] = $soft;
+      if(preg_match("/w/",$this->getacl("windowsSoftwareIds"))){
+        if(isset($_POST['newSoftwareId']) && isset($_POST['addSoftware'])){
+          $soft = trim(get_post('newSoftwareId'));
+          if(!empty($soft) && !in_array($soft, $this->softwareIds)){
+            $this->softwareIds[] = $soft;
+          }
         }
       }
 
       // We've to remove software Ids here
-      if(isset($_POST['softwareIds']) && isset($_POST['removeSoftware'])){
-        foreach($_POST['softwareIds'] as $key){
-          if(isset($this->softwareIds[$key])){
-            unset($this->softwareIds[$key]);
+      if(preg_match("/w/",$this->getacl("windowsSoftwareIds"))){
+        if(isset($_POST['softwareIds']) && isset($_POST['removeSoftware'])){
+          foreach($_POST['softwareIds'] as $key){
+            if(isset($this->softwareIds[$key])){
+              unset($this->softwareIds[$key]);
+            }
           }
         }
       }
 
       // We've to create a new license
-      if(isset($_POST['addLicense'])){
-        $this->dialog = new licenseGeneric($this->config,array(), $this->opsiHosts);
-        $this->dialog->set_acl_base($this->config->current['BASE']);
+      if(preg_match("/w/",$this->getacl("licenses"))){
+        if(isset($_POST['addLicense'])){
+          $this->dialog = new licenseGeneric($this->config,$this->dn,array(), $this->opsiHosts);
+          $this->dialog->set_acl_base($this->config->current['BASE']);
+        }
       }
   
       // Search post for image button clicks.
-      foreach($_POST as $name => $value){
-        if(preg_match("/^editLicense_/",$name)){
-          $id = preg_replace("/^editLicense_(.*)_.$/","\\1",$name);
-          if(isset($this->licenses[$id])){
-            $this->dialog = new licenseGeneric($this->config,$this->licenses[$id], $this->opsiHosts);
-            $this->dialog->set_acl_base($this->config->current['BASE']);
+      if(preg_match("/r/",$this->getacl("licenses"))){
+        foreach($_POST as $name => $value){
+          if(preg_match("/^editLicense_/",$name)){
+            $id = preg_replace("/^editLicense_(.*)_.$/","\\1",$name);
+            if(isset($this->licenses[$id])){
+              $this->dialog = new licenseGeneric($this->config,$this->dn,$this->licenses[$id], $this->opsiHosts);
+              $this->dialog->set_acl_base($this->config->current['BASE']);
+            }
+            break;
           }
-          break;
-        }
-        if(preg_match("/^removeLicense_/",$name)){
-          $id = preg_replace("/^removeLicense_(.*)_.$/","\\1",$name);
-          if(isset($this->licenses[$id])){
-            unset($this->licenses[$id]);
+          if(preg_match("/^removeLicense_/",$name)){
+            $id = preg_replace("/^removeLicense_(.*)_.$/","\\1",$name);
+            if(isset($this->licenses[$id])){
+              unset($this->licenses[$id]);
+            }
+            break;
           }
-          break;
         }
       }
     }
@@ -478,8 +494,8 @@ class licensePoolGeneric extends plugin
   static function plInfo()
   {
     return (array(
-          "plShortName"   => _("Generic"),
-          "plDescription" => _("License generic"),
+          "plShortName"   => _("Pool generic"),
+          "plDescription" => _("License pool generic"),
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
           "plPriority"    => 1,
@@ -487,7 +503,10 @@ class licensePoolGeneric extends plugin
           "plCategory"    => array("opsi"),
           "plProvidedAcls"=> array(
             "cn"                => _("Name"),
-            "description" => _("Description"))
+            "description" => _("Description"),
+            "productIds"  => _("Applications"),
+            "windowsSoftwareIds"  => _("Windows software IDs"),
+            "licenses"  => _("Licenses"))
           ));
   }
 }
index 45dd1eb46b40e5a7d797dadfa362c9e9b81fce08..1ca85f471742ae44cd233ff07f5f6eaa66bfd222 100644 (file)
@@ -22,7 +22,9 @@
               {if $initially_was_account}
                 <input type='text' name='dummy12' disabled value='{$cn}'>
               {else}
+{render acl=$licenseACL}
                 <input type='text' name='cn' value='{$cn}'>
+{/render}
               {/if}
             </td>
           </tr>
@@ -31,7 +33,9 @@
               {t}Partner{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='partner' value='{$partner}'>
+{/render}
             </td>
           </tr>
         </table>
@@ -45,7 +49,9 @@
               {t}Description{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='description' value='{$description}'>
+{/render}
             </td>
           </tr>
         </table>
@@ -64,7 +70,9 @@
               {t}Conclusion date{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='conclusionDate' value='{$conclusionDate}'>
+{/render}
             </td>
           </tr>
           <tr>
@@ -72,7 +80,9 @@
               {t}Expiration date{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='expirationDate' value='{$expirationDate}'>
+{/render}
             </td>
           </tr>
         </table>
@@ -86,7 +96,9 @@
               {t}Notification date{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='notificationDate' value='{$notificationDate}'>
+{/render}
             </td>
           </tr>
         </table>
               {t}License key{/t}{$must}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='licenseKey' value='{$licenseKey}'>
+{/render}
             </td>
           </tr>
           {if $licenseModel == "VOLUME"}
               {t}Maximum installations{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <input type='text' name='maximumInstallations' value='{$maximumInstallations}'>
+{/render}
             </td>
           </tr>
           {/if}
               {t}Reserved for Host{/t}
             </td>
             <td>
+{render acl=$licenseACL}
               <select name='boundToHost'>
                 <option value="">{t}none{/t}</option>
                 {html_options options=$hosts selected=$boundToHost}
               </select>
+{/render}
             </td>
           </tr>
           {/if}
           <tr>
             <td colspan="2">
               <b>{t}Used by Host{/t}</b><br>
+{render acl=$licenseACL}
               <select   disabled
                 name='selectedUsedHosts[]' multiple size=4 style='width:100%;'>
                 {html_options options=$usedByHost}
               </select><br>
+{/render}
 <!--
     
       Actually we can't modify the license usage, due to a lack of functions.
index e67729f746cbc0ed836b2a9a2166df57155aa956..1afd3bc72b2783896ad509d0469016c4b987917b 100644 (file)
@@ -44,7 +44,9 @@
           <tr> 
             <td>
               {$licenses}
+{render acl=$licensesACL}
               <input type='submit' name='addLicense' value='{msgPool type=addButton}'>
+{/render}
             </td>
           </tr>
         </table>
         <table style='width:100%;'>
           <tr> 
             <td>
+{render acl=$productIdsACL}
               <select name='productIds[]' multiple size="6" style="width:100%;">
                 {html_options options=$productIds}
               </select><br>
+{/render}
+{render acl=$productIdsACL}
               <select name='availableProduct'>
                 {html_options options=$availableProductIds}
               </select>
+{/render}
+{render acl=$productIdsACL}
               <input type='submit' name='addProduct' value='{msgPool type='addButton'}'>
+{/render}
+{render acl=$productIdsACL}
               <input type='submit' name='removeProduct' value='{msgPool type='delButton'}'>
+{/render}
             </td>
           </tr>
         </table>
         <table style='width:100%;'>
           <tr> 
             <td>
+{render acl=$windowsSoftwareIdsACL}
               <select name='softwareIds[]' multiple size="6" style="width:100%;">
                 {html_options options=$softwareIds}
               </select>
+{/render}
+{render acl=$windowsSoftwareIdsACL}
               <input type='text' name='newSoftwareId' value='' size=10>
+{/render}
+{render acl=$windowsSoftwareIdsACL}
               <input type='submit' name='addSoftware' value='{msgPool type='addButton'}'>
+{/render}
+{render acl=$windowsSoftwareIdsACL}
               <input type='submit' name='removeSoftware' value='{msgPool type='delButton'}'>
+{/render}
             </td>
           </tr>
         </table>