Code

Backports from 2.7
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Sep 2011 08:20:53 +0000 (08:20 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Sep 2011 08:20:53 +0000 (08:20 +0000)
-Updated the dyngroup plugin, to avoid saving objects members that were collected via dyngroup as real object members.
.e.g There is a group that uses dyngroup to include all users an memberUid attribue. If we now save the group, we do not want to get this memberUid attributes saved as real properties, instead they have to stay dynamic

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.7@20996 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/addons/dyngroup/class_DynamicLdapGroup.inc
gosa-core/plugins/admin/groups/class_group.inc
gosa-core/plugins/admin/groups/generic.tpl
gosa-core/plugins/admin/ogroups/class_ogroup.inc
gosa-core/plugins/admin/ogroups/generic.tpl

index 60f05865fcbc066a6633567172a1594232260e92..bedc5eecc7d4e7b47c096665ac1f656d7e5c198b 100644 (file)
@@ -96,6 +96,19 @@ class DynamicLdapGroup extends plugin
     }
 
 
+    /*!\brief    Checks whether the given attribute is managed by this dyngroup extension or not.
+     */
+    function isAttributeDynamic($attr)
+    {
+        if($this->is_account){
+            foreach($this->labeledURIparsed as $uri){
+                if($uri['attr'] == $attr) return(TRUE);
+            }
+        }
+        return(FALSE);
+    }
+
+
     public function check ()
     {
         $messages = plugin::check();
index cab9e58ff0ef43a7969ac023baf5908cccb7cb00..b0d44f6f1e3923e7e27494b2d32a6f39f3597c3f 100644 (file)
@@ -203,7 +203,7 @@ class group extends plugin
         // Prepare lists
         $this->memberList = new sortableListing();
         $this->memberList->setDeleteable(true);
-        $this->memberList->setInstantDelete(true);
+        $this->memberList->setInstantDelete(false);
         $this->memberList->setEditable(false);
         $this->memberList->setWidth("100%");
         $this->memberList->setHeight("300px");
@@ -327,8 +327,8 @@ class group extends plugin
             foreach($this->members as $uid => $member){
                 $data[$uid] = $member;
                 $givenName = $sn = _("Unknown");
-                if(isset($member['sn'][0])) $sn = $member['sn'][0];
-                if(isset($member['givenName'][0])) $givenName = $member['givenName'][0];
+                if(isset($member['sn']) && isset($member['sn'][0])) $sn = $member['sn'][0];
+                if(isset($member['givenName']) && isset($member['givenName'][0])) $givenName = $member['givenName'][0];
                 $image = image('images/false.png');
                 if(isset($member['sn'])){
                     $image = image('plugins/users/images/select_user.png');
@@ -336,6 +336,8 @@ class group extends plugin
                 $lData[$uid] = array('data' => array($image,$sn, $givenName, $uid));
             }
             $this->memberList->setListData($data,$lData);
+            $bool = $this->isRestrictedByDynGroup();
+            $this->memberList->setDeleteable(!$bool);
             $this->memberList->update();
             $smarty->assign("memberList", $this->memberList->render());
         }else{
@@ -362,11 +364,11 @@ class group extends plugin
 
             $data = $lData = array();
             foreach($this->memberUid_used_by_some as $uid => $member){
-                $member = $this->members[$member];
+                $member = (isset($this->members[$member])) ? $this->members[$member] : NULL;
                 $data[$uid] = $member;
                 $givenName = $sn = _("Unknown");
-                if(isset($member['sn'][0])) $sn = $member['sn'][0];
-                if(isset($member['givenName'][0])) $givenName = $member['givenName'][0];
+                if(isset($member['sn']) && isset($member['sn'][0])) $sn = $member['sn'][0];
+                if(isset($member['givenName'][0]) && isset($member['givenName'][0])) $givenName = $member['givenName'][0];
                 $image = image('images/false.png');
                 if(isset($member['sn'])){
                     $image = image('plugins/users/images/select_user.png');
@@ -437,9 +439,26 @@ class group extends plugin
             }
         }
 
+        $bool = $this->isRestrictedByDynGroup();
+        $smarty->assign("restrictedByDynGroup", $bool);
+        if($bool){
+            $smarty->assign("memberUidACL", preg_replace("/[^r]/","",$this->getacl('memberUid')));
+             
+        }
         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
     }
 
+
+    function isRestrictedByDynGroup()
+    {
+        $bool = FALSE;
+        if(isset($this->parent->by_object['DynamicLdapGroup'])){
+            $bool = $this->parent->by_object['DynamicLdapGroup']->isAttributeDynamic('memberUid') ||
+                $this->parent->by_object['DynamicLdapGroup']->isAttributeDynamic('member');
+        }
+        return($bool);
+    }
+
     function addUser($uid)
     {
         /* In mutliple edit we have to handle two arrays.
@@ -794,7 +813,8 @@ class group extends plugin
         }
 
         /* Take members array */
-        if (count ($this->memberUid)){
+        
+        if (!$this->isRestrictedByDynGroup() && count ($this->memberUid)){
             $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
         }
 
@@ -808,7 +828,6 @@ class group extends plugin
             $this->attrs['member'] = array();
             if (count($this->memberUid)){
                 foreach($this->attrs['memberUid'] as $uid) {
-
                     if(isset($this->dnMapping[$uid])){
                         $this->attrs['member'][]= $this->dnMapping[$uid];
                     }
@@ -1183,7 +1202,7 @@ class group extends plugin
         //  - ond one which represents those users which are only part of SOME groups.
         $this->commonList = new sortableListing();
         $this->commonList->setDeleteable(true);
-        $this->commonList->setInstantDelete(true);
+        $this->commonList->setInstantDelete(false);
         $this->commonList->setEditable(false);
         $this->commonList->setWidth("100%");
         $this->commonList->setHeight("120px");
@@ -1193,7 +1212,7 @@ class group extends plugin
 
         $this->partialList = new sortableListing();
         $this->partialList->setDeleteable(true);
-        $this->partialList->setInstantDelete(true);
+        $this->partialList->setInstantDelete(false);
         $this->partialList->setEditable(false);
         $this->partialList->setWidth("100%");
         $this->partialList->setHeight("120px");
index 5a591fd79959a11a128343e298540bc34b4a1ef2..c2015f6f0e021b6f30137d0d47922534192e1b26 100644 (file)
    <table summary="" style="width:100%">
     <tr>
      <td style="width:50%">
-       {if $multiple_support}
-        <h3>{t}Common group members{/t}</h3>
-        {render acl=$memberUidACL}
-            {$commonList}
-        {/render}
-        {render acl=$memberUidACL}
-          <button type='submit' name='edit_membership'>{msgPool type=addButton}</button>
-        {/render}
-        
-        <br>
-        <h3>{t}Partial group members{/t}</h3>
-        {render acl=$memberUidACL}
-            {$partialList}
-        {/render}
-       {else}
-        <h3>{t}Group members{/t}</h3>
-        {render acl=$memberUidACL}
-            {$memberList}
-        {/render}
-        {render acl=$memberUidACL}
-          <button type='submit' name='edit_membership'>{msgPool type=addButton}</button>
-        {/render}
-       {/if}
+
+      {if $restrictedByDynGroup}
+        <b>{t}The group members are part of a dyn-group and cannot be managed!{/t}</b>
+        {if $multiple_support}
+            {render acl=$memberUidACL}
+                {$commonList}
+            {/render}
+        {else}
+            {render acl=$memberUidACL}
+                {$memberList}
+            {/render}
+        {/if}
+      {else}
+
+        {if $multiple_support}
+            <h3>{t}Common group members{/t}</h3>
+            {render acl=$memberUidACL}
+                {$commonList}
+            {/render}
+            {render acl=$memberUidACL}
+              <button type='submit' name='edit_membership'>{msgPool type=addButton}</button>
+            {/render}
+            
+            <br>
+            <h3>{t}Partial group members{/t}</h3>
+            {render acl=$memberUidACL}
+                {$partialList}
+            {/render}
+        {else}
+            <h3>{t}Group members{/t}</h3>
+            {render acl=$memberUidACL}
+                {$memberList}
+            {/render}
+            {render acl=$memberUidACL}
+              <button type='submit' name='edit_membership'>{msgPool type=addButton}</button>
+            {/render}
+        {/if}
+      {/if}
      </td>
     </tr> 
    </table>
index c68ac83f4794400b9ef91abd7e136b2624b591c0..cb719055c989632e07a5c4f0f0aaeae6bc304644 100644 (file)
@@ -66,7 +66,7 @@ class ogroup extends plugin
     var $view_logged = FALSE;
 
     var $copyMembers = TRUE;
-
+    var $wasDyGroup = FALSE;
     var $baseSelector;
 
     /* Already assigned Workstations. Will be hidden in selection. 
@@ -361,6 +361,17 @@ class ogroup extends plugin
             $data[$key] = $dn;
             $lData[$key] = array('data'=> array(image($image),$name));
         }
+
+        if($this->isRestrictedByDynGroup()){
+            $this->memberListing->setDeleteable(false);
+            $smarty->assign("memberACL", preg_replace("/[^r]/", "", $this->getacl("member")));
+            $smarty->assign("isRestrictedByDynGroup", TRUE);
+            
+        }else{
+            $this->memberListing->setDeleteable(true);
+            $smarty->assign("isRestrictedByDynGroup", FALSE);
+        }
+
         $this->memberListing->setListData($data,$lData);
         $this->memberListing->update();
         $smarty->assign("memberList",$this->memberListing->render());
@@ -374,6 +385,17 @@ class ogroup extends plugin
     }
 
 
+    function isRestrictedByDynGroup()
+    {
+        $bool = FALSE;
+        if(isset($this->parent->by_object['DynamicLdapGroup'])){
+            $bool = $this->parent->by_object['DynamicLdapGroup']->isAttributeDynamic('member');
+        }
+        $this->wasDyGroup |= $bool;
+        return($bool);
+    }
+
+
     function set_acl_base($base)
     {
         plugin::set_acl_base($base);
@@ -710,9 +732,11 @@ class ogroup extends plugin
         plugin::save();
 
         /* Move members to target array */
-        $this->attrs['member'] =array();
-        foreach ($this->member as $key => $desc){
-            $this->attrs['member'][]= LDAP::fix($key);
+        if(!$this->wasDyGroup && !$this->isRestrictedByDynGroup()){
+            $this->attrs['member'] =array();
+            foreach ($this->member as $key => $desc){
+                $this->attrs['member'][]= LDAP::fix($key);
+            }
         }
 
         $ldap= $this->config->get_ldap_link();
index 34b4d8c2a093a4a023097f0092f14cd49b1c5908..e99cc8ac039b7e28429582de62ade2b08aedfce1 100644 (file)
     {$trustModeDialog}
   </td>
   <td style='padding-left:10px;' class='left-border'>
+   {if $isRestrictedByDynGroup}
+   <b>{t}The group members are part of a dyn-group and cannot be managed!{/t}</b>
+    <br>
+    <br>
+    {/if}
 
    <b><LABEL for="members">{t}Member objects{/t}</LABEL></b>&nbsp;({$combinedObjects})
    <br>
 {render acl=$memberACL}
    {$memberList}
 {/render}
+{if !$isRestrictedByDynGroup}
 {render acl=$memberACL}
    <button type='submit' name='edit_membership'>{msgPool type=addButton}</button>&nbsp;
 {/render}
+{/if}
   </td>
  </tr>
 </table>