@@ -28,48 +28,48 @@ |
||
| 28 | 28 | |
| 29 | 29 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
| 30 | 30 | |
| 31 | - /** @var PluginManager */ |
|
| 32 | - private $pluginManager; |
|
| 31 | + /** @var PluginManager */ |
|
| 32 | + private $pluginManager; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
| 36 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
| 37 | - * @param string $principalPrefix |
|
| 38 | - */ |
|
| 39 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
| 40 | - \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
| 41 | - PluginManager $pluginManager, |
|
| 42 | - $principalPrefix = 'principals') { |
|
| 43 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
| 44 | - $this->pluginManager = $pluginManager; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
| 36 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
| 37 | + * @param string $principalPrefix |
|
| 38 | + */ |
|
| 39 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, |
|
| 40 | + \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, |
|
| 41 | + PluginManager $pluginManager, |
|
| 42 | + $principalPrefix = 'principals') { |
|
| 43 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
| 44 | + $this->pluginManager = $pluginManager; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * This method returns a node for a principal. |
|
| 49 | - * |
|
| 50 | - * The passed array contains principal information, and is guaranteed to |
|
| 51 | - * at least contain a uri item. Other properties may or may not be |
|
| 52 | - * supplied by the authentication backend. |
|
| 53 | - * |
|
| 54 | - * @param array $principal |
|
| 55 | - * |
|
| 56 | - * @return \Sabre\DAV\INode |
|
| 57 | - */ |
|
| 58 | - function getChildForPrincipal(array $principal) { |
|
| 59 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager); |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * This method returns a node for a principal. |
|
| 49 | + * |
|
| 50 | + * The passed array contains principal information, and is guaranteed to |
|
| 51 | + * at least contain a uri item. Other properties may or may not be |
|
| 52 | + * supplied by the authentication backend. |
|
| 53 | + * |
|
| 54 | + * @param array $principal |
|
| 55 | + * |
|
| 56 | + * @return \Sabre\DAV\INode |
|
| 57 | + */ |
|
| 58 | + function getChildForPrincipal(array $principal) { |
|
| 59 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->pluginManager); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - function getName() { |
|
| 62 | + function getName() { |
|
| 63 | 63 | |
| 64 | - if ($this->principalPrefix === 'principals') { |
|
| 65 | - return parent::getName(); |
|
| 66 | - } |
|
| 67 | - // Grabbing all the components of the principal path. |
|
| 68 | - $parts = explode('/', $this->principalPrefix); |
|
| 64 | + if ($this->principalPrefix === 'principals') { |
|
| 65 | + return parent::getName(); |
|
| 66 | + } |
|
| 67 | + // Grabbing all the components of the principal path. |
|
| 68 | + $parts = explode('/', $this->principalPrefix); |
|
| 69 | 69 | |
| 70 | - // We are only interested in the second part. |
|
| 71 | - return $parts[1]; |
|
| 70 | + // We are only interested in the second part. |
|
| 71 | + return $parts[1]; |
|
| 72 | 72 | |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | } |
@@ -37,82 +37,82 @@ |
||
| 37 | 37 | |
| 38 | 38 | class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { |
| 39 | 39 | |
| 40 | - /** @var IL10N */ |
|
| 41 | - protected $l10n; |
|
| 42 | - |
|
| 43 | - /** @var IConfig */ |
|
| 44 | - protected $config; |
|
| 45 | - |
|
| 46 | - /** @var PluginManager */ |
|
| 47 | - private $pluginManager; |
|
| 48 | - |
|
| 49 | - public function __construct(Backend\BackendInterface $carddavBackend, |
|
| 50 | - string $principalUri, |
|
| 51 | - PluginManager $pluginManager) { |
|
| 52 | - parent::__construct($carddavBackend, $principalUri); |
|
| 53 | - $this->pluginManager = $pluginManager; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Returns a list of address books |
|
| 58 | - * |
|
| 59 | - * @return array |
|
| 60 | - */ |
|
| 61 | - function getChildren() { |
|
| 62 | - if ($this->l10n === null) { |
|
| 63 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
| 64 | - } |
|
| 65 | - if ($this->config === null) { |
|
| 66 | - $this->config = \OC::$server->getConfig(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
| 70 | - $objects = array_map(function(array $addressBook) { |
|
| 71 | - if ($addressBook['principaluri'] === 'principals/system/system') { |
|
| 72 | - return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
| 76 | - }, $addressBooks); |
|
| 77 | - foreach ($this->pluginManager->getAddressBookPlugins() as $plugin) { |
|
| 78 | - $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
| 79 | - } |
|
| 80 | - return $objects; |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function createExtendedCollection($name, MkCol $mkCol) { |
|
| 85 | - if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
| 86 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - parent::createExtendedCollection($name, $mkCol); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Returns a list of ACE's for this node. |
|
| 94 | - * |
|
| 95 | - * Each ACE has the following properties: |
|
| 96 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 97 | - * currently the only supported privileges |
|
| 98 | - * * 'principal', a url to the principal who owns the node |
|
| 99 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 100 | - * be updated. |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - function getACL() { |
|
| 105 | - |
|
| 106 | - $acl = parent::getACL(); |
|
| 107 | - if ($this->principalUri === 'principals/system/system') { |
|
| 108 | - $acl[] = [ |
|
| 109 | - 'privilege' => '{DAV:}read', |
|
| 110 | - 'principal' => '{DAV:}authenticated', |
|
| 111 | - 'protected' => true, |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $acl; |
|
| 116 | - } |
|
| 40 | + /** @var IL10N */ |
|
| 41 | + protected $l10n; |
|
| 42 | + |
|
| 43 | + /** @var IConfig */ |
|
| 44 | + protected $config; |
|
| 45 | + |
|
| 46 | + /** @var PluginManager */ |
|
| 47 | + private $pluginManager; |
|
| 48 | + |
|
| 49 | + public function __construct(Backend\BackendInterface $carddavBackend, |
|
| 50 | + string $principalUri, |
|
| 51 | + PluginManager $pluginManager) { |
|
| 52 | + parent::__construct($carddavBackend, $principalUri); |
|
| 53 | + $this->pluginManager = $pluginManager; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Returns a list of address books |
|
| 58 | + * |
|
| 59 | + * @return array |
|
| 60 | + */ |
|
| 61 | + function getChildren() { |
|
| 62 | + if ($this->l10n === null) { |
|
| 63 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
| 64 | + } |
|
| 65 | + if ($this->config === null) { |
|
| 66 | + $this->config = \OC::$server->getConfig(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
| 70 | + $objects = array_map(function(array $addressBook) { |
|
| 71 | + if ($addressBook['principaluri'] === 'principals/system/system') { |
|
| 72 | + return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return new AddressBook($this->carddavBackend, $addressBook, $this->l10n); |
|
| 76 | + }, $addressBooks); |
|
| 77 | + foreach ($this->pluginManager->getAddressBookPlugins() as $plugin) { |
|
| 78 | + $plugin->fetchAllForAddressBookHome($this->principalUri); |
|
| 79 | + } |
|
| 80 | + return $objects; |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function createExtendedCollection($name, MkCol $mkCol) { |
|
| 85 | + if (ExternalAddressBook::doesViolateReservedName($name)) { |
|
| 86 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + parent::createExtendedCollection($name, $mkCol); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Returns a list of ACE's for this node. |
|
| 94 | + * |
|
| 95 | + * Each ACE has the following properties: |
|
| 96 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 97 | + * currently the only supported privileges |
|
| 98 | + * * 'principal', a url to the principal who owns the node |
|
| 99 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 100 | + * be updated. |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + function getACL() { |
|
| 105 | + |
|
| 106 | + $acl = parent::getACL(); |
|
| 107 | + if ($this->principalUri === 'principals/system/system') { |
|
| 108 | + $acl[] = [ |
|
| 109 | + 'privilege' => '{DAV:}read', |
|
| 110 | + 'principal' => '{DAV:}authenticated', |
|
| 111 | + 'protected' => true, |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return $acl; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | } |
@@ -11,43 +11,43 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | interface IAddressBookProvider { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Provides the appId of the plugin |
|
| 16 | - * |
|
| 17 | - * @since 19.0.0 |
|
| 18 | - * @return string AppId |
|
| 19 | - */ |
|
| 20 | - public function getAppId(): string; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Fetches all address books for a given principal uri |
|
| 24 | - * |
|
| 25 | - * @since 19.0.0 |
|
| 26 | - * @param string $principalUri E.g. principals/users/user1 |
|
| 27 | - * @return ExternalAddressBook[] Array of all address books |
|
| 28 | - */ |
|
| 29 | - public function fetchAllForAddressBookHome(string $principalUri): array; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Checks whether plugin has an address book for a given principalUri and URI |
|
| 33 | - * |
|
| 34 | - * @since 19.0.0 |
|
| 35 | - * @param string $principalUri E.g. principals/users/user1 |
|
| 36 | - * @param string $uri E.g. personal |
|
| 37 | - * @return bool True if address book for principalUri and URI exists, false otherwise |
|
| 38 | - */ |
|
| 39 | - public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Fetches an address book for a given principalUri and URI |
|
| 43 | - * Returns null if address book does not exist |
|
| 44 | - * |
|
| 45 | - * @param string $principalUri E.g. principals/users/user1 |
|
| 46 | - * @param string $uri E.g. personal |
|
| 47 | - * |
|
| 48 | - * @return ExternalAddressBook|null address book if it exists, null otherwise |
|
| 49 | - *@since 19.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook; |
|
| 14 | + /** |
|
| 15 | + * Provides the appId of the plugin |
|
| 16 | + * |
|
| 17 | + * @since 19.0.0 |
|
| 18 | + * @return string AppId |
|
| 19 | + */ |
|
| 20 | + public function getAppId(): string; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Fetches all address books for a given principal uri |
|
| 24 | + * |
|
| 25 | + * @since 19.0.0 |
|
| 26 | + * @param string $principalUri E.g. principals/users/user1 |
|
| 27 | + * @return ExternalAddressBook[] Array of all address books |
|
| 28 | + */ |
|
| 29 | + public function fetchAllForAddressBookHome(string $principalUri): array; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Checks whether plugin has an address book for a given principalUri and URI |
|
| 33 | + * |
|
| 34 | + * @since 19.0.0 |
|
| 35 | + * @param string $principalUri E.g. principals/users/user1 |
|
| 36 | + * @param string $uri E.g. personal |
|
| 37 | + * @return bool True if address book for principalUri and URI exists, false otherwise |
|
| 38 | + */ |
|
| 39 | + public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Fetches an address book for a given principalUri and URI |
|
| 43 | + * Returns null if address book does not exist |
|
| 44 | + * |
|
| 45 | + * @param string $principalUri E.g. principals/users/user1 |
|
| 46 | + * @param string $uri E.g. personal |
|
| 47 | + * |
|
| 48 | + * @return ExternalAddressBook|null address book if it exists, null otherwise |
|
| 49 | + *@since 19.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook; |
|
| 52 | 52 | |
| 53 | 53 | } |
@@ -12,102 +12,102 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { |
| 14 | 14 | |
| 15 | - /** @var string */ |
|
| 16 | - private const PREFIX = 'app-generated'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var string |
|
| 20 | - * |
|
| 21 | - * Double dash is a valid delimiter, |
|
| 22 | - * because it will always split the URIs correctly: |
|
| 23 | - * - our prefix contains only one dash and won't be split |
|
| 24 | - * - appIds are not allowed to contain dashes as per spec: |
|
| 25 | - * > must contain only lowercase ASCII characters and underscore |
|
| 26 | - * - explode has a limit of three, so even if the app-generated |
|
| 27 | - * URI has double dashes, it won't be split |
|
| 28 | - */ |
|
| 29 | - private const DELIMITER = '--'; |
|
| 30 | - |
|
| 31 | - /** @var string */ |
|
| 32 | - private $appId; |
|
| 33 | - |
|
| 34 | - /** @var string */ |
|
| 35 | - private $uri; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param string $appId |
|
| 39 | - * @param string $uri |
|
| 40 | - */ |
|
| 41 | - public function __construct(string $appId, string $uri) { |
|
| 42 | - $this->appId = $appId; |
|
| 43 | - $this->uri = $uri; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @inheritDoc |
|
| 48 | - */ |
|
| 49 | - final public function getName() { |
|
| 50 | - return implode(self::DELIMITER, [ |
|
| 51 | - self::PREFIX, |
|
| 52 | - $this->appId, |
|
| 53 | - $this->uri, |
|
| 54 | - ]); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @inheritDoc |
|
| 59 | - */ |
|
| 60 | - final public function setName($name) { |
|
| 61 | - throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @inheritDoc |
|
| 66 | - */ |
|
| 67 | - final public function createDirectory($name) { |
|
| 68 | - throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Checks whether the address book uri is app-generated |
|
| 74 | - * |
|
| 75 | - * @param string $uri |
|
| 76 | - * |
|
| 77 | - * @return bool |
|
| 78 | - */ |
|
| 79 | - public static function isAppGeneratedAddressBook(string $uri): bool { |
|
| 80 | - return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Splits an app-generated uri into appId and uri |
|
| 85 | - * |
|
| 86 | - * @param string $uri |
|
| 87 | - * |
|
| 88 | - * @return array |
|
| 89 | - */ |
|
| 90 | - public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
| 91 | - $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
| 92 | - // Check the array has expected amount of elements |
|
| 93 | - // and none of them is an empty string |
|
| 94 | - if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
| 95 | - throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $array; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Checks whether a address book name the user wants to create violates |
|
| 103 | - * the reserved name for URIs |
|
| 104 | - * |
|
| 105 | - * @param string $uri |
|
| 106 | - * |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - public static function doesViolateReservedName(string $uri): bool { |
|
| 110 | - return strpos($uri, self::PREFIX) === 0; |
|
| 111 | - } |
|
| 15 | + /** @var string */ |
|
| 16 | + private const PREFIX = 'app-generated'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var string |
|
| 20 | + * |
|
| 21 | + * Double dash is a valid delimiter, |
|
| 22 | + * because it will always split the URIs correctly: |
|
| 23 | + * - our prefix contains only one dash and won't be split |
|
| 24 | + * - appIds are not allowed to contain dashes as per spec: |
|
| 25 | + * > must contain only lowercase ASCII characters and underscore |
|
| 26 | + * - explode has a limit of three, so even if the app-generated |
|
| 27 | + * URI has double dashes, it won't be split |
|
| 28 | + */ |
|
| 29 | + private const DELIMITER = '--'; |
|
| 30 | + |
|
| 31 | + /** @var string */ |
|
| 32 | + private $appId; |
|
| 33 | + |
|
| 34 | + /** @var string */ |
|
| 35 | + private $uri; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param string $appId |
|
| 39 | + * @param string $uri |
|
| 40 | + */ |
|
| 41 | + public function __construct(string $appId, string $uri) { |
|
| 42 | + $this->appId = $appId; |
|
| 43 | + $this->uri = $uri; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @inheritDoc |
|
| 48 | + */ |
|
| 49 | + final public function getName() { |
|
| 50 | + return implode(self::DELIMITER, [ |
|
| 51 | + self::PREFIX, |
|
| 52 | + $this->appId, |
|
| 53 | + $this->uri, |
|
| 54 | + ]); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @inheritDoc |
|
| 59 | + */ |
|
| 60 | + final public function setName($name) { |
|
| 61 | + throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @inheritDoc |
|
| 66 | + */ |
|
| 67 | + final public function createDirectory($name) { |
|
| 68 | + throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Checks whether the address book uri is app-generated |
|
| 74 | + * |
|
| 75 | + * @param string $uri |
|
| 76 | + * |
|
| 77 | + * @return bool |
|
| 78 | + */ |
|
| 79 | + public static function isAppGeneratedAddressBook(string $uri): bool { |
|
| 80 | + return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Splits an app-generated uri into appId and uri |
|
| 85 | + * |
|
| 86 | + * @param string $uri |
|
| 87 | + * |
|
| 88 | + * @return array |
|
| 89 | + */ |
|
| 90 | + public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
| 91 | + $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
| 92 | + // Check the array has expected amount of elements |
|
| 93 | + // and none of them is an empty string |
|
| 94 | + if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
| 95 | + throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $array; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Checks whether a address book name the user wants to create violates |
|
| 103 | + * the reserved name for URIs |
|
| 104 | + * |
|
| 105 | + * @param string $uri |
|
| 106 | + * |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + public static function doesViolateReservedName(string $uri): bool { |
|
| 110 | + return strpos($uri, self::PREFIX) === 0; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |
@@ -42,264 +42,264 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class PluginManager { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var ServerContainer |
|
| 47 | - */ |
|
| 48 | - private $container; |
|
| 45 | + /** |
|
| 46 | + * @var ServerContainer |
|
| 47 | + */ |
|
| 48 | + private $container; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var IAppManager |
|
| 52 | - */ |
|
| 53 | - private $appManager; |
|
| 50 | + /** |
|
| 51 | + * @var IAppManager |
|
| 52 | + */ |
|
| 53 | + private $appManager; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * App plugins |
|
| 57 | - * |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - private $plugins = null; |
|
| 55 | + /** |
|
| 56 | + * App plugins |
|
| 57 | + * |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + private $plugins = null; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * App collections |
|
| 64 | - * |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - private $collections = null; |
|
| 62 | + /** |
|
| 63 | + * App collections |
|
| 64 | + * |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + private $collections = null; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Address book plugins |
|
| 71 | - * |
|
| 72 | - * @var IAddressBookProvider[]|null |
|
| 73 | - */ |
|
| 74 | - private $addressBookPlugins = null; |
|
| 69 | + /** |
|
| 70 | + * Address book plugins |
|
| 71 | + * |
|
| 72 | + * @var IAddressBookProvider[]|null |
|
| 73 | + */ |
|
| 74 | + private $addressBookPlugins = null; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Calendar plugins |
|
| 78 | - * |
|
| 79 | - * @var array |
|
| 80 | - */ |
|
| 81 | - private $calendarPlugins = null; |
|
| 76 | + /** |
|
| 77 | + * Calendar plugins |
|
| 78 | + * |
|
| 79 | + * @var array |
|
| 80 | + */ |
|
| 81 | + private $calendarPlugins = null; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Contstruct a PluginManager |
|
| 85 | - * |
|
| 86 | - * @param ServerContainer $container server container for resolving plugin classes |
|
| 87 | - * @param IAppManager $appManager app manager to loading apps and their info |
|
| 88 | - */ |
|
| 89 | - public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
| 90 | - $this->container = $container; |
|
| 91 | - $this->appManager = $appManager; |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * Contstruct a PluginManager |
|
| 85 | + * |
|
| 86 | + * @param ServerContainer $container server container for resolving plugin classes |
|
| 87 | + * @param IAppManager $appManager app manager to loading apps and their info |
|
| 88 | + */ |
|
| 89 | + public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
| 90 | + $this->container = $container; |
|
| 91 | + $this->appManager = $appManager; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Returns an array of app-registered plugins |
|
| 96 | - * |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - public function getAppPlugins() { |
|
| 100 | - if (null === $this->plugins) { |
|
| 101 | - $this->populate(); |
|
| 102 | - } |
|
| 103 | - return $this->plugins; |
|
| 104 | - } |
|
| 94 | + /** |
|
| 95 | + * Returns an array of app-registered plugins |
|
| 96 | + * |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + public function getAppPlugins() { |
|
| 100 | + if (null === $this->plugins) { |
|
| 101 | + $this->populate(); |
|
| 102 | + } |
|
| 103 | + return $this->plugins; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Returns an array of app-registered collections |
|
| 108 | - * |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - public function getAppCollections() { |
|
| 112 | - if (null === $this->collections) { |
|
| 113 | - $this->populate(); |
|
| 114 | - } |
|
| 115 | - return $this->collections; |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * Returns an array of app-registered collections |
|
| 108 | + * |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + public function getAppCollections() { |
|
| 112 | + if (null === $this->collections) { |
|
| 113 | + $this->populate(); |
|
| 114 | + } |
|
| 115 | + return $this->collections; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @return IAddressBookProvider[] |
|
| 120 | - */ |
|
| 121 | - public function getAddressBookPlugins(): array { |
|
| 122 | - if ($this->addressBookPlugins === null) { |
|
| 123 | - $this->populate(); |
|
| 124 | - } |
|
| 125 | - return $this->addressBookPlugins; |
|
| 126 | - } |
|
| 118 | + /** |
|
| 119 | + * @return IAddressBookProvider[] |
|
| 120 | + */ |
|
| 121 | + public function getAddressBookPlugins(): array { |
|
| 122 | + if ($this->addressBookPlugins === null) { |
|
| 123 | + $this->populate(); |
|
| 124 | + } |
|
| 125 | + return $this->addressBookPlugins; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Returns an array of app-registered calendar plugins |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function getCalendarPlugins():array { |
|
| 134 | - if (null === $this->calendarPlugins) { |
|
| 135 | - $this->populate(); |
|
| 136 | - } |
|
| 137 | - return $this->calendarPlugins; |
|
| 138 | - } |
|
| 128 | + /** |
|
| 129 | + * Returns an array of app-registered calendar plugins |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function getCalendarPlugins():array { |
|
| 134 | + if (null === $this->calendarPlugins) { |
|
| 135 | + $this->populate(); |
|
| 136 | + } |
|
| 137 | + return $this->calendarPlugins; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Retrieve plugin and collection list and populate attributes |
|
| 142 | - */ |
|
| 143 | - private function populate() { |
|
| 144 | - $this->plugins = []; |
|
| 145 | - $this->addressBookPlugins = []; |
|
| 146 | - $this->calendarPlugins = []; |
|
| 147 | - $this->collections = []; |
|
| 148 | - foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 149 | - // load plugins and collections from info.xml |
|
| 150 | - $info = $this->appManager->getAppInfo($app); |
|
| 151 | - if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 152 | - continue; |
|
| 153 | - } |
|
| 154 | - $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 155 | - $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 156 | - $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info)); |
|
| 157 | - $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info)); |
|
| 158 | - } |
|
| 159 | - } |
|
| 140 | + /** |
|
| 141 | + * Retrieve plugin and collection list and populate attributes |
|
| 142 | + */ |
|
| 143 | + private function populate() { |
|
| 144 | + $this->plugins = []; |
|
| 145 | + $this->addressBookPlugins = []; |
|
| 146 | + $this->calendarPlugins = []; |
|
| 147 | + $this->collections = []; |
|
| 148 | + foreach ($this->appManager->getInstalledApps() as $app) { |
|
| 149 | + // load plugins and collections from info.xml |
|
| 150 | + $info = $this->appManager->getAppInfo($app); |
|
| 151 | + if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 152 | + continue; |
|
| 153 | + } |
|
| 154 | + $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 155 | + $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 156 | + $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info)); |
|
| 157 | + $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info)); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - private function extractPluginList(array $array) { |
|
| 162 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 163 | - if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 164 | - if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 165 | - $items = $array['sabre']['plugins']['plugin']; |
|
| 166 | - if (!is_array($items)) { |
|
| 167 | - $items = [$items]; |
|
| 168 | - } |
|
| 169 | - return $items; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - return []; |
|
| 174 | - } |
|
| 161 | + private function extractPluginList(array $array) { |
|
| 162 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 163 | + if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 164 | + if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 165 | + $items = $array['sabre']['plugins']['plugin']; |
|
| 166 | + if (!is_array($items)) { |
|
| 167 | + $items = [$items]; |
|
| 168 | + } |
|
| 169 | + return $items; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + return []; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - private function extractCollectionList(array $array) { |
|
| 177 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 178 | - if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 179 | - if (isset($array['sabre']['collections']['collection'])) { |
|
| 180 | - $items = $array['sabre']['collections']['collection']; |
|
| 181 | - if (!is_array($items)) { |
|
| 182 | - $items = [$items]; |
|
| 183 | - } |
|
| 184 | - return $items; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - return []; |
|
| 189 | - } |
|
| 176 | + private function extractCollectionList(array $array) { |
|
| 177 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 178 | + if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 179 | + if (isset($array['sabre']['collections']['collection'])) { |
|
| 180 | + $items = $array['sabre']['collections']['collection']; |
|
| 181 | + if (!is_array($items)) { |
|
| 182 | + $items = [$items]; |
|
| 183 | + } |
|
| 184 | + return $items; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + return []; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * @param array $array |
|
| 193 | - * |
|
| 194 | - * @return string[] |
|
| 195 | - */ |
|
| 196 | - private function extractAddressBookPluginList(array $array): array { |
|
| 197 | - if (!isset($array['sabre']) || !is_array($array['sabre'])) { |
|
| 198 | - return []; |
|
| 199 | - } |
|
| 200 | - if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) { |
|
| 201 | - return []; |
|
| 202 | - } |
|
| 203 | - if (!isset($array['sabre']['address-book-plugins']['plugin'])) { |
|
| 204 | - return []; |
|
| 205 | - } |
|
| 191 | + /** |
|
| 192 | + * @param array $array |
|
| 193 | + * |
|
| 194 | + * @return string[] |
|
| 195 | + */ |
|
| 196 | + private function extractAddressBookPluginList(array $array): array { |
|
| 197 | + if (!isset($array['sabre']) || !is_array($array['sabre'])) { |
|
| 198 | + return []; |
|
| 199 | + } |
|
| 200 | + if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) { |
|
| 201 | + return []; |
|
| 202 | + } |
|
| 203 | + if (!isset($array['sabre']['address-book-plugins']['plugin'])) { |
|
| 204 | + return []; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $items = $array['sabre']['address-book-plugins']['plugin']; |
|
| 208 | - if (!is_array($items)) { |
|
| 209 | - $items = [$items]; |
|
| 210 | - } |
|
| 211 | - return $items; |
|
| 212 | - } |
|
| 207 | + $items = $array['sabre']['address-book-plugins']['plugin']; |
|
| 208 | + if (!is_array($items)) { |
|
| 209 | + $items = [$items]; |
|
| 210 | + } |
|
| 211 | + return $items; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - private function extractCalendarPluginList(array $array):array { |
|
| 215 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 216 | - if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) { |
|
| 217 | - if (isset($array['sabre']['calendar-plugins']['plugin'])) { |
|
| 218 | - $items = $array['sabre']['calendar-plugins']['plugin']; |
|
| 219 | - if (!is_array($items)) { |
|
| 220 | - $items = [$items]; |
|
| 221 | - } |
|
| 222 | - return $items; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - return []; |
|
| 227 | - } |
|
| 214 | + private function extractCalendarPluginList(array $array):array { |
|
| 215 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 216 | + if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) { |
|
| 217 | + if (isset($array['sabre']['calendar-plugins']['plugin'])) { |
|
| 218 | + $items = $array['sabre']['calendar-plugins']['plugin']; |
|
| 219 | + if (!is_array($items)) { |
|
| 220 | + $items = [$items]; |
|
| 221 | + } |
|
| 222 | + return $items; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + return []; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
| 230 | - foreach ($plugins as $plugin) { |
|
| 231 | - try { |
|
| 232 | - $this->plugins[] = $this->container->query($plugin); |
|
| 233 | - } catch (QueryException $e) { |
|
| 234 | - if (class_exists($plugin)) { |
|
| 235 | - $this->plugins[] = new $plugin(); |
|
| 236 | - } else { |
|
| 237 | - throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } |
|
| 229 | + private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
| 230 | + foreach ($plugins as $plugin) { |
|
| 231 | + try { |
|
| 232 | + $this->plugins[] = $this->container->query($plugin); |
|
| 233 | + } catch (QueryException $e) { |
|
| 234 | + if (class_exists($plugin)) { |
|
| 235 | + $this->plugins[] = new $plugin(); |
|
| 236 | + } else { |
|
| 237 | + throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
| 244 | - foreach ($collections as $collection) { |
|
| 245 | - try { |
|
| 246 | - $this->collections[] = $this->container->query($collection); |
|
| 247 | - } catch (QueryException $e) { |
|
| 248 | - if (class_exists($collection)) { |
|
| 249 | - $this->collections[] = new $collection(); |
|
| 250 | - } else { |
|
| 251 | - throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 243 | + private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
| 244 | + foreach ($collections as $collection) { |
|
| 245 | + try { |
|
| 246 | + $this->collections[] = $this->container->query($collection); |
|
| 247 | + } catch (QueryException $e) { |
|
| 248 | + if (class_exists($collection)) { |
|
| 249 | + $this->collections[] = new $collection(); |
|
| 250 | + } else { |
|
| 251 | + throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - private function createPluginInstance(string $className) { |
|
| 258 | - try { |
|
| 259 | - return $this->container->query($className); |
|
| 260 | - } catch (QueryException $e) { |
|
| 261 | - if (class_exists($className)) { |
|
| 262 | - return new $className(); |
|
| 263 | - } |
|
| 264 | - } |
|
| 257 | + private function createPluginInstance(string $className) { |
|
| 258 | + try { |
|
| 259 | + return $this->container->query($className); |
|
| 260 | + } catch (QueryException $e) { |
|
| 261 | + if (class_exists($className)) { |
|
| 262 | + return new $className(); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - throw new \Exception("Sabre plugin class '$className' is unknown and could not be loaded"); |
|
| 267 | - } |
|
| 266 | + throw new \Exception("Sabre plugin class '$className' is unknown and could not be loaded"); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * @param string[] $plugin |
|
| 271 | - */ |
|
| 272 | - private function loadSabreAddressBookPluginsFromInfoXml(array $plugins): void { |
|
| 273 | - $providers = array_map(function(string $className): IAddressBookProvider { |
|
| 274 | - $instance = $this->createPluginInstance($className); |
|
| 275 | - if (!($instance instanceof IAddressBookProvider)) { |
|
| 276 | - throw new \Exception("Sabre address book plugin class '$className' does not implement the \OCA\DAV\CardDAV\Integration\IAddressBookProvider interface"); |
|
| 277 | - } |
|
| 278 | - return $instance; |
|
| 279 | - }, $plugins); |
|
| 280 | - foreach ($providers as $provider) { |
|
| 281 | - $this->addressBookPlugins[] = $provider; |
|
| 282 | - } |
|
| 283 | - } |
|
| 269 | + /** |
|
| 270 | + * @param string[] $plugin |
|
| 271 | + */ |
|
| 272 | + private function loadSabreAddressBookPluginsFromInfoXml(array $plugins): void { |
|
| 273 | + $providers = array_map(function(string $className): IAddressBookProvider { |
|
| 274 | + $instance = $this->createPluginInstance($className); |
|
| 275 | + if (!($instance instanceof IAddressBookProvider)) { |
|
| 276 | + throw new \Exception("Sabre address book plugin class '$className' does not implement the \OCA\DAV\CardDAV\Integration\IAddressBookProvider interface"); |
|
| 277 | + } |
|
| 278 | + return $instance; |
|
| 279 | + }, $plugins); |
|
| 280 | + foreach ($providers as $provider) { |
|
| 281 | + $this->addressBookPlugins[] = $provider; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - private function loadSabreCalendarPluginsFromInfoXml(array $calendarPlugins):void { |
|
| 286 | - foreach ($calendarPlugins as $calendarPlugin) { |
|
| 287 | - try { |
|
| 288 | - $instantiatedCalendarPlugin = $this->container->query($calendarPlugin); |
|
| 289 | - } catch (QueryException $e) { |
|
| 290 | - if (class_exists($calendarPlugin)) { |
|
| 291 | - $instantiatedCalendarPlugin = new $calendarPlugin(); |
|
| 292 | - } else { |
|
| 293 | - throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' is unknown and could not be loaded"); |
|
| 294 | - } |
|
| 295 | - } |
|
| 285 | + private function loadSabreCalendarPluginsFromInfoXml(array $calendarPlugins):void { |
|
| 286 | + foreach ($calendarPlugins as $calendarPlugin) { |
|
| 287 | + try { |
|
| 288 | + $instantiatedCalendarPlugin = $this->container->query($calendarPlugin); |
|
| 289 | + } catch (QueryException $e) { |
|
| 290 | + if (class_exists($calendarPlugin)) { |
|
| 291 | + $instantiatedCalendarPlugin = new $calendarPlugin(); |
|
| 292 | + } else { |
|
| 293 | + throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' is unknown and could not be loaded"); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - if (!($instantiatedCalendarPlugin instanceof ICalendarProvider)) { |
|
| 298 | - throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' does not implement ICalendarProvider interface"); |
|
| 299 | - } |
|
| 297 | + if (!($instantiatedCalendarPlugin instanceof ICalendarProvider)) { |
|
| 298 | + throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' does not implement ICalendarProvider interface"); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - $this->calendarPlugins[] = $instantiatedCalendarPlugin; |
|
| 302 | - } |
|
| 303 | - } |
|
| 301 | + $this->calendarPlugins[] = $instantiatedCalendarPlugin; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | 305 | } |
@@ -48,132 +48,132 @@ |
||
| 48 | 48 | |
| 49 | 49 | class RootCollection extends SimpleCollection { |
| 50 | 50 | |
| 51 | - public function __construct() { |
|
| 52 | - $config = \OC::$server->getConfig(); |
|
| 53 | - $l10n = \OC::$server->getL10N('dav'); |
|
| 54 | - $random = \OC::$server->getSecureRandom(); |
|
| 55 | - $logger = \OC::$server->getLogger(); |
|
| 56 | - $userManager = \OC::$server->getUserManager(); |
|
| 57 | - $userSession = \OC::$server->getUserSession(); |
|
| 58 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 59 | - $shareManager = \OC::$server->getShareManager(); |
|
| 60 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 61 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 62 | - $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 63 | - |
|
| 64 | - $userPrincipalBackend = new Principal( |
|
| 65 | - $userManager, |
|
| 66 | - $groupManager, |
|
| 67 | - $shareManager, |
|
| 68 | - \OC::$server->getUserSession(), |
|
| 69 | - \OC::$server->getAppManager(), |
|
| 70 | - $proxyMapper, |
|
| 71 | - \OC::$server->getConfig() |
|
| 72 | - ); |
|
| 73 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager); |
|
| 74 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 75 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 76 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 77 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 78 | - |
|
| 79 | - // setup the first level of the dav tree |
|
| 80 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 81 | - $userPrincipals->disableListing = $disableListing; |
|
| 82 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 83 | - $groupPrincipals->disableListing = $disableListing; |
|
| 84 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 85 | - $systemPrincipals->disableListing = $disableListing; |
|
| 86 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 87 | - $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 88 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 89 | - $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 93 | - $filesCollection->disableListing = $disableListing; |
|
| 94 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 95 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 96 | - $userCalendarRoot->disableListing = $disableListing; |
|
| 97 | - |
|
| 98 | - $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 99 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 100 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
| 101 | - $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 102 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 103 | - $roomCalendarRoot->disableListing = $disableListing; |
|
| 104 | - |
|
| 105 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 106 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 107 | - |
|
| 108 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 109 | - \OC::$server->getSystemTagManager(), |
|
| 110 | - \OC::$server->getUserSession(), |
|
| 111 | - $groupManager |
|
| 112 | - ); |
|
| 113 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 114 | - \OC::$server->getSystemTagManager(), |
|
| 115 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 116 | - \OC::$server->getUserSession(), |
|
| 117 | - $groupManager, |
|
| 118 | - \OC::$server->getEventDispatcher() |
|
| 119 | - ); |
|
| 120 | - $commentsCollection = new Comments\RootCollection( |
|
| 121 | - \OC::$server->getCommentsManager(), |
|
| 122 | - $userManager, |
|
| 123 | - \OC::$server->getUserSession(), |
|
| 124 | - \OC::$server->getEventDispatcher(), |
|
| 125 | - \OC::$server->getLogger() |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
| 129 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 130 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users'); |
|
| 131 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 132 | - |
|
| 133 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 134 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system'); |
|
| 135 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 136 | - |
|
| 137 | - $uploadCollection = new Upload\RootCollection( |
|
| 138 | - $userPrincipalBackend, |
|
| 139 | - 'principals/users', |
|
| 140 | - \OC::$server->query(CleanupService::class)); |
|
| 141 | - $uploadCollection->disableListing = $disableListing; |
|
| 142 | - |
|
| 143 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 144 | - $avatarCollection->disableListing = $disableListing; |
|
| 145 | - |
|
| 146 | - $appleProvisioning = new AppleProvisioningNode( |
|
| 147 | - \OC::$server->query(ITimeFactory::class)); |
|
| 148 | - |
|
| 149 | - $children = [ |
|
| 150 | - new SimpleCollection('principals', [ |
|
| 151 | - $userPrincipals, |
|
| 152 | - $groupPrincipals, |
|
| 153 | - $systemPrincipals, |
|
| 154 | - $calendarResourcePrincipals, |
|
| 155 | - $calendarRoomPrincipals]), |
|
| 156 | - $filesCollection, |
|
| 157 | - $userCalendarRoot, |
|
| 158 | - new SimpleCollection('system-calendars', [ |
|
| 159 | - $resourceCalendarRoot, |
|
| 160 | - $roomCalendarRoot, |
|
| 161 | - ]), |
|
| 162 | - $publicCalendarRoot, |
|
| 163 | - new SimpleCollection('addressbooks', [ |
|
| 164 | - $usersAddressBookRoot, |
|
| 165 | - $systemAddressBookRoot]), |
|
| 166 | - $systemTagCollection, |
|
| 167 | - $systemTagRelationsCollection, |
|
| 168 | - $commentsCollection, |
|
| 169 | - $uploadCollection, |
|
| 170 | - $avatarCollection, |
|
| 171 | - new SimpleCollection('provisioning', [ |
|
| 172 | - $appleProvisioning |
|
| 173 | - ]) |
|
| 174 | - ]; |
|
| 175 | - |
|
| 176 | - parent::__construct('root', $children); |
|
| 177 | - } |
|
| 51 | + public function __construct() { |
|
| 52 | + $config = \OC::$server->getConfig(); |
|
| 53 | + $l10n = \OC::$server->getL10N('dav'); |
|
| 54 | + $random = \OC::$server->getSecureRandom(); |
|
| 55 | + $logger = \OC::$server->getLogger(); |
|
| 56 | + $userManager = \OC::$server->getUserManager(); |
|
| 57 | + $userSession = \OC::$server->getUserSession(); |
|
| 58 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 59 | + $shareManager = \OC::$server->getShareManager(); |
|
| 60 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 61 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 62 | + $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
| 63 | + |
|
| 64 | + $userPrincipalBackend = new Principal( |
|
| 65 | + $userManager, |
|
| 66 | + $groupManager, |
|
| 67 | + $shareManager, |
|
| 68 | + \OC::$server->getUserSession(), |
|
| 69 | + \OC::$server->getAppManager(), |
|
| 70 | + $proxyMapper, |
|
| 71 | + \OC::$server->getConfig() |
|
| 72 | + ); |
|
| 73 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager); |
|
| 74 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 75 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
| 76 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 77 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 78 | + |
|
| 79 | + // setup the first level of the dav tree |
|
| 80 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 81 | + $userPrincipals->disableListing = $disableListing; |
|
| 82 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 83 | + $groupPrincipals->disableListing = $disableListing; |
|
| 84 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 85 | + $systemPrincipals->disableListing = $disableListing; |
|
| 86 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 87 | + $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 88 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 89 | + $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 93 | + $filesCollection->disableListing = $disableListing; |
|
| 94 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 95 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 96 | + $userCalendarRoot->disableListing = $disableListing; |
|
| 97 | + |
|
| 98 | + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 99 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 100 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
| 101 | + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 102 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 103 | + $roomCalendarRoot->disableListing = $disableListing; |
|
| 104 | + |
|
| 105 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 106 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 107 | + |
|
| 108 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 109 | + \OC::$server->getSystemTagManager(), |
|
| 110 | + \OC::$server->getUserSession(), |
|
| 111 | + $groupManager |
|
| 112 | + ); |
|
| 113 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 114 | + \OC::$server->getSystemTagManager(), |
|
| 115 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 116 | + \OC::$server->getUserSession(), |
|
| 117 | + $groupManager, |
|
| 118 | + \OC::$server->getEventDispatcher() |
|
| 119 | + ); |
|
| 120 | + $commentsCollection = new Comments\RootCollection( |
|
| 121 | + \OC::$server->getCommentsManager(), |
|
| 122 | + $userManager, |
|
| 123 | + \OC::$server->getUserSession(), |
|
| 124 | + \OC::$server->getEventDispatcher(), |
|
| 125 | + \OC::$server->getLogger() |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
| 129 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 130 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users'); |
|
| 131 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 132 | + |
|
| 133 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 134 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system'); |
|
| 135 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 136 | + |
|
| 137 | + $uploadCollection = new Upload\RootCollection( |
|
| 138 | + $userPrincipalBackend, |
|
| 139 | + 'principals/users', |
|
| 140 | + \OC::$server->query(CleanupService::class)); |
|
| 141 | + $uploadCollection->disableListing = $disableListing; |
|
| 142 | + |
|
| 143 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 144 | + $avatarCollection->disableListing = $disableListing; |
|
| 145 | + |
|
| 146 | + $appleProvisioning = new AppleProvisioningNode( |
|
| 147 | + \OC::$server->query(ITimeFactory::class)); |
|
| 148 | + |
|
| 149 | + $children = [ |
|
| 150 | + new SimpleCollection('principals', [ |
|
| 151 | + $userPrincipals, |
|
| 152 | + $groupPrincipals, |
|
| 153 | + $systemPrincipals, |
|
| 154 | + $calendarResourcePrincipals, |
|
| 155 | + $calendarRoomPrincipals]), |
|
| 156 | + $filesCollection, |
|
| 157 | + $userCalendarRoot, |
|
| 158 | + new SimpleCollection('system-calendars', [ |
|
| 159 | + $resourceCalendarRoot, |
|
| 160 | + $roomCalendarRoot, |
|
| 161 | + ]), |
|
| 162 | + $publicCalendarRoot, |
|
| 163 | + new SimpleCollection('addressbooks', [ |
|
| 164 | + $usersAddressBookRoot, |
|
| 165 | + $systemAddressBookRoot]), |
|
| 166 | + $systemTagCollection, |
|
| 167 | + $systemTagRelationsCollection, |
|
| 168 | + $commentsCollection, |
|
| 169 | + $uploadCollection, |
|
| 170 | + $avatarCollection, |
|
| 171 | + new SimpleCollection('provisioning', [ |
|
| 172 | + $appleProvisioning |
|
| 173 | + ]) |
|
| 174 | + ]; |
|
| 175 | + |
|
| 176 | + parent::__construct('root', $children); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | } |