Filters sources based on permissions.
public static permissionsFilter ( array $in, integer $permission = Horde_Perms::READ, array $options = [] ) : array | ||
$in | array | The source list we want filtered. |
$permission | integer | The Horde_Perms::* constant we will filter on. |
$options | array | Additional options: - require_add: (boolean) Only return sources that can be added to. |
return | array | The filtered data. |
/** */ public function davGetCollections($user) { global $injector, $registry; $hordeUser = $registry->convertUsername($user, true); $dav = $injector->getInstance('Horde_Dav_Storage'); $factory = $injector->getInstance('Turba_Shares'); $books = array(); foreach (Turba::getAddressBooks(Horde_Perms::SHOW) as $id => $book) { $readOnly = false; switch ($book['type']) { // Ugly hack! There is currently no clean way to retrieve address // books that the user "owns", or to find out if a SQL/LDAP/Kolab // address book contains per-user or global contacts. case 'share': $share = $factory->getShare($id); if ($user == '-system-' && strlen($share->get('owner')) || $user != '-system-' && $hordeUser != $share->get('owner') && $hordeUser != $registry->getAuth()) { continue; } $readOnly = !$share->hasPermission($hordeUser, Horde_Perms::EDIT); break; case 'facebook': case 'favourites': case 'vbook': if ($user == '-system-') { continue; } $readOnly = true; break; default: if (!Turba::permissionsFilter(array($id => $book), Horde_Perms::EDIT)) { $readOnly = true; } break; } try { $id = $dav->getExternalCollectionId($id, 'contacts') ?: $id; } catch (Horde_Dav_Exception $e) { } $books[] = array('id' => $id, 'uri' => $id, 'principaluri' => 'principals/' . $user, '{DAV:}displayname' => $book['title'], '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(array(array('contentType' => 'text/directory', 'version' => '3.0'), array('contentType' => 'text/vcard', 'version' => '3.0'), array('contentType' => 'text/x-vcard', 'version' => '2.1'))), '{http://sabredav.org/ns}read-only' => $readOnly); } return $books; }
/** * Global variables defined: * $addSources - TODO * $attributes - (array) Attribute data from the config/attributes.php * file. * $browse_source_count - TODO * $cfgSources - TODO * $copymoveSources - TODO */ protected function _init() { global $injector, $registry, $session; /* For now, autoloading the Content_* classes depend on there being a * registry entry for the 'content' application that contains at least * the fileroot entry. */ $injector->getInstance('Horde_Autoloader')->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Content_/', $registry->get('fileroot', 'content') . '/lib/')); if (!class_exists('Content_Tagger')) { throw new Horde_Exception(_("The Content_Tagger class could not be found. Make sure the Content application is installed.")); } // Turba source and attribute configuration. $attributes = $registry->loadConfigFile('attributes.php', 'attributes', 'turba')->config['attributes']; $cfgSources = Turba::availableSources(); /* UGLY UGLY UGLY - we should NOT be using this as a global * variable all over the place. */ $GLOBALS['cfgSources'] =& $cfgSources; // See if any of our sources are configured to use Horde_Share. foreach ($cfgSources as $key => $cfg) { if (!empty($cfg['use_shares'])) { // Create a share instance. $session->set('turba', 'has_share', true); $cfgSources = Turba::getConfigFromShares($cfgSources); break; } } $GLOBALS['attributes'] = $attributes; $cfgSources = Turba::permissionsFilter($cfgSources); // Build the directory sources select widget. if (empty(Turba::$source)) { if (!(Turba::$source = $session->get('turba', 'source'))) { Turba::$source = Turba::getDefaultAddressbook(); } Turba::$source = Horde_Util::getFormData('source', Turba::$source); } $GLOBALS['browse_source_count'] = 0; foreach (Turba::getAddressBooks() as $key => $curSource) { if (!empty($curSource['browse'])) { $GLOBALS['browse_source_count']++; if (empty(Turba::$source)) { Turba::$source = $key; } } } if (empty($cfgSources[Turba::$source]['browse'])) { Turba::$source = Turba::getDefaultAddressbook(); } $session->set('turba', 'source', Turba::$source); $GLOBALS['addSources'] = Turba::getAddressBooks(Horde_Perms::EDIT, array('require_add' => true)); $GLOBALS['copymoveSources'] = $GLOBALS['addSources']; unset($GLOBALS['copymoveSources'][Turba::$source]); }