From 82bb2e1d13c4b192fa4d6156e0aa1ac5597190fa Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 7 Oct 2009 11:51:01 -0400 Subject: [PATCH] Add a Turba_Driver::canAdd() method for indicating the driver's ability 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 | 15 +++++++++++++++ turba/lib/Driver/Imsp.php | 5 +++++ turba/lib/Driver/Kolab.php | 5 +++++ turba/lib/Driver/Ldap.php | 5 +++++ turba/lib/Driver/Prefs.php | 5 +++++ turba/lib/Driver/Share.php | 5 +++++ turba/lib/Driver/Sql.php | 5 +++++ turba/lib/Turba.php | 11 ++++++++--- turba/lib/base.php | 2 +- 9 files changed, 54 insertions(+), 4 deletions(-) diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index bf651b937..63792a022 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -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. diff --git a/turba/lib/Driver/Imsp.php b/turba/lib/Driver/Imsp.php index 080c3a945..c3a489418 100644 --- a/turba/lib/Driver/Imsp.php +++ b/turba/lib/Driver/Imsp.php @@ -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. */ diff --git a/turba/lib/Driver/Kolab.php b/turba/lib/Driver/Kolab.php index c468dbe05..ed285bc0b 100644 --- a/turba/lib/Driver/Kolab.php +++ b/turba/lib/Driver/Kolab.php @@ -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. */ diff --git a/turba/lib/Driver/Ldap.php b/turba/lib/Driver/Ldap.php index 3620152e2..62f0d499e 100644 --- a/turba/lib/Driver/Ldap.php +++ b/turba/lib/Driver/Ldap.php @@ -311,6 +311,11 @@ class Turba_Driver_Ldap extends Turba_Driver } } + function _canAdd() + { + return true; + } + /** * Deletes the specified entry from the LDAP directory. */ diff --git a/turba/lib/Driver/Prefs.php b/turba/lib/Driver/Prefs.php index 5eb075c84..7b9f1d0f9 100644 --- a/turba/lib/Driver/Prefs.php +++ b/turba/lib/Driver/Prefs.php @@ -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. */ diff --git a/turba/lib/Driver/Share.php b/turba/lib/Driver/Share.php index 9db465fe3..d6b25c8b5 100644 --- a/turba/lib/Driver/Share.php +++ b/turba/lib/Driver/Share.php @@ -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. */ diff --git a/turba/lib/Driver/Sql.php b/turba/lib/Driver/Sql.php index 751170c9e..4200d6df0 100644 --- a/turba/lib/Driver/Sql.php +++ b/turba/lib/Driver/Sql.php @@ -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. */ diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index 093a7fb7b..182b4936f 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -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; } } diff --git a/turba/lib/base.php b/turba/lib/base.php index b05328e9f..17677ba74 100644 --- a/turba/lib/base.php +++ b/turba/lib/base.php @@ -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]); -- 2.11.0