@@ -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 | } |
@@ -23,11 +23,11 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PublicCalendarObject extends CalendarObject { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * public calendars are always shared |
|
| 28 | - * @return bool |
|
| 29 | - */ |
|
| 30 | - protected function isShared() { |
|
| 31 | - return true; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * public calendars are always shared |
|
| 28 | + * @return bool |
|
| 29 | + */ |
|
| 30 | + protected function isShared() { |
|
| 31 | + return true; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -27,17 +27,17 @@ |
||
| 27 | 27 | |
| 28 | 28 | class SearchTermFilter implements XmlDeserializable { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param Reader $reader |
|
| 32 | - * @throws BadRequest |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public static function xmlDeserialize(Reader $reader) { |
|
| 36 | - $value = $reader->parseInnerTree(); |
|
| 37 | - if (!is_string($value)) { |
|
| 38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * @param Reader $reader |
|
| 32 | + * @throws BadRequest |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public static function xmlDeserialize(Reader $reader) { |
|
| 36 | + $value = $reader->parseInnerTree(); |
|
| 37 | + if (!is_string($value)) { |
|
| 38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $value; |
|
| 42 | - } |
|
| 41 | + return $value; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | public static function xmlDeserialize(Reader $reader) { |
| 36 | 36 | $value = $reader->parseInnerTree(); |
| 37 | 37 | if (!is_string($value)) { |
| 38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
| 38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}search-term has illegal value'); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return $value; |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | $tag = $this->tagManager->getTagsByIds([$name]); |
| 105 | 105 | $tag = current($tag); |
| 106 | 106 | if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
| 107 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 107 | + throw new NotFound('Tag with id '.$name.' not found'); |
|
| 108 | 108 | } |
| 109 | 109 | return $this->makeNode($tag); |
| 110 | 110 | } catch (\InvalidArgumentException $e) { |
| 111 | 111 | throw new BadRequest('Invalid tag id', 0, $e); |
| 112 | 112 | } catch (TagNotFoundException $e) { |
| 113 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 113 | + throw new NotFound('Tag with id '.$name.' not found', 0, $e); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $tags = $this->tagManager->getAllTags($visibilityFilter); |
| 124 | - return array_map(function ($tag) { |
|
| 124 | + return array_map(function($tag) { |
|
| 125 | 125 | return $this->makeNode($tag); |
| 126 | 126 | }, $tags); |
| 127 | 127 | } |
@@ -20,150 +20,150 @@ |
||
| 20 | 20 | |
| 21 | 21 | class SystemTagsByIdCollection implements ICollection { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * SystemTagsByIdCollection constructor. |
|
| 25 | - * |
|
| 26 | - * @param ISystemTagManager $tagManager |
|
| 27 | - * @param IUserSession $userSession |
|
| 28 | - * @param IGroupManager $groupManager |
|
| 29 | - */ |
|
| 30 | - public function __construct( |
|
| 31 | - private ISystemTagManager $tagManager, |
|
| 32 | - private IUserSession $userSession, |
|
| 33 | - private IGroupManager $groupManager, |
|
| 34 | - protected ISystemTagObjectMapper $tagMapper, |
|
| 35 | - ) { |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Returns whether the currently logged in user is an administrator |
|
| 40 | - * |
|
| 41 | - * @return bool true if the user is an admin |
|
| 42 | - */ |
|
| 43 | - private function isAdmin() { |
|
| 44 | - $user = $this->userSession->getUser(); |
|
| 45 | - if ($user !== null) { |
|
| 46 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 47 | - } |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param string $name |
|
| 53 | - * @param resource|string $data Initial payload |
|
| 54 | - * |
|
| 55 | - * @throws Forbidden |
|
| 56 | - * |
|
| 57 | - * @return never |
|
| 58 | - */ |
|
| 59 | - public function createFile($name, $data = null) { |
|
| 60 | - throw new Forbidden('Cannot create tags by id'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param string $name |
|
| 65 | - * |
|
| 66 | - * @return never |
|
| 67 | - */ |
|
| 68 | - public function createDirectory($name) { |
|
| 69 | - throw new Forbidden('Permission denied to create collections'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param string $name |
|
| 74 | - * |
|
| 75 | - * @return SystemTagNode |
|
| 76 | - */ |
|
| 77 | - public function getChild($name) { |
|
| 78 | - try { |
|
| 79 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 80 | - $tag = current($tag); |
|
| 81 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 82 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 83 | - } |
|
| 84 | - return $this->makeNode($tag); |
|
| 85 | - } catch (\InvalidArgumentException $e) { |
|
| 86 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 87 | - } catch (TagNotFoundException $e) { |
|
| 88 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return SystemTagNode[] |
|
| 94 | - * |
|
| 95 | - * @psalm-return array<SystemTagNode> |
|
| 96 | - */ |
|
| 97 | - public function getChildren() { |
|
| 98 | - $visibilityFilter = true; |
|
| 99 | - if ($this->isAdmin()) { |
|
| 100 | - $visibilityFilter = null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
| 104 | - return array_map(function ($tag) { |
|
| 105 | - return $this->makeNode($tag); |
|
| 106 | - }, $tags); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param string $name |
|
| 111 | - */ |
|
| 112 | - public function childExists($name) { |
|
| 113 | - try { |
|
| 114 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 115 | - $tag = current($tag); |
|
| 116 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - return true; |
|
| 120 | - } catch (\InvalidArgumentException $e) { |
|
| 121 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 122 | - } catch (TagNotFoundException $e) { |
|
| 123 | - return false; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return never |
|
| 129 | - */ |
|
| 130 | - public function delete() { |
|
| 131 | - throw new Forbidden('Permission denied to delete this collection'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return string |
|
| 136 | - * |
|
| 137 | - * @psalm-return 'systemtags' |
|
| 138 | - */ |
|
| 139 | - public function getName() { |
|
| 140 | - return 'systemtags'; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return never |
|
| 145 | - */ |
|
| 146 | - public function setName($name) { |
|
| 147 | - throw new Forbidden('Permission denied to rename this collection'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Returns the last modification time, as a unix timestamp |
|
| 152 | - * |
|
| 153 | - * @return null |
|
| 154 | - */ |
|
| 155 | - public function getLastModified() { |
|
| 156 | - return null; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Create a sabre node for the given system tag |
|
| 161 | - * |
|
| 162 | - * @param ISystemTag $tag |
|
| 163 | - * |
|
| 164 | - * @return SystemTagNode |
|
| 165 | - */ |
|
| 166 | - private function makeNode(ISystemTag $tag) { |
|
| 167 | - return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager, $this->tagMapper); |
|
| 168 | - } |
|
| 23 | + /** |
|
| 24 | + * SystemTagsByIdCollection constructor. |
|
| 25 | + * |
|
| 26 | + * @param ISystemTagManager $tagManager |
|
| 27 | + * @param IUserSession $userSession |
|
| 28 | + * @param IGroupManager $groupManager |
|
| 29 | + */ |
|
| 30 | + public function __construct( |
|
| 31 | + private ISystemTagManager $tagManager, |
|
| 32 | + private IUserSession $userSession, |
|
| 33 | + private IGroupManager $groupManager, |
|
| 34 | + protected ISystemTagObjectMapper $tagMapper, |
|
| 35 | + ) { |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Returns whether the currently logged in user is an administrator |
|
| 40 | + * |
|
| 41 | + * @return bool true if the user is an admin |
|
| 42 | + */ |
|
| 43 | + private function isAdmin() { |
|
| 44 | + $user = $this->userSession->getUser(); |
|
| 45 | + if ($user !== null) { |
|
| 46 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 47 | + } |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param string $name |
|
| 53 | + * @param resource|string $data Initial payload |
|
| 54 | + * |
|
| 55 | + * @throws Forbidden |
|
| 56 | + * |
|
| 57 | + * @return never |
|
| 58 | + */ |
|
| 59 | + public function createFile($name, $data = null) { |
|
| 60 | + throw new Forbidden('Cannot create tags by id'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param string $name |
|
| 65 | + * |
|
| 66 | + * @return never |
|
| 67 | + */ |
|
| 68 | + public function createDirectory($name) { |
|
| 69 | + throw new Forbidden('Permission denied to create collections'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param string $name |
|
| 74 | + * |
|
| 75 | + * @return SystemTagNode |
|
| 76 | + */ |
|
| 77 | + public function getChild($name) { |
|
| 78 | + try { |
|
| 79 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 80 | + $tag = current($tag); |
|
| 81 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 82 | + throw new NotFound('Tag with id ' . $name . ' not found'); |
|
| 83 | + } |
|
| 84 | + return $this->makeNode($tag); |
|
| 85 | + } catch (\InvalidArgumentException $e) { |
|
| 86 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 87 | + } catch (TagNotFoundException $e) { |
|
| 88 | + throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return SystemTagNode[] |
|
| 94 | + * |
|
| 95 | + * @psalm-return array<SystemTagNode> |
|
| 96 | + */ |
|
| 97 | + public function getChildren() { |
|
| 98 | + $visibilityFilter = true; |
|
| 99 | + if ($this->isAdmin()) { |
|
| 100 | + $visibilityFilter = null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
| 104 | + return array_map(function ($tag) { |
|
| 105 | + return $this->makeNode($tag); |
|
| 106 | + }, $tags); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param string $name |
|
| 111 | + */ |
|
| 112 | + public function childExists($name) { |
|
| 113 | + try { |
|
| 114 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
| 115 | + $tag = current($tag); |
|
| 116 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + return true; |
|
| 120 | + } catch (\InvalidArgumentException $e) { |
|
| 121 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 122 | + } catch (TagNotFoundException $e) { |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return never |
|
| 129 | + */ |
|
| 130 | + public function delete() { |
|
| 131 | + throw new Forbidden('Permission denied to delete this collection'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return string |
|
| 136 | + * |
|
| 137 | + * @psalm-return 'systemtags' |
|
| 138 | + */ |
|
| 139 | + public function getName() { |
|
| 140 | + return 'systemtags'; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return never |
|
| 145 | + */ |
|
| 146 | + public function setName($name) { |
|
| 147 | + throw new Forbidden('Permission denied to rename this collection'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Returns the last modification time, as a unix timestamp |
|
| 152 | + * |
|
| 153 | + * @return null |
|
| 154 | + */ |
|
| 155 | + public function getLastModified() { |
|
| 156 | + return null; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Create a sabre node for the given system tag |
|
| 161 | + * |
|
| 162 | + * @param ISystemTag $tag |
|
| 163 | + * |
|
| 164 | + * @return SystemTagNode |
|
| 165 | + */ |
|
| 166 | + private function makeNode(ISystemTag $tag) { |
|
| 167 | + return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager, $this->tagMapper); |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function createDirectory($name) { |
| 42 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 42 | + throw new Forbidden('Permission denied to create file (filename '.$name.')'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function getChild($name) { |
@@ -17,95 +17,95 @@ |
||
| 17 | 17 | use Sabre\DAV\ICollection; |
| 18 | 18 | |
| 19 | 19 | class UploadFolder implements ICollection { |
| 20 | - public function __construct( |
|
| 21 | - private Directory $node, |
|
| 22 | - private CleanupService $cleanupService, |
|
| 23 | - private IStorage $storage, |
|
| 24 | - private string $uid, |
|
| 25 | - ) { |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function createFile($name, $data = null) { |
|
| 29 | - // TODO: verify name - should be a simple number |
|
| 30 | - try { |
|
| 31 | - $this->node->createFile($name, $data); |
|
| 32 | - } catch (\Exception $e) { |
|
| 33 | - if ($this->node->childExists($name)) { |
|
| 34 | - $child = $this->node->getChild($name); |
|
| 35 | - $child->delete(); |
|
| 36 | - } |
|
| 37 | - throw $e; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function createDirectory($name) { |
|
| 42 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getChild($name) { |
|
| 46 | - if ($name === '.file') { |
|
| 47 | - return new FutureFile($this->node, '.file'); |
|
| 48 | - } |
|
| 49 | - return new UploadFile($this->node->getChild($name)); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function getChildren() { |
|
| 53 | - $tmpChildren = $this->node->getChildren(); |
|
| 54 | - |
|
| 55 | - $children = []; |
|
| 56 | - $children[] = new FutureFile($this->node, '.file'); |
|
| 57 | - |
|
| 58 | - foreach ($tmpChildren as $child) { |
|
| 59 | - $children[] = new UploadFile($child); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 63 | - /** @var ObjectStoreStorage $storage */ |
|
| 64 | - $objectStore = $this->storage->getObjectStore(); |
|
| 65 | - if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
| 66 | - $cache = Server::get(ICacheFactory::class)->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
| 67 | - $uploadSession = $cache->get($this->getName()); |
|
| 68 | - if ($uploadSession) { |
|
| 69 | - $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
| 70 | - $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
| 71 | - $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
| 72 | - foreach ($parts as $part) { |
|
| 73 | - $children[] = new PartFile($this->node, $part); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return $children; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function childExists($name) { |
|
| 83 | - if ($name === '.file') { |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 86 | - return $this->node->childExists($name); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function delete() { |
|
| 90 | - $this->node->delete(); |
|
| 91 | - |
|
| 92 | - // Background cleanup job is not needed anymore |
|
| 93 | - $this->cleanupService->removeJob($this->uid, $this->getName()); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function getName() { |
|
| 97 | - return $this->node->getName(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function setName($name) { |
|
| 101 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function getLastModified() { |
|
| 105 | - return $this->node->getLastModified(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getStorage() { |
|
| 109 | - return $this->storage; |
|
| 110 | - } |
|
| 20 | + public function __construct( |
|
| 21 | + private Directory $node, |
|
| 22 | + private CleanupService $cleanupService, |
|
| 23 | + private IStorage $storage, |
|
| 24 | + private string $uid, |
|
| 25 | + ) { |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function createFile($name, $data = null) { |
|
| 29 | + // TODO: verify name - should be a simple number |
|
| 30 | + try { |
|
| 31 | + $this->node->createFile($name, $data); |
|
| 32 | + } catch (\Exception $e) { |
|
| 33 | + if ($this->node->childExists($name)) { |
|
| 34 | + $child = $this->node->getChild($name); |
|
| 35 | + $child->delete(); |
|
| 36 | + } |
|
| 37 | + throw $e; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function createDirectory($name) { |
|
| 42 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getChild($name) { |
|
| 46 | + if ($name === '.file') { |
|
| 47 | + return new FutureFile($this->node, '.file'); |
|
| 48 | + } |
|
| 49 | + return new UploadFile($this->node->getChild($name)); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function getChildren() { |
|
| 53 | + $tmpChildren = $this->node->getChildren(); |
|
| 54 | + |
|
| 55 | + $children = []; |
|
| 56 | + $children[] = new FutureFile($this->node, '.file'); |
|
| 57 | + |
|
| 58 | + foreach ($tmpChildren as $child) { |
|
| 59 | + $children[] = new UploadFile($child); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if ($this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 63 | + /** @var ObjectStoreStorage $storage */ |
|
| 64 | + $objectStore = $this->storage->getObjectStore(); |
|
| 65 | + if ($objectStore instanceof IObjectStoreMultiPartUpload) { |
|
| 66 | + $cache = Server::get(ICacheFactory::class)->createDistributed(ChunkingV2Plugin::CACHE_KEY); |
|
| 67 | + $uploadSession = $cache->get($this->getName()); |
|
| 68 | + if ($uploadSession) { |
|
| 69 | + $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; |
|
| 70 | + $id = $uploadSession[ChunkingV2Plugin::UPLOAD_TARGET_ID]; |
|
| 71 | + $parts = $objectStore->getMultipartUploads($this->storage->getURN($id), $uploadId); |
|
| 72 | + foreach ($parts as $part) { |
|
| 73 | + $children[] = new PartFile($this->node, $part); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return $children; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function childExists($name) { |
|
| 83 | + if ($name === '.file') { |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | + return $this->node->childExists($name); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function delete() { |
|
| 90 | + $this->node->delete(); |
|
| 91 | + |
|
| 92 | + // Background cleanup job is not needed anymore |
|
| 93 | + $this->cleanupService->removeJob($this->uid, $this->getName()); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function getName() { |
|
| 97 | + return $this->node->getName(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function setName($name) { |
|
| 101 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function getLastModified() { |
|
| 105 | + return $this->node->getLastModified(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getStorage() { |
|
| 109 | + return $this->storage; |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
| 51 | 51 | ]) |
| 52 | 52 | ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
| 53 | - ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 53 | + ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | 54 | if (isset($params['options']['key']) && $params['options']['key']) { |
| 55 | 55 | return $rackspaceAuth; |
| 56 | 56 | } |
@@ -33,29 +33,29 @@ |
||
| 33 | 33 | use OCP\IL10N; |
| 34 | 34 | |
| 35 | 35 | class Swift extends Backend { |
| 36 | - use LegacyDependencyCheckPolyfill; |
|
| 36 | + use LegacyDependencyCheckPolyfill; |
|
| 37 | 37 | |
| 38 | - public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) { |
|
| 39 | - $this |
|
| 40 | - ->setIdentifier('swift') |
|
| 41 | - ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat |
|
| 42 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') |
|
| 43 | - ->setText($l->t('OpenStack Object Storage')) |
|
| 44 | - ->addParameters([ |
|
| 45 | - (new DefinitionParameter('service_name', $l->t('Service name'))) |
|
| 46 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 47 | - new DefinitionParameter('region', $l->t('Region')), |
|
| 48 | - new DefinitionParameter('bucket', $l->t('Bucket')), |
|
| 49 | - (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) |
|
| 50 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 51 | - ]) |
|
| 52 | - ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
|
| 53 | - ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | - if (isset($params['options']['key']) && $params['options']['key']) { |
|
| 55 | - return $rackspaceAuth; |
|
| 56 | - } |
|
| 57 | - return $openstackAuth; |
|
| 58 | - }) |
|
| 59 | - ; |
|
| 60 | - } |
|
| 38 | + public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) { |
|
| 39 | + $this |
|
| 40 | + ->setIdentifier('swift') |
|
| 41 | + ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat |
|
| 42 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift') |
|
| 43 | + ->setText($l->t('OpenStack Object Storage')) |
|
| 44 | + ->addParameters([ |
|
| 45 | + (new DefinitionParameter('service_name', $l->t('Service name'))) |
|
| 46 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 47 | + new DefinitionParameter('region', $l->t('Region')), |
|
| 48 | + new DefinitionParameter('bucket', $l->t('Bucket')), |
|
| 49 | + (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)'))) |
|
| 50 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
| 51 | + ]) |
|
| 52 | + ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) |
|
| 53 | + ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) { |
|
| 54 | + if (isset($params['options']['key']) && $params['options']['key']) { |
|
| 55 | + return $rackspaceAuth; |
|
| 56 | + } |
|
| 57 | + return $openstackAuth; |
|
| 58 | + }) |
|
| 59 | + ; |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -36,101 +36,101 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | trait VisibilityTrait { |
| 38 | 38 | |
| 39 | - /** @var int visibility */ |
|
| 40 | - protected $visibility = BackendService::VISIBILITY_DEFAULT; |
|
| 39 | + /** @var int visibility */ |
|
| 40 | + protected $visibility = BackendService::VISIBILITY_DEFAULT; |
|
| 41 | 41 | |
| 42 | - /** @var int allowed visibilities */ |
|
| 43 | - protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT; |
|
| 42 | + /** @var int allowed visibilities */ |
|
| 43 | + protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return int |
|
| 47 | - */ |
|
| 48 | - public function getVisibility() { |
|
| 49 | - return $this->visibility; |
|
| 50 | - } |
|
| 45 | + /** |
|
| 46 | + * @return int |
|
| 47 | + */ |
|
| 48 | + public function getVisibility() { |
|
| 49 | + return $this->visibility; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Check if the backend is visible for a user type |
|
| 54 | - * |
|
| 55 | - * @param int $visibility |
|
| 56 | - * @return bool |
|
| 57 | - */ |
|
| 58 | - public function isVisibleFor($visibility) { |
|
| 59 | - if ($this->visibility & $visibility) { |
|
| 60 | - return true; |
|
| 61 | - } |
|
| 62 | - return false; |
|
| 63 | - } |
|
| 52 | + /** |
|
| 53 | + * Check if the backend is visible for a user type |
|
| 54 | + * |
|
| 55 | + * @param int $visibility |
|
| 56 | + * @return bool |
|
| 57 | + */ |
|
| 58 | + public function isVisibleFor($visibility) { |
|
| 59 | + if ($this->visibility & $visibility) { |
|
| 60 | + return true; |
|
| 61 | + } |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param int $visibility |
|
| 67 | - * @return self |
|
| 68 | - */ |
|
| 69 | - public function setVisibility($visibility) { |
|
| 70 | - $this->visibility = $visibility; |
|
| 71 | - $this->allowedVisibility |= $visibility; |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * @param int $visibility |
|
| 67 | + * @return self |
|
| 68 | + */ |
|
| 69 | + public function setVisibility($visibility) { |
|
| 70 | + $this->visibility = $visibility; |
|
| 71 | + $this->allowedVisibility |= $visibility; |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param int $visibility |
|
| 77 | - * @return self |
|
| 78 | - */ |
|
| 79 | - public function addVisibility($visibility) { |
|
| 80 | - return $this->setVisibility($this->visibility | $visibility); |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @param int $visibility |
|
| 77 | + * @return self |
|
| 78 | + */ |
|
| 79 | + public function addVisibility($visibility) { |
|
| 80 | + return $this->setVisibility($this->visibility | $visibility); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param int $visibility |
|
| 85 | - * @return self |
|
| 86 | - */ |
|
| 87 | - public function removeVisibility($visibility) { |
|
| 88 | - return $this->setVisibility($this->visibility & ~$visibility); |
|
| 89 | - } |
|
| 83 | + /** |
|
| 84 | + * @param int $visibility |
|
| 85 | + * @return self |
|
| 86 | + */ |
|
| 87 | + public function removeVisibility($visibility) { |
|
| 88 | + return $this->setVisibility($this->visibility & ~$visibility); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function getAllowedVisibility() { |
|
| 95 | - return $this->allowedVisibility; |
|
| 96 | - } |
|
| 91 | + /** |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function getAllowedVisibility() { |
|
| 95 | + return $this->allowedVisibility; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Check if the backend is allowed to be visible for a user type |
|
| 100 | - * |
|
| 101 | - * @param int $allowedVisibility |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - public function isAllowedVisibleFor($allowedVisibility) { |
|
| 105 | - if ($this->allowedVisibility & $allowedVisibility) { |
|
| 106 | - return true; |
|
| 107 | - } |
|
| 108 | - return false; |
|
| 109 | - } |
|
| 98 | + /** |
|
| 99 | + * Check if the backend is allowed to be visible for a user type |
|
| 100 | + * |
|
| 101 | + * @param int $allowedVisibility |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + public function isAllowedVisibleFor($allowedVisibility) { |
|
| 105 | + if ($this->allowedVisibility & $allowedVisibility) { |
|
| 106 | + return true; |
|
| 107 | + } |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @param int $allowedVisibility |
|
| 113 | - * @return self |
|
| 114 | - */ |
|
| 115 | - public function setAllowedVisibility($allowedVisibility) { |
|
| 116 | - $this->allowedVisibility = $allowedVisibility; |
|
| 117 | - $this->visibility &= $allowedVisibility; |
|
| 118 | - return $this; |
|
| 119 | - } |
|
| 111 | + /** |
|
| 112 | + * @param int $allowedVisibility |
|
| 113 | + * @return self |
|
| 114 | + */ |
|
| 115 | + public function setAllowedVisibility($allowedVisibility) { |
|
| 116 | + $this->allowedVisibility = $allowedVisibility; |
|
| 117 | + $this->visibility &= $allowedVisibility; |
|
| 118 | + return $this; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @param int $allowedVisibility |
|
| 123 | - * @return self |
|
| 124 | - */ |
|
| 125 | - public function addAllowedVisibility($allowedVisibility) { |
|
| 126 | - return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility); |
|
| 127 | - } |
|
| 121 | + /** |
|
| 122 | + * @param int $allowedVisibility |
|
| 123 | + * @return self |
|
| 124 | + */ |
|
| 125 | + public function addAllowedVisibility($allowedVisibility) { |
|
| 126 | + return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @param int $allowedVisibility |
|
| 131 | - * @return self |
|
| 132 | - */ |
|
| 133 | - public function removeAllowedVisibility($allowedVisibility) { |
|
| 134 | - return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility); |
|
| 135 | - } |
|
| 129 | + /** |
|
| 130 | + * @param int $allowedVisibility |
|
| 131 | + * @return self |
|
| 132 | + */ |
|
| 133 | + public function removeAllowedVisibility($allowedVisibility) { |
|
| 134 | + return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility); |
|
| 135 | + } |
|
| 136 | 136 | } |