@@ -39,7 +39,7 @@ |
||
| 39 | 39 | |
| 40 | 40 | public function xmlSerialize(Writer $writer) { |
| 41 | 41 | foreach ($this->groups as $group) { |
| 42 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 42 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}group', $group); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -11,19 +11,19 @@ |
||
| 11 | 11 | use Sabre\Xml\XmlSerializable; |
| 12 | 12 | |
| 13 | 13 | class Groups implements XmlSerializable { |
| 14 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 14 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param list<string> $groups |
|
| 18 | - */ |
|
| 19 | - public function __construct( |
|
| 20 | - private array $groups, |
|
| 21 | - ) { |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * @param list<string> $groups |
|
| 18 | + */ |
|
| 19 | + public function __construct( |
|
| 20 | + private array $groups, |
|
| 21 | + ) { |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function xmlSerialize(Writer $writer) { |
|
| 25 | - foreach ($this->groups as $group) { |
|
| 26 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 27 | - } |
|
| 28 | - } |
|
| 24 | + public function xmlSerialize(Writer $writer) { |
|
| 25 | + foreach ($this->groups as $group) { |
|
| 26 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -116,42 +116,42 @@ |
||
| 116 | 116 | * @return void |
| 117 | 117 | */ |
| 118 | 118 | public function xmlSerialize(Writer $writer) { |
| 119 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 119 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
| 120 | 120 | |
| 121 | 121 | if (!is_null($this->organizer)) { |
| 122 | - $writer->startElement($cs . 'organizer'); |
|
| 122 | + $writer->startElement($cs.'organizer'); |
|
| 123 | 123 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
| 124 | 124 | |
| 125 | 125 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
| 126 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 126 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
| 127 | 127 | } |
| 128 | 128 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
| 129 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 129 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
| 130 | 130 | } |
| 131 | 131 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
| 132 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 132 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
| 133 | 133 | } |
| 134 | 134 | $writer->endElement(); // organizer |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | foreach ($this->users as $user) { |
| 138 | - $writer->startElement($cs . 'user'); |
|
| 138 | + $writer->startElement($cs.'user'); |
|
| 139 | 139 | $writer->writeElement('{DAV:}href', $user['href']); |
| 140 | 140 | if (isset($user['commonName']) && $user['commonName']) { |
| 141 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 141 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
| 142 | 142 | } |
| 143 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 143 | + $writer->writeElement($cs.'invite-accepted'); |
|
| 144 | 144 | |
| 145 | - $writer->startElement($cs . 'access'); |
|
| 145 | + $writer->startElement($cs.'access'); |
|
| 146 | 146 | if ($user['readOnly']) { |
| 147 | - $writer->writeElement($cs . 'read'); |
|
| 147 | + $writer->writeElement($cs.'read'); |
|
| 148 | 148 | } else { |
| 149 | - $writer->writeElement($cs . 'read-write'); |
|
| 149 | + $writer->writeElement($cs.'read-write'); |
|
| 150 | 150 | } |
| 151 | 151 | $writer->endElement(); // access |
| 152 | 152 | |
| 153 | 153 | if (isset($user['summary']) && $user['summary']) { |
| 154 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 154 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $writer->endElement(); //user |
@@ -26,113 +26,113 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Invite implements XmlSerializable { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Creates the property. |
|
| 31 | - * |
|
| 32 | - * Users is an array. Each element of the array has the following |
|
| 33 | - * properties: |
|
| 34 | - * |
|
| 35 | - * * href - Often a mailto: address |
|
| 36 | - * * commonName - Optional, for example a first and lastname for a user. |
|
| 37 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 38 | - * * readOnly - true or false |
|
| 39 | - * * summary - Optional, description of the share |
|
| 40 | - * |
|
| 41 | - * The organizer key is optional to specify. It's only useful when a |
|
| 42 | - * 'sharee' requests the sharing information. |
|
| 43 | - * |
|
| 44 | - * The organizer may have the following properties: |
|
| 45 | - * * href - Often a mailto: address. |
|
| 46 | - * * commonName - Optional human-readable name. |
|
| 47 | - * * firstName - Optional first name. |
|
| 48 | - * * lastName - Optional last name. |
|
| 49 | - * |
|
| 50 | - * If you wonder why these two structures are so different, I guess a |
|
| 51 | - * valid answer is that the current spec is still a draft. |
|
| 52 | - * |
|
| 53 | - * @param array $users |
|
| 54 | - */ |
|
| 55 | - public function __construct( |
|
| 56 | - /** |
|
| 57 | - * The list of users a calendar has been shared to. |
|
| 58 | - */ |
|
| 59 | - protected array $users, |
|
| 60 | - /** |
|
| 61 | - * The organizer contains information about the person who shared the |
|
| 62 | - * object. |
|
| 63 | - */ |
|
| 64 | - protected ?array $organizer = null, |
|
| 65 | - ) { |
|
| 66 | - } |
|
| 29 | + /** |
|
| 30 | + * Creates the property. |
|
| 31 | + * |
|
| 32 | + * Users is an array. Each element of the array has the following |
|
| 33 | + * properties: |
|
| 34 | + * |
|
| 35 | + * * href - Often a mailto: address |
|
| 36 | + * * commonName - Optional, for example a first and lastname for a user. |
|
| 37 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 38 | + * * readOnly - true or false |
|
| 39 | + * * summary - Optional, description of the share |
|
| 40 | + * |
|
| 41 | + * The organizer key is optional to specify. It's only useful when a |
|
| 42 | + * 'sharee' requests the sharing information. |
|
| 43 | + * |
|
| 44 | + * The organizer may have the following properties: |
|
| 45 | + * * href - Often a mailto: address. |
|
| 46 | + * * commonName - Optional human-readable name. |
|
| 47 | + * * firstName - Optional first name. |
|
| 48 | + * * lastName - Optional last name. |
|
| 49 | + * |
|
| 50 | + * If you wonder why these two structures are so different, I guess a |
|
| 51 | + * valid answer is that the current spec is still a draft. |
|
| 52 | + * |
|
| 53 | + * @param array $users |
|
| 54 | + */ |
|
| 55 | + public function __construct( |
|
| 56 | + /** |
|
| 57 | + * The list of users a calendar has been shared to. |
|
| 58 | + */ |
|
| 59 | + protected array $users, |
|
| 60 | + /** |
|
| 61 | + * The organizer contains information about the person who shared the |
|
| 62 | + * object. |
|
| 63 | + */ |
|
| 64 | + protected ?array $organizer = null, |
|
| 65 | + ) { |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Returns the list of users, as it was passed to the constructor. |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - public function getValue() { |
|
| 74 | - return $this->users; |
|
| 75 | - } |
|
| 68 | + /** |
|
| 69 | + * Returns the list of users, as it was passed to the constructor. |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + public function getValue() { |
|
| 74 | + return $this->users; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The xmlSerialize method is called during xml writing. |
|
| 79 | - * |
|
| 80 | - * Use the $writer argument to write its own xml serialization. |
|
| 81 | - * |
|
| 82 | - * An important note: do _not_ create a parent element. Any element |
|
| 83 | - * implementing XmlSerializble should only ever write what's considered |
|
| 84 | - * its 'inner xml'. |
|
| 85 | - * |
|
| 86 | - * The parent of the current element is responsible for writing a |
|
| 87 | - * containing element. |
|
| 88 | - * |
|
| 89 | - * This allows serializers to be re-used for different element names. |
|
| 90 | - * |
|
| 91 | - * If you are opening new elements, you must also close them again. |
|
| 92 | - * |
|
| 93 | - * @param Writer $writer |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function xmlSerialize(Writer $writer) { |
|
| 97 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 77 | + /** |
|
| 78 | + * The xmlSerialize method is called during xml writing. |
|
| 79 | + * |
|
| 80 | + * Use the $writer argument to write its own xml serialization. |
|
| 81 | + * |
|
| 82 | + * An important note: do _not_ create a parent element. Any element |
|
| 83 | + * implementing XmlSerializble should only ever write what's considered |
|
| 84 | + * its 'inner xml'. |
|
| 85 | + * |
|
| 86 | + * The parent of the current element is responsible for writing a |
|
| 87 | + * containing element. |
|
| 88 | + * |
|
| 89 | + * This allows serializers to be re-used for different element names. |
|
| 90 | + * |
|
| 91 | + * If you are opening new elements, you must also close them again. |
|
| 92 | + * |
|
| 93 | + * @param Writer $writer |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function xmlSerialize(Writer $writer) { |
|
| 97 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 98 | 98 | |
| 99 | - if (!is_null($this->organizer)) { |
|
| 100 | - $writer->startElement($cs . 'organizer'); |
|
| 101 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 99 | + if (!is_null($this->organizer)) { |
|
| 100 | + $writer->startElement($cs . 'organizer'); |
|
| 101 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 102 | 102 | |
| 103 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 104 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 105 | - } |
|
| 106 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 107 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 108 | - } |
|
| 109 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 110 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 111 | - } |
|
| 112 | - $writer->endElement(); // organizer |
|
| 113 | - } |
|
| 103 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 104 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 105 | + } |
|
| 106 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 107 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 108 | + } |
|
| 109 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 110 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 111 | + } |
|
| 112 | + $writer->endElement(); // organizer |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - foreach ($this->users as $user) { |
|
| 116 | - $writer->startElement($cs . 'user'); |
|
| 117 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
| 118 | - if (isset($user['commonName']) && $user['commonName']) { |
|
| 119 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 120 | - } |
|
| 121 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 115 | + foreach ($this->users as $user) { |
|
| 116 | + $writer->startElement($cs . 'user'); |
|
| 117 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
| 118 | + if (isset($user['commonName']) && $user['commonName']) { |
|
| 119 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 120 | + } |
|
| 121 | + $writer->writeElement($cs . 'invite-accepted'); |
|
| 122 | 122 | |
| 123 | - $writer->startElement($cs . 'access'); |
|
| 124 | - if ($user['readOnly']) { |
|
| 125 | - $writer->writeElement($cs . 'read'); |
|
| 126 | - } else { |
|
| 127 | - $writer->writeElement($cs . 'read-write'); |
|
| 128 | - } |
|
| 129 | - $writer->endElement(); // access |
|
| 123 | + $writer->startElement($cs . 'access'); |
|
| 124 | + if ($user['readOnly']) { |
|
| 125 | + $writer->writeElement($cs . 'read'); |
|
| 126 | + } else { |
|
| 127 | + $writer->writeElement($cs . 'read-write'); |
|
| 128 | + } |
|
| 129 | + $writer->endElement(); // access |
|
| 130 | 130 | |
| 131 | - if (isset($user['summary']) && $user['summary']) { |
|
| 132 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 133 | - } |
|
| 131 | + if (isset($user['summary']) && $user['summary']) { |
|
| 132 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $writer->endElement(); //user |
|
| 136 | - } |
|
| 137 | - } |
|
| 135 | + $writer->endElement(); //user |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | private function setupUserFs($userId) { |
| 64 | 64 | \OC_Util::setupFS($userId); |
| 65 | 65 | $this->session->close(); |
| 66 | - return $this->principalPrefix . $userId; |
|
| 66 | + return $this->principalPrefix.$userId; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | use Sabre\HTTP\ResponseInterface; |
| 17 | 17 | |
| 18 | 18 | class BearerAuth extends AbstractBearer { |
| 19 | - public function __construct( |
|
| 20 | - private IUserSession $userSession, |
|
| 21 | - private ISession $session, |
|
| 22 | - private IRequest $request, |
|
| 23 | - private IConfig $config, |
|
| 24 | - private string $principalPrefix = 'principals/users/', |
|
| 25 | - ) { |
|
| 26 | - // setup realm |
|
| 27 | - $defaults = new Defaults(); |
|
| 28 | - $this->realm = $defaults->getName() ?: 'Nextcloud'; |
|
| 29 | - } |
|
| 19 | + public function __construct( |
|
| 20 | + private IUserSession $userSession, |
|
| 21 | + private ISession $session, |
|
| 22 | + private IRequest $request, |
|
| 23 | + private IConfig $config, |
|
| 24 | + private string $principalPrefix = 'principals/users/', |
|
| 25 | + ) { |
|
| 26 | + // setup realm |
|
| 27 | + $defaults = new Defaults(); |
|
| 28 | + $this->realm = $defaults->getName() ?: 'Nextcloud'; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - private function setupUserFs($userId) { |
|
| 32 | - \OC_Util::setupFS($userId); |
|
| 33 | - $this->session->close(); |
|
| 34 | - return $this->principalPrefix . $userId; |
|
| 35 | - } |
|
| 31 | + private function setupUserFs($userId) { |
|
| 32 | + \OC_Util::setupFS($userId); |
|
| 33 | + $this->session->close(); |
|
| 34 | + return $this->principalPrefix . $userId; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * {@inheritdoc} |
|
| 39 | - */ |
|
| 40 | - public function validateBearerToken($bearerToken) { |
|
| 41 | - \OC_Util::setupFS(); |
|
| 37 | + /** |
|
| 38 | + * {@inheritdoc} |
|
| 39 | + */ |
|
| 40 | + public function validateBearerToken($bearerToken) { |
|
| 41 | + \OC_Util::setupFS(); |
|
| 42 | 42 | |
| 43 | - if (!$this->userSession->isLoggedIn()) { |
|
| 44 | - $this->userSession->tryTokenLogin($this->request); |
|
| 45 | - } |
|
| 46 | - if ($this->userSession->isLoggedIn()) { |
|
| 47 | - return $this->setupUserFs($this->userSession->getUser()->getUID()); |
|
| 48 | - } |
|
| 43 | + if (!$this->userSession->isLoggedIn()) { |
|
| 44 | + $this->userSession->tryTokenLogin($this->request); |
|
| 45 | + } |
|
| 46 | + if ($this->userSession->isLoggedIn()) { |
|
| 47 | + return $this->setupUserFs($this->userSession->getUser()->getUID()); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return false; |
|
| 51 | - } |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate |
|
| 55 | - * header which some DAV clients can't handle. Thus we override this function |
|
| 56 | - * and make it simply return a 401. |
|
| 57 | - * |
|
| 58 | - * @param RequestInterface $request |
|
| 59 | - * @param ResponseInterface $response |
|
| 60 | - */ |
|
| 61 | - public function challenge(RequestInterface $request, ResponseInterface $response): void { |
|
| 62 | - // Legacy ownCloud clients still authenticate via OAuth2 |
|
| 63 | - $enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false); |
|
| 64 | - $userAgent = $request->getHeader('User-Agent'); |
|
| 65 | - if ($enableOcClients && $userAgent !== null && str_contains($userAgent, 'mirall')) { |
|
| 66 | - parent::challenge($request, $response); |
|
| 67 | - return; |
|
| 68 | - } |
|
| 53 | + /** |
|
| 54 | + * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate |
|
| 55 | + * header which some DAV clients can't handle. Thus we override this function |
|
| 56 | + * and make it simply return a 401. |
|
| 57 | + * |
|
| 58 | + * @param RequestInterface $request |
|
| 59 | + * @param ResponseInterface $response |
|
| 60 | + */ |
|
| 61 | + public function challenge(RequestInterface $request, ResponseInterface $response): void { |
|
| 62 | + // Legacy ownCloud clients still authenticate via OAuth2 |
|
| 63 | + $enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false); |
|
| 64 | + $userAgent = $request->getHeader('User-Agent'); |
|
| 65 | + if ($enableOcClients && $userAgent !== null && str_contains($userAgent, 'mirall')) { |
|
| 66 | + parent::challenge($request, $response); |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 71 | - } |
|
| 70 | + $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -31,12 +31,12 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class UnsupportedMediaType extends \Sabre\DAV\Exception { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the HTTP status code for this exception |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function getHTTPCode() { |
|
| 40 | - return 415; |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * Returns the HTTP status code for this exception |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function getHTTPCode() { |
|
| 40 | + return 415; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -31,12 +31,12 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class EntityTooLarge extends \Sabre\DAV\Exception { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the HTTP status code for this exception |
|
| 36 | - * |
|
| 37 | - * @return int |
|
| 38 | - */ |
|
| 39 | - public function getHTTPCode() { |
|
| 40 | - return 413; |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * Returns the HTTP status code for this exception |
|
| 36 | + * |
|
| 37 | + * @return int |
|
| 38 | + */ |
|
| 39 | + public function getHTTPCode() { |
|
| 40 | + return 413; |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | return null; |
| 89 | 89 | } |
| 90 | 90 | foreach ($tree as $elem) { |
| 91 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 91 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
| 92 | 92 | $tags[] = $elem['value']; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function xmlSerialize(Writer $writer) { |
| 118 | 118 | foreach ($this->tags as $tag) { |
| 119 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 119 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -17,86 +17,86 @@ |
||
| 17 | 17 | * This property contains multiple "tag" elements, each containing a tag name. |
| 18 | 18 | */ |
| 19 | 19 | class TagList implements Element { |
| 20 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 20 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param array $tags |
|
| 24 | - */ |
|
| 25 | - public function __construct( |
|
| 26 | - /** |
|
| 27 | - * tags |
|
| 28 | - */ |
|
| 29 | - private array $tags, |
|
| 30 | - ) { |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * @param array $tags |
|
| 24 | + */ |
|
| 25 | + public function __construct( |
|
| 26 | + /** |
|
| 27 | + * tags |
|
| 28 | + */ |
|
| 29 | + private array $tags, |
|
| 30 | + ) { |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Returns the tags |
|
| 35 | - * |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function getTags() { |
|
| 39 | - return $this->tags; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Returns the tags |
|
| 35 | + * |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function getTags() { |
|
| 39 | + return $this->tags; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The deserialize method is called during xml parsing. |
|
| 44 | - * |
|
| 45 | - * This method is called statictly, this is because in theory this method |
|
| 46 | - * may be used as a type of constructor, or factory method. |
|
| 47 | - * |
|
| 48 | - * Often you want to return an instance of the current class, but you are |
|
| 49 | - * free to return other data as well. |
|
| 50 | - * |
|
| 51 | - * You are responsible for advancing the reader to the next element. Not |
|
| 52 | - * doing anything will result in a never-ending loop. |
|
| 53 | - * |
|
| 54 | - * If you just want to skip parsing for this element altogether, you can |
|
| 55 | - * just call $reader->next(); |
|
| 56 | - * |
|
| 57 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 58 | - * the next element. |
|
| 59 | - * |
|
| 60 | - * @param Reader $reader |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public static function xmlDeserialize(Reader $reader) { |
|
| 64 | - $tags = []; |
|
| 42 | + /** |
|
| 43 | + * The deserialize method is called during xml parsing. |
|
| 44 | + * |
|
| 45 | + * This method is called statictly, this is because in theory this method |
|
| 46 | + * may be used as a type of constructor, or factory method. |
|
| 47 | + * |
|
| 48 | + * Often you want to return an instance of the current class, but you are |
|
| 49 | + * free to return other data as well. |
|
| 50 | + * |
|
| 51 | + * You are responsible for advancing the reader to the next element. Not |
|
| 52 | + * doing anything will result in a never-ending loop. |
|
| 53 | + * |
|
| 54 | + * If you just want to skip parsing for this element altogether, you can |
|
| 55 | + * just call $reader->next(); |
|
| 56 | + * |
|
| 57 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 58 | + * the next element. |
|
| 59 | + * |
|
| 60 | + * @param Reader $reader |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public static function xmlDeserialize(Reader $reader) { |
|
| 64 | + $tags = []; |
|
| 65 | 65 | |
| 66 | - $tree = $reader->parseInnerTree(); |
|
| 67 | - if ($tree === null) { |
|
| 68 | - return null; |
|
| 69 | - } |
|
| 70 | - foreach ($tree as $elem) { |
|
| 71 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 72 | - $tags[] = $elem['value']; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - return new self($tags); |
|
| 76 | - } |
|
| 66 | + $tree = $reader->parseInnerTree(); |
|
| 67 | + if ($tree === null) { |
|
| 68 | + return null; |
|
| 69 | + } |
|
| 70 | + foreach ($tree as $elem) { |
|
| 71 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 72 | + $tags[] = $elem['value']; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + return new self($tags); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * The xmlSerialize method is called during xml writing. |
|
| 80 | - * |
|
| 81 | - * Use the $writer argument to write its own xml serialization. |
|
| 82 | - * |
|
| 83 | - * An important note: do _not_ create a parent element. Any element |
|
| 84 | - * implementing XmlSerializble should only ever write what's considered |
|
| 85 | - * its 'inner xml'. |
|
| 86 | - * |
|
| 87 | - * The parent of the current element is responsible for writing a |
|
| 88 | - * containing element. |
|
| 89 | - * |
|
| 90 | - * This allows serializers to be re-used for different element names. |
|
| 91 | - * |
|
| 92 | - * If you are opening new elements, you must also close them again. |
|
| 93 | - * |
|
| 94 | - * @param Writer $writer |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public function xmlSerialize(Writer $writer) { |
|
| 98 | - foreach ($this->tags as $tag) { |
|
| 99 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 100 | - } |
|
| 101 | - } |
|
| 78 | + /** |
|
| 79 | + * The xmlSerialize method is called during xml writing. |
|
| 80 | + * |
|
| 81 | + * Use the $writer argument to write its own xml serialization. |
|
| 82 | + * |
|
| 83 | + * An important note: do _not_ create a parent element. Any element |
|
| 84 | + * implementing XmlSerializble should only ever write what's considered |
|
| 85 | + * its 'inner xml'. |
|
| 86 | + * |
|
| 87 | + * The parent of the current element is responsible for writing a |
|
| 88 | + * containing element. |
|
| 89 | + * |
|
| 90 | + * This allows serializers to be re-used for different element names. |
|
| 91 | + * |
|
| 92 | + * If you are opening new elements, you must also close them again. |
|
| 93 | + * |
|
| 94 | + * @param Writer $writer |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public function xmlSerialize(Writer $writer) { |
|
| 98 | + foreach ($this->tags as $tag) { |
|
| 99 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | */ |
| 65 | 65 | public function xmlSerialize(Writer $writer) { |
| 66 | 66 | foreach ($this->checksums as $checksum) { |
| 67 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
| 67 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}checksum', $checksum); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -32,37 +32,37 @@ |
||
| 32 | 32 | * checksum name. |
| 33 | 33 | */ |
| 34 | 34 | class ChecksumList implements XmlSerializable { |
| 35 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 35 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 36 | 36 | |
| 37 | - /** @var string[] of TYPE:CHECKSUM */ |
|
| 38 | - private array $checksums; |
|
| 37 | + /** @var string[] of TYPE:CHECKSUM */ |
|
| 38 | + private array $checksums; |
|
| 39 | 39 | |
| 40 | - public function __construct(string $checksum) { |
|
| 41 | - $this->checksums = explode(' ', $checksum); |
|
| 42 | - } |
|
| 40 | + public function __construct(string $checksum) { |
|
| 41 | + $this->checksums = explode(' ', $checksum); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * The xmlSerialize method is called during xml writing. |
|
| 46 | - * |
|
| 47 | - * Use the $writer argument to write its own xml serialization. |
|
| 48 | - * |
|
| 49 | - * An important note: do _not_ create a parent element. Any element |
|
| 50 | - * implementing XmlSerializble should only ever write what's considered |
|
| 51 | - * its 'inner xml'. |
|
| 52 | - * |
|
| 53 | - * The parent of the current element is responsible for writing a |
|
| 54 | - * containing element. |
|
| 55 | - * |
|
| 56 | - * This allows serializers to be re-used for different element names. |
|
| 57 | - * |
|
| 58 | - * If you are opening new elements, you must also close them again. |
|
| 59 | - * |
|
| 60 | - * @param Writer $writer |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - public function xmlSerialize(Writer $writer) { |
|
| 64 | - foreach ($this->checksums as $checksum) { |
|
| 65 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
| 66 | - } |
|
| 67 | - } |
|
| 44 | + /** |
|
| 45 | + * The xmlSerialize method is called during xml writing. |
|
| 46 | + * |
|
| 47 | + * Use the $writer argument to write its own xml serialization. |
|
| 48 | + * |
|
| 49 | + * An important note: do _not_ create a parent element. Any element |
|
| 50 | + * implementing XmlSerializble should only ever write what's considered |
|
| 51 | + * its 'inner xml'. |
|
| 52 | + * |
|
| 53 | + * The parent of the current element is responsible for writing a |
|
| 54 | + * containing element. |
|
| 55 | + * |
|
| 56 | + * This allows serializers to be re-used for different element names. |
|
| 57 | + * |
|
| 58 | + * If you are opening new elements, you must also close them again. |
|
| 59 | + * |
|
| 60 | + * @param Writer $writer |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + public function xmlSerialize(Writer $writer) { |
|
| 64 | + foreach ($this->checksums as $checksum) { |
|
| 65 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | return null; |
| 72 | 72 | } |
| 73 | 73 | foreach ($tree as $elem) { |
| 74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
| 75 | - $shareTypes[] = (int)$elem['value']; |
|
| 74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
| 75 | + $shareTypes[] = (int) $elem['value']; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function xmlSerialize(Writer $writer) { |
| 88 | 88 | foreach ($this->shareTypes as $shareType) { |
| 89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
| 89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -17,58 +17,58 @@ |
||
| 17 | 17 | * This property contains multiple "share-type" elements, each containing a share type. |
| 18 | 18 | */ |
| 19 | 19 | class ShareTypeList implements Element { |
| 20 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 20 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param int[] $shareTypes |
|
| 24 | - */ |
|
| 25 | - public function __construct( |
|
| 26 | - /** |
|
| 27 | - * Share types |
|
| 28 | - */ |
|
| 29 | - private $shareTypes, |
|
| 30 | - ) { |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * @param int[] $shareTypes |
|
| 24 | + */ |
|
| 25 | + public function __construct( |
|
| 26 | + /** |
|
| 27 | + * Share types |
|
| 28 | + */ |
|
| 29 | + private $shareTypes, |
|
| 30 | + ) { |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Returns the share types |
|
| 35 | - * |
|
| 36 | - * @return int[] |
|
| 37 | - */ |
|
| 38 | - public function getShareTypes() { |
|
| 39 | - return $this->shareTypes; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Returns the share types |
|
| 35 | + * |
|
| 36 | + * @return int[] |
|
| 37 | + */ |
|
| 38 | + public function getShareTypes() { |
|
| 39 | + return $this->shareTypes; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The deserialize method is called during xml parsing. |
|
| 44 | - * |
|
| 45 | - * @param Reader $reader |
|
| 46 | - * @return mixed |
|
| 47 | - */ |
|
| 48 | - public static function xmlDeserialize(Reader $reader) { |
|
| 49 | - $shareTypes = []; |
|
| 42 | + /** |
|
| 43 | + * The deserialize method is called during xml parsing. |
|
| 44 | + * |
|
| 45 | + * @param Reader $reader |
|
| 46 | + * @return mixed |
|
| 47 | + */ |
|
| 48 | + public static function xmlDeserialize(Reader $reader) { |
|
| 49 | + $shareTypes = []; |
|
| 50 | 50 | |
| 51 | - $tree = $reader->parseInnerTree(); |
|
| 52 | - if ($tree === null) { |
|
| 53 | - return null; |
|
| 54 | - } |
|
| 55 | - foreach ($tree as $elem) { |
|
| 56 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
| 57 | - $shareTypes[] = (int)$elem['value']; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - return new self($shareTypes); |
|
| 61 | - } |
|
| 51 | + $tree = $reader->parseInnerTree(); |
|
| 52 | + if ($tree === null) { |
|
| 53 | + return null; |
|
| 54 | + } |
|
| 55 | + foreach ($tree as $elem) { |
|
| 56 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
| 57 | + $shareTypes[] = (int)$elem['value']; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + return new self($shareTypes); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The xmlSerialize method is called during xml writing. |
|
| 65 | - * |
|
| 66 | - * @param Writer $writer |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public function xmlSerialize(Writer $writer) { |
|
| 70 | - foreach ($this->shareTypes as $shareType) { |
|
| 71 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
| 72 | - } |
|
| 73 | - } |
|
| 63 | + /** |
|
| 64 | + * The xmlSerialize method is called during xml writing. |
|
| 65 | + * |
|
| 66 | + * @param Writer $writer |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public function xmlSerialize(Writer $writer) { |
|
| 70 | + foreach ($this->shareTypes as $shareType) { |
|
| 71 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
| 111 | + throw new NotFound('Node with name \''.$name.'\' could not be found'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -30,197 +30,197 @@ |
||
| 30 | 30 | |
| 31 | 31 | class CalendarHome extends \Sabre\CalDAV\CalendarHome { |
| 32 | 32 | |
| 33 | - /** @var IL10N */ |
|
| 34 | - private $l10n; |
|
| 35 | - |
|
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 38 | - |
|
| 39 | - /** @var PluginManager */ |
|
| 40 | - private $pluginManager; |
|
| 41 | - |
|
| 42 | - private ?array $cachedChildren = null; |
|
| 43 | - |
|
| 44 | - public function __construct( |
|
| 45 | - BackendInterface $caldavBackend, |
|
| 46 | - array $principalInfo, |
|
| 47 | - private LoggerInterface $logger, |
|
| 48 | - private FederatedCalendarFactory $federatedCalendarFactory, |
|
| 49 | - private bool $returnCachedSubscriptions, |
|
| 50 | - ) { |
|
| 51 | - parent::__construct($caldavBackend, $principalInfo); |
|
| 52 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
| 53 | - $this->config = Server::get(IConfig::class); |
|
| 54 | - $this->pluginManager = new PluginManager( |
|
| 55 | - \OC::$server, |
|
| 56 | - Server::get(IAppManager::class) |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return BackendInterface |
|
| 62 | - */ |
|
| 63 | - public function getCalDAVBackend() { |
|
| 64 | - return $this->caldavBackend; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @inheritdoc |
|
| 69 | - */ |
|
| 70 | - public function createExtendedCollection($name, MkCol $mkCol): void { |
|
| 71 | - $reservedNames = [ |
|
| 72 | - BirthdayService::BIRTHDAY_CALENDAR_URI, |
|
| 73 | - TrashbinHome::NAME, |
|
| 74 | - ]; |
|
| 75 | - |
|
| 76 | - if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
| 77 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - parent::createExtendedCollection($name, $mkCol); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @inheritdoc |
|
| 85 | - */ |
|
| 86 | - public function getChildren() { |
|
| 87 | - if ($this->cachedChildren) { |
|
| 88 | - return $this->cachedChildren; |
|
| 89 | - } |
|
| 90 | - $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
| 91 | - $objects = []; |
|
| 92 | - foreach ($calendars as $calendar) { |
|
| 93 | - $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($this->caldavBackend instanceof SchedulingSupport) { |
|
| 97 | - $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 98 | - $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // We're adding a notifications node, if it's supported by the backend. |
|
| 102 | - if ($this->caldavBackend instanceof NotificationSupport) { |
|
| 103 | - $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 107 | - $objects[] = new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 108 | - |
|
| 109 | - $federatedCalendars = $this->caldavBackend->getFederatedCalendarsForUser( |
|
| 110 | - $this->principalInfo['uri'], |
|
| 111 | - ); |
|
| 112 | - foreach ($federatedCalendars as $federatedCalendarInfo) { |
|
| 113 | - $objects[] = $this->federatedCalendarFactory->createFederatedCalendar( |
|
| 114 | - $federatedCalendarInfo, |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // If the backend supports subscriptions, we'll add those as well, |
|
| 120 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 121 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 122 | - if ($this->returnCachedSubscriptions) { |
|
| 123 | - $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
| 124 | - } else { |
|
| 125 | - $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 131 | - /** @var ICalendarProvider $calendarPlugin */ |
|
| 132 | - $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
| 133 | - foreach ($calendars as $calendar) { |
|
| 134 | - $objects[] = $calendar; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $this->cachedChildren = $objects; |
|
| 139 | - return $objects; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param string $name |
|
| 144 | - * |
|
| 145 | - * @return INode |
|
| 146 | - */ |
|
| 147 | - public function getChild($name) { |
|
| 148 | - // Special nodes |
|
| 149 | - if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 150 | - return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 151 | - } |
|
| 152 | - if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 153 | - return new Outbox($this->config, $this->principalInfo['uri']); |
|
| 154 | - } |
|
| 155 | - if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
| 156 | - return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 157 | - } |
|
| 158 | - if ($name === TrashbinHome::NAME && $this->caldavBackend instanceof CalDavBackend) { |
|
| 159 | - return new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Only check if the methods are available |
|
| 163 | - if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 164 | - // Calendar - this covers all "regular" calendars, but not shared |
|
| 165 | - $calendar = $this->caldavBackend->getCalendarByUri($this->principalInfo['uri'], $name); |
|
| 166 | - if (!empty($calendar)) { |
|
| 167 | - return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Federated calendar |
|
| 171 | - $federatedCalendar = $this->caldavBackend->getFederatedCalendarByUri( |
|
| 172 | - $this->principalInfo['uri'], |
|
| 173 | - $name, |
|
| 174 | - ); |
|
| 175 | - if ($federatedCalendar !== null) { |
|
| 176 | - return $this->federatedCalendarFactory->createFederatedCalendar($federatedCalendar); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Fallback to cover shared calendars |
|
| 181 | - foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
| 182 | - if ($calendar['uri'] === $name) { |
|
| 183 | - return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 188 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 189 | - if ($subscription['uri'] === $name) { |
|
| 190 | - if ($this->returnCachedSubscriptions) { |
|
| 191 | - return new CachedSubscription($this->caldavBackend, $subscription); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return new Subscription($this->caldavBackend, $subscription); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
| 200 | - [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 201 | - |
|
| 202 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 203 | - /** @var ICalendarProvider $calendarPlugin */ |
|
| 204 | - if ($calendarPlugin->getAppId() !== $appId) { |
|
| 205 | - continue; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
| 209 | - return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param array $filters |
|
| 219 | - * @param integer|null $limit |
|
| 220 | - * @param integer|null $offset |
|
| 221 | - */ |
|
| 222 | - public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
| 223 | - $principalUri = $this->principalInfo['uri']; |
|
| 224 | - return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
| 225 | - } |
|
| 33 | + /** @var IL10N */ |
|
| 34 | + private $l10n; |
|
| 35 | + |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | + |
|
| 39 | + /** @var PluginManager */ |
|
| 40 | + private $pluginManager; |
|
| 41 | + |
|
| 42 | + private ?array $cachedChildren = null; |
|
| 43 | + |
|
| 44 | + public function __construct( |
|
| 45 | + BackendInterface $caldavBackend, |
|
| 46 | + array $principalInfo, |
|
| 47 | + private LoggerInterface $logger, |
|
| 48 | + private FederatedCalendarFactory $federatedCalendarFactory, |
|
| 49 | + private bool $returnCachedSubscriptions, |
|
| 50 | + ) { |
|
| 51 | + parent::__construct($caldavBackend, $principalInfo); |
|
| 52 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
| 53 | + $this->config = Server::get(IConfig::class); |
|
| 54 | + $this->pluginManager = new PluginManager( |
|
| 55 | + \OC::$server, |
|
| 56 | + Server::get(IAppManager::class) |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return BackendInterface |
|
| 62 | + */ |
|
| 63 | + public function getCalDAVBackend() { |
|
| 64 | + return $this->caldavBackend; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @inheritdoc |
|
| 69 | + */ |
|
| 70 | + public function createExtendedCollection($name, MkCol $mkCol): void { |
|
| 71 | + $reservedNames = [ |
|
| 72 | + BirthdayService::BIRTHDAY_CALENDAR_URI, |
|
| 73 | + TrashbinHome::NAME, |
|
| 74 | + ]; |
|
| 75 | + |
|
| 76 | + if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
| 77 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + parent::createExtendedCollection($name, $mkCol); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @inheritdoc |
|
| 85 | + */ |
|
| 86 | + public function getChildren() { |
|
| 87 | + if ($this->cachedChildren) { |
|
| 88 | + return $this->cachedChildren; |
|
| 89 | + } |
|
| 90 | + $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
| 91 | + $objects = []; |
|
| 92 | + foreach ($calendars as $calendar) { |
|
| 93 | + $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($this->caldavBackend instanceof SchedulingSupport) { |
|
| 97 | + $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 98 | + $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // We're adding a notifications node, if it's supported by the backend. |
|
| 102 | + if ($this->caldavBackend instanceof NotificationSupport) { |
|
| 103 | + $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 107 | + $objects[] = new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 108 | + |
|
| 109 | + $federatedCalendars = $this->caldavBackend->getFederatedCalendarsForUser( |
|
| 110 | + $this->principalInfo['uri'], |
|
| 111 | + ); |
|
| 112 | + foreach ($federatedCalendars as $federatedCalendarInfo) { |
|
| 113 | + $objects[] = $this->federatedCalendarFactory->createFederatedCalendar( |
|
| 114 | + $federatedCalendarInfo, |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // If the backend supports subscriptions, we'll add those as well, |
|
| 120 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 121 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 122 | + if ($this->returnCachedSubscriptions) { |
|
| 123 | + $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
| 124 | + } else { |
|
| 125 | + $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 131 | + /** @var ICalendarProvider $calendarPlugin */ |
|
| 132 | + $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
| 133 | + foreach ($calendars as $calendar) { |
|
| 134 | + $objects[] = $calendar; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $this->cachedChildren = $objects; |
|
| 139 | + return $objects; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param string $name |
|
| 144 | + * |
|
| 145 | + * @return INode |
|
| 146 | + */ |
|
| 147 | + public function getChild($name) { |
|
| 148 | + // Special nodes |
|
| 149 | + if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 150 | + return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 151 | + } |
|
| 152 | + if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 153 | + return new Outbox($this->config, $this->principalInfo['uri']); |
|
| 154 | + } |
|
| 155 | + if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
| 156 | + return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 157 | + } |
|
| 158 | + if ($name === TrashbinHome::NAME && $this->caldavBackend instanceof CalDavBackend) { |
|
| 159 | + return new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Only check if the methods are available |
|
| 163 | + if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 164 | + // Calendar - this covers all "regular" calendars, but not shared |
|
| 165 | + $calendar = $this->caldavBackend->getCalendarByUri($this->principalInfo['uri'], $name); |
|
| 166 | + if (!empty($calendar)) { |
|
| 167 | + return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Federated calendar |
|
| 171 | + $federatedCalendar = $this->caldavBackend->getFederatedCalendarByUri( |
|
| 172 | + $this->principalInfo['uri'], |
|
| 173 | + $name, |
|
| 174 | + ); |
|
| 175 | + if ($federatedCalendar !== null) { |
|
| 176 | + return $this->federatedCalendarFactory->createFederatedCalendar($federatedCalendar); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Fallback to cover shared calendars |
|
| 181 | + foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
| 182 | + if ($calendar['uri'] === $name) { |
|
| 183 | + return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 188 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 189 | + if ($subscription['uri'] === $name) { |
|
| 190 | + if ($this->returnCachedSubscriptions) { |
|
| 191 | + return new CachedSubscription($this->caldavBackend, $subscription); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return new Subscription($this->caldavBackend, $subscription); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
| 200 | + [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 201 | + |
|
| 202 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 203 | + /** @var ICalendarProvider $calendarPlugin */ |
|
| 204 | + if ($calendarPlugin->getAppId() !== $appId) { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
| 209 | + return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param array $filters |
|
| 219 | + * @param integer|null $limit |
|
| 220 | + * @param integer|null $offset |
|
| 221 | + */ |
|
| 222 | + public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
| 223 | + $principalUri = $this->principalInfo['uri']; |
|
| 224 | + return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
| 225 | + } |
|
| 226 | 226 | } |