Add a Turba_Driver::canAdd() method for indicating the driver's ability
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 7 Oct 2009 15:51:01 +0000 (11:51 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 7 Oct 2009 15:51:01 +0000 (11:51 -0400)
to add a new contact.

Needed because we don't have perms on individual contacts, just on the
contact's address book. So for sources such as a virtual address book,
we may be able to edit the contact, but we can't add new contacts to
the address book.

turba/lib/Driver.php
turba/lib/Driver/Imsp.php
turba/lib/Driver/Kolab.php
turba/lib/Driver/Ldap.php
turba/lib/Driver/Prefs.php
turba/lib/Driver/Share.php
turba/lib/Driver/Sql.php
turba/lib/Turba.php
turba/lib/base.php

index bf651b9..63792a0 100644 (file)
@@ -793,6 +793,21 @@ class Turba_Driver
     }
 
     /**
+     * Returns ability of the backend to add new contacts.
+     *
+     * @return boolean
+     */
+    function canAdd()
+    {
+        return $this->_canAdd();
+    }
+
+    function _canAdd()
+    {
+        return false;
+    }
+
+    /**
      * Deletes the specified entry from the contact source.
      *
      * @param string $object_id  The ID of the object to delete.
index 080c3a9..c3a4894 100644 (file)
@@ -309,6 +309,11 @@ class Turba_Driver_Imsp extends Turba_Driver
         return $this->_imsp->addEntry($this->_bookName, $attributes);
     }
 
+    function _canAdd()
+    {
+        return true;
+    }
+
     /**
      * Deletes the specified object from the IMSP server.
      */
index c468dbe..ed285bc 100644 (file)
@@ -92,6 +92,11 @@ class Turba_Driver_Kolab extends Turba_Driver
         return $this->_wrapper->_add($attributes);
     }
 
+    function _canAdd()
+    {
+        return true;
+    }
+
     /**
      * Removes the specified object from the Kolab message store.
      */
index 3620152..62f0d49 100644 (file)
@@ -311,6 +311,11 @@ class Turba_Driver_Ldap extends Turba_Driver
         }
     }
 
+    function _canAdd()
+    {
+        return true;
+    }
+
     /**
      * Deletes the specified entry from the LDAP directory.
      */
index 5eb075c..7b9f1d0 100644 (file)
@@ -67,6 +67,11 @@ class Turba_Driver_Prefs extends Turba_Driver
         return true;
     }
 
+    public function _canAdd()
+    {
+        return true;
+    }
+
     /**
      * Deletes the specified object from the preferences.
      */
index 9db465f..d6b25c8 100644 (file)
@@ -127,6 +127,11 @@ class Turba_Driver_Share extends Turba_Driver
         return $this->_driver->_add($attributes, $blob_fields);
     }
 
+    function _canAdd()
+    {
+        return $this->_driver->canAdd();
+    }
+
     /**
      * Deletes the specified object from the SQL database.
      */
index 751170c..4200d6d 100644 (file)
@@ -303,6 +303,11 @@ class Turba_Driver_Sql extends Turba_Driver
         return true;
     }
 
+    function canAdd()
+    {
+        return true;
+    }
+
     /**
      * Deletes the specified object from the SQL database.
      */
index 093a7fb..182b493 100644 (file)
@@ -88,10 +88,11 @@ class Turba {
      * return them in the user's preferred order.
      *
      * @param integer $permission  The PERMS_* constant to filter on.
+     * @param array $options       Any additional options.
      *
      * @return array  The filtered, ordered $cfgSources entries.
      */
-    function getAddressBooks($permission = PERMS_READ)
+    function getAddressBooks($permission = PERMS_READ, $options = array())
     {
         $addressbooks = array();
         foreach (array_keys(Turba::getAddressBookOrder()) as $addressbook) {
@@ -102,7 +103,7 @@ class Turba {
             $addressbooks = $GLOBALS['cfgSources'];
         }
 
-        return Turba::permissionsFilter($addressbooks, $permission);
+        return Turba::permissionsFilter($addressbooks, $permission, $options);
     }
 
     /**
@@ -319,10 +320,11 @@ class Turba {
      * @param array $in            The data we want filtered.
      * @param string $filter       What type of data we are filtering.
      * @param integer $permission  The PERMS_* constant we will filter on.
+     * @param array $options       Additional options.
      *
      * @return array  The filtered data.
      */
-    function permissionsFilter($in, $permission = PERMS_READ)
+    function permissionsFilter($in, $permission = PERMS_READ, $options = array())
     {
         $out = array();
 
@@ -334,6 +336,9 @@ class Turba {
             }
 
             if ($driver->hasPermission($permission)) {
+                if (!empty($options['require_add']) && !$driver->canAdd()) {
+                    continue;
+                }
                 $out[$sourceId] = $source;
             }
         }
index b05328e..17677ba 100644 (file)
@@ -85,7 +85,7 @@ $_SESSION['turba']['source'] = $default_source;
 
 // Only set $add_source_options if there is at least one editable address book
 // that is not the current address book.
-$addSources = Turba::getAddressBooks(PERMS_EDIT);
+$addSources = Turba::getAddressBooks(PERMS_EDIT, array('require_add' => true));
 $copymove_source_options = '';
 $copymoveSources = $addSources;
 unset($copymoveSources[$default_source]);