@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | 175 | public function getId() { |
| 176 | - return 'shared::' . $this->getMountPoint(); |
|
| 176 | + return 'shared::'.$this->getMountPoint(); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | $info = array( |
| 272 | - 'target' => $this->getMountPoint() . $path, |
|
| 272 | + 'target' => $this->getMountPoint().$path, |
|
| 273 | 273 | 'source' => $source, |
| 274 | 274 | 'mode' => $mode, |
| 275 | 275 | ); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | |
| 479 | 479 | public function file_get_contents($path) { |
| 480 | 480 | $info = [ |
| 481 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 481 | + 'target' => $this->getMountPoint().'/'.$path, |
|
| 482 | 482 | 'source' => $this->getUnjailedPath($path), |
| 483 | 483 | ]; |
| 484 | 484 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | public function file_put_contents($path, $data) { |
| 489 | 489 | $info = [ |
| 490 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 490 | + 'target' => $this->getMountPoint().'/'.$path, |
|
| 491 | 491 | 'source' => $this->getUnjailedPath($path), |
| 492 | 492 | ]; |
| 493 | 493 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
@@ -47,442 +47,442 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { |
| 49 | 49 | |
| 50 | - /** @var \OCP\Share\IShare */ |
|
| 51 | - private $superShare; |
|
| 52 | - |
|
| 53 | - /** @var \OCP\Share\IShare[] */ |
|
| 54 | - private $groupedShares; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \OC\Files\View |
|
| 58 | - */ |
|
| 59 | - private $ownerView; |
|
| 60 | - |
|
| 61 | - private $initialized = false; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var ICacheEntry |
|
| 65 | - */ |
|
| 66 | - private $sourceRootInfo; |
|
| 67 | - |
|
| 68 | - /** @var string */ |
|
| 69 | - private $user; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var \OCP\ILogger |
|
| 73 | - */ |
|
| 74 | - private $logger; |
|
| 75 | - |
|
| 76 | - /** @var IStorage */ |
|
| 77 | - private $nonMaskedStorage; |
|
| 78 | - |
|
| 79 | - private $options; |
|
| 80 | - |
|
| 81 | - public function __construct($arguments) { |
|
| 82 | - $this->ownerView = $arguments['ownerView']; |
|
| 83 | - $this->logger = \OC::$server->getLogger(); |
|
| 84 | - |
|
| 85 | - $this->superShare = $arguments['superShare']; |
|
| 86 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 87 | - |
|
| 88 | - $this->user = $arguments['user']; |
|
| 89 | - |
|
| 90 | - parent::__construct([ |
|
| 91 | - 'storage' => null, |
|
| 92 | - 'root' => null, |
|
| 93 | - ]); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return ICacheEntry |
|
| 98 | - */ |
|
| 99 | - private function getSourceRootInfo() { |
|
| 100 | - if (is_null($this->sourceRootInfo)) { |
|
| 101 | - if (is_null($this->superShare->getNodeCacheEntry())) { |
|
| 102 | - $this->init(); |
|
| 103 | - $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
| 104 | - } else { |
|
| 105 | - $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - return $this->sourceRootInfo; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - private function init() { |
|
| 112 | - if ($this->initialized) { |
|
| 113 | - return; |
|
| 114 | - } |
|
| 115 | - $this->initialized = true; |
|
| 116 | - try { |
|
| 117 | - Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
| 118 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 119 | - list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
| 120 | - $this->storage = new PermissionsMask([ |
|
| 121 | - 'storage' => $this->nonMaskedStorage, |
|
| 122 | - 'mask' => $this->superShare->getPermissions() |
|
| 123 | - ]); |
|
| 124 | - } catch (NotFoundException $e) { |
|
| 125 | - // original file not accessible or deleted, set FailedStorage |
|
| 126 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 127 | - $this->cache = new FailedCache(); |
|
| 128 | - $this->rootPath = ''; |
|
| 129 | - } catch (NoUserException $e) { |
|
| 130 | - // sharer user deleted, set FailedStorage |
|
| 131 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 132 | - $this->cache = new FailedCache(); |
|
| 133 | - $this->rootPath = ''; |
|
| 134 | - } catch (\Exception $e) { |
|
| 135 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 136 | - $this->cache = new FailedCache(); |
|
| 137 | - $this->rootPath = ''; |
|
| 138 | - $this->logger->logException($e); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if (!$this->nonMaskedStorage) { |
|
| 142 | - $this->nonMaskedStorage = $this->storage; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @inheritdoc |
|
| 148 | - */ |
|
| 149 | - public function instanceOfStorage($class) { |
|
| 150 | - if ($class === '\OC\Files\Storage\Common') { |
|
| 151 | - return true; |
|
| 152 | - } |
|
| 153 | - if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - return parent::instanceOfStorage($class); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function getShareId() { |
|
| 163 | - return $this->superShare->getId(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - private function isValid() { |
|
| 167 | - return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * get id of the mount point |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function getId() { |
|
| 176 | - return 'shared::' . $this->getMountPoint(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the permissions granted for a shared file |
|
| 181 | - * |
|
| 182 | - * @param string $target Shared target file path |
|
| 183 | - * @return int CRUDS permissions granted |
|
| 184 | - */ |
|
| 185 | - public function getPermissions($target = '') { |
|
| 186 | - if (!$this->isValid()) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - $permissions = $this->superShare->getPermissions(); |
|
| 190 | - // part files and the mount point always have delete permissions |
|
| 191 | - if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
| 192 | - $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if (\OCP\Util::isSharingDisabledForUser()) { |
|
| 196 | - $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $permissions; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - public function isCreatable($path) { |
|
| 203 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public function isReadable($path) { |
|
| 207 | - if (!$this->isValid()) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - if (!$this->file_exists($path)) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - /** @var IStorage $storage */ |
|
| 214 | - /** @var string $internalPath */ |
|
| 215 | - list($storage, $internalPath) = $this->resolvePath($path); |
|
| 216 | - return $storage->isReadable($internalPath); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public function isUpdatable($path) { |
|
| 220 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function isDeletable($path) { |
|
| 224 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - public function isSharable($path) { |
|
| 228 | - if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - public function fopen($path, $mode) { |
|
| 235 | - if ($source = $this->getUnjailedPath($path)) { |
|
| 236 | - switch ($mode) { |
|
| 237 | - case 'r+': |
|
| 238 | - case 'rb+': |
|
| 239 | - case 'w+': |
|
| 240 | - case 'wb+': |
|
| 241 | - case 'x+': |
|
| 242 | - case 'xb+': |
|
| 243 | - case 'a+': |
|
| 244 | - case 'ab+': |
|
| 245 | - case 'w': |
|
| 246 | - case 'wb': |
|
| 247 | - case 'x': |
|
| 248 | - case 'xb': |
|
| 249 | - case 'a': |
|
| 250 | - case 'ab': |
|
| 251 | - $creatable = $this->isCreatable($path); |
|
| 252 | - $updatable = $this->isUpdatable($path); |
|
| 253 | - // if neither permissions given, no need to continue |
|
| 254 | - if (!$creatable && !$updatable) { |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $exists = $this->file_exists($path); |
|
| 259 | - // if a file exists, updatable permissions are required |
|
| 260 | - if ($exists && !$updatable) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // part file is allowed if !$creatable but the final file is $updatable |
|
| 265 | - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
| 266 | - if (!$exists && !$creatable) { |
|
| 267 | - return false; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - $info = array( |
|
| 272 | - 'target' => $this->getMountPoint() . $path, |
|
| 273 | - 'source' => $source, |
|
| 274 | - 'mode' => $mode, |
|
| 275 | - ); |
|
| 276 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
| 277 | - return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
| 278 | - } |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * see http://php.net/manual/en/function.rename.php |
|
| 284 | - * |
|
| 285 | - * @param string $path1 |
|
| 286 | - * @param string $path2 |
|
| 287 | - * @return bool |
|
| 288 | - */ |
|
| 289 | - public function rename($path1, $path2) { |
|
| 290 | - $this->init(); |
|
| 291 | - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
| 292 | - $targetExists = $this->file_exists($path2); |
|
| 293 | - $sameFodler = dirname($path1) === dirname($path2); |
|
| 294 | - |
|
| 295 | - if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
| 296 | - if (!$this->isUpdatable('')) { |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 299 | - } else { |
|
| 300 | - if (!$this->isCreatable('')) { |
|
| 301 | - return false; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * return mount point of share, relative to data/user/files |
|
| 310 | - * |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - public function getMountPoint() { |
|
| 314 | - return $this->superShare->getTarget(); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param string $path |
|
| 319 | - */ |
|
| 320 | - public function setMountPoint($path) { |
|
| 321 | - $this->superShare->setTarget($path); |
|
| 322 | - |
|
| 323 | - foreach ($this->groupedShares as $share) { |
|
| 324 | - $share->setTarget($path); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * get the user who shared the file |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function getSharedFrom() { |
|
| 334 | - return $this->superShare->getShareOwner(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return \OCP\Share\IShare |
|
| 339 | - */ |
|
| 340 | - public function getShare() { |
|
| 341 | - return $this->superShare; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * return share type, can be "file" or "folder" |
|
| 346 | - * |
|
| 347 | - * @return string |
|
| 348 | - */ |
|
| 349 | - public function getItemType() { |
|
| 350 | - return $this->superShare->getNodeType(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param string $path |
|
| 355 | - * @param null $storage |
|
| 356 | - * @return Cache |
|
| 357 | - */ |
|
| 358 | - public function getCache($path = '', $storage = null) { |
|
| 359 | - if ($this->cache) { |
|
| 360 | - return $this->cache; |
|
| 361 | - } |
|
| 362 | - if (!$storage) { |
|
| 363 | - $storage = $this; |
|
| 364 | - } |
|
| 365 | - if ($this->storage instanceof FailedStorage) { |
|
| 366 | - return new FailedCache(); |
|
| 367 | - } |
|
| 368 | - $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
| 369 | - return $this->cache; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - public function getScanner($path = '', $storage = null) { |
|
| 373 | - if (!$storage) { |
|
| 374 | - $storage = $this; |
|
| 375 | - } |
|
| 376 | - return new \OCA\Files_Sharing\Scanner($storage); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public function getOwner($path) { |
|
| 380 | - return $this->superShare->getShareOwner(); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * unshare complete storage, also the grouped shares |
|
| 385 | - * |
|
| 386 | - * @return bool |
|
| 387 | - */ |
|
| 388 | - public function unshareStorage() { |
|
| 389 | - foreach ($this->groupedShares as $share) { |
|
| 390 | - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
| 391 | - } |
|
| 392 | - return true; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param string $path |
|
| 397 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 398 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 399 | - * @throws \OCP\Lock\LockedException |
|
| 400 | - */ |
|
| 401 | - public function acquireLock($path, $type, ILockingProvider $provider) { |
|
| 402 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 403 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 404 | - $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
| 405 | - // lock the parent folders of the owner when locking the share as recipient |
|
| 406 | - if ($path === '') { |
|
| 407 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 408 | - $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * @param string $path |
|
| 414 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 415 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 416 | - */ |
|
| 417 | - public function releaseLock($path, $type, ILockingProvider $provider) { |
|
| 418 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 419 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 420 | - $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
| 421 | - // unlock the parent folders of the owner when unlocking the share as recipient |
|
| 422 | - if ($path === '') { |
|
| 423 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 424 | - $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param string $path |
|
| 430 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 431 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 432 | - */ |
|
| 433 | - public function changeLock($path, $type, ILockingProvider $provider) { |
|
| 434 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 435 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 436 | - $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @return array [ available, last_checked ] |
|
| 441 | - */ |
|
| 442 | - public function getAvailability() { |
|
| 443 | - // shares do not participate in availability logic |
|
| 444 | - return [ |
|
| 445 | - 'available' => true, |
|
| 446 | - 'last_checked' => 0 |
|
| 447 | - ]; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @param bool $available |
|
| 452 | - */ |
|
| 453 | - public function setAvailability($available) { |
|
| 454 | - // shares do not participate in availability logic |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - public function getSourceStorage() { |
|
| 458 | - $this->init(); |
|
| 459 | - return $this->nonMaskedStorage; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - public function getWrapperStorage() { |
|
| 463 | - $this->init(); |
|
| 464 | - return $this->storage; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - public function file_get_contents($path) { |
|
| 468 | - $info = [ |
|
| 469 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 470 | - 'source' => $this->getUnjailedPath($path), |
|
| 471 | - ]; |
|
| 472 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
| 473 | - return parent::file_get_contents($path); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - public function file_put_contents($path, $data) { |
|
| 477 | - $info = [ |
|
| 478 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 479 | - 'source' => $this->getUnjailedPath($path), |
|
| 480 | - ]; |
|
| 481 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
| 482 | - return parent::file_put_contents($path, $data); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - public function setMountOptions(array $options) { |
|
| 486 | - $this->mountOptions = $options; |
|
| 487 | - } |
|
| 50 | + /** @var \OCP\Share\IShare */ |
|
| 51 | + private $superShare; |
|
| 52 | + |
|
| 53 | + /** @var \OCP\Share\IShare[] */ |
|
| 54 | + private $groupedShares; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \OC\Files\View |
|
| 58 | + */ |
|
| 59 | + private $ownerView; |
|
| 60 | + |
|
| 61 | + private $initialized = false; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var ICacheEntry |
|
| 65 | + */ |
|
| 66 | + private $sourceRootInfo; |
|
| 67 | + |
|
| 68 | + /** @var string */ |
|
| 69 | + private $user; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var \OCP\ILogger |
|
| 73 | + */ |
|
| 74 | + private $logger; |
|
| 75 | + |
|
| 76 | + /** @var IStorage */ |
|
| 77 | + private $nonMaskedStorage; |
|
| 78 | + |
|
| 79 | + private $options; |
|
| 80 | + |
|
| 81 | + public function __construct($arguments) { |
|
| 82 | + $this->ownerView = $arguments['ownerView']; |
|
| 83 | + $this->logger = \OC::$server->getLogger(); |
|
| 84 | + |
|
| 85 | + $this->superShare = $arguments['superShare']; |
|
| 86 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 87 | + |
|
| 88 | + $this->user = $arguments['user']; |
|
| 89 | + |
|
| 90 | + parent::__construct([ |
|
| 91 | + 'storage' => null, |
|
| 92 | + 'root' => null, |
|
| 93 | + ]); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return ICacheEntry |
|
| 98 | + */ |
|
| 99 | + private function getSourceRootInfo() { |
|
| 100 | + if (is_null($this->sourceRootInfo)) { |
|
| 101 | + if (is_null($this->superShare->getNodeCacheEntry())) { |
|
| 102 | + $this->init(); |
|
| 103 | + $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
| 104 | + } else { |
|
| 105 | + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + return $this->sourceRootInfo; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + private function init() { |
|
| 112 | + if ($this->initialized) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 115 | + $this->initialized = true; |
|
| 116 | + try { |
|
| 117 | + Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
| 118 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 119 | + list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
| 120 | + $this->storage = new PermissionsMask([ |
|
| 121 | + 'storage' => $this->nonMaskedStorage, |
|
| 122 | + 'mask' => $this->superShare->getPermissions() |
|
| 123 | + ]); |
|
| 124 | + } catch (NotFoundException $e) { |
|
| 125 | + // original file not accessible or deleted, set FailedStorage |
|
| 126 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 127 | + $this->cache = new FailedCache(); |
|
| 128 | + $this->rootPath = ''; |
|
| 129 | + } catch (NoUserException $e) { |
|
| 130 | + // sharer user deleted, set FailedStorage |
|
| 131 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 132 | + $this->cache = new FailedCache(); |
|
| 133 | + $this->rootPath = ''; |
|
| 134 | + } catch (\Exception $e) { |
|
| 135 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 136 | + $this->cache = new FailedCache(); |
|
| 137 | + $this->rootPath = ''; |
|
| 138 | + $this->logger->logException($e); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if (!$this->nonMaskedStorage) { |
|
| 142 | + $this->nonMaskedStorage = $this->storage; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @inheritdoc |
|
| 148 | + */ |
|
| 149 | + public function instanceOfStorage($class) { |
|
| 150 | + if ($class === '\OC\Files\Storage\Common') { |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 153 | + if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + return parent::instanceOfStorage($class); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function getShareId() { |
|
| 163 | + return $this->superShare->getId(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + private function isValid() { |
|
| 167 | + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * get id of the mount point |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function getId() { |
|
| 176 | + return 'shared::' . $this->getMountPoint(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the permissions granted for a shared file |
|
| 181 | + * |
|
| 182 | + * @param string $target Shared target file path |
|
| 183 | + * @return int CRUDS permissions granted |
|
| 184 | + */ |
|
| 185 | + public function getPermissions($target = '') { |
|
| 186 | + if (!$this->isValid()) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + $permissions = $this->superShare->getPermissions(); |
|
| 190 | + // part files and the mount point always have delete permissions |
|
| 191 | + if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
| 192 | + $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if (\OCP\Util::isSharingDisabledForUser()) { |
|
| 196 | + $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $permissions; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + public function isCreatable($path) { |
|
| 203 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public function isReadable($path) { |
|
| 207 | + if (!$this->isValid()) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + if (!$this->file_exists($path)) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + /** @var IStorage $storage */ |
|
| 214 | + /** @var string $internalPath */ |
|
| 215 | + list($storage, $internalPath) = $this->resolvePath($path); |
|
| 216 | + return $storage->isReadable($internalPath); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function isUpdatable($path) { |
|
| 220 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function isDeletable($path) { |
|
| 224 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + public function isSharable($path) { |
|
| 228 | + if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + public function fopen($path, $mode) { |
|
| 235 | + if ($source = $this->getUnjailedPath($path)) { |
|
| 236 | + switch ($mode) { |
|
| 237 | + case 'r+': |
|
| 238 | + case 'rb+': |
|
| 239 | + case 'w+': |
|
| 240 | + case 'wb+': |
|
| 241 | + case 'x+': |
|
| 242 | + case 'xb+': |
|
| 243 | + case 'a+': |
|
| 244 | + case 'ab+': |
|
| 245 | + case 'w': |
|
| 246 | + case 'wb': |
|
| 247 | + case 'x': |
|
| 248 | + case 'xb': |
|
| 249 | + case 'a': |
|
| 250 | + case 'ab': |
|
| 251 | + $creatable = $this->isCreatable($path); |
|
| 252 | + $updatable = $this->isUpdatable($path); |
|
| 253 | + // if neither permissions given, no need to continue |
|
| 254 | + if (!$creatable && !$updatable) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $exists = $this->file_exists($path); |
|
| 259 | + // if a file exists, updatable permissions are required |
|
| 260 | + if ($exists && !$updatable) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // part file is allowed if !$creatable but the final file is $updatable |
|
| 265 | + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
| 266 | + if (!$exists && !$creatable) { |
|
| 267 | + return false; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + $info = array( |
|
| 272 | + 'target' => $this->getMountPoint() . $path, |
|
| 273 | + 'source' => $source, |
|
| 274 | + 'mode' => $mode, |
|
| 275 | + ); |
|
| 276 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
| 277 | + return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
| 278 | + } |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * see http://php.net/manual/en/function.rename.php |
|
| 284 | + * |
|
| 285 | + * @param string $path1 |
|
| 286 | + * @param string $path2 |
|
| 287 | + * @return bool |
|
| 288 | + */ |
|
| 289 | + public function rename($path1, $path2) { |
|
| 290 | + $this->init(); |
|
| 291 | + $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
| 292 | + $targetExists = $this->file_exists($path2); |
|
| 293 | + $sameFodler = dirname($path1) === dirname($path2); |
|
| 294 | + |
|
| 295 | + if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
| 296 | + if (!$this->isUpdatable('')) { |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | + } else { |
|
| 300 | + if (!$this->isCreatable('')) { |
|
| 301 | + return false; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * return mount point of share, relative to data/user/files |
|
| 310 | + * |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + public function getMountPoint() { |
|
| 314 | + return $this->superShare->getTarget(); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param string $path |
|
| 319 | + */ |
|
| 320 | + public function setMountPoint($path) { |
|
| 321 | + $this->superShare->setTarget($path); |
|
| 322 | + |
|
| 323 | + foreach ($this->groupedShares as $share) { |
|
| 324 | + $share->setTarget($path); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * get the user who shared the file |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function getSharedFrom() { |
|
| 334 | + return $this->superShare->getShareOwner(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return \OCP\Share\IShare |
|
| 339 | + */ |
|
| 340 | + public function getShare() { |
|
| 341 | + return $this->superShare; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * return share type, can be "file" or "folder" |
|
| 346 | + * |
|
| 347 | + * @return string |
|
| 348 | + */ |
|
| 349 | + public function getItemType() { |
|
| 350 | + return $this->superShare->getNodeType(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param string $path |
|
| 355 | + * @param null $storage |
|
| 356 | + * @return Cache |
|
| 357 | + */ |
|
| 358 | + public function getCache($path = '', $storage = null) { |
|
| 359 | + if ($this->cache) { |
|
| 360 | + return $this->cache; |
|
| 361 | + } |
|
| 362 | + if (!$storage) { |
|
| 363 | + $storage = $this; |
|
| 364 | + } |
|
| 365 | + if ($this->storage instanceof FailedStorage) { |
|
| 366 | + return new FailedCache(); |
|
| 367 | + } |
|
| 368 | + $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
| 369 | + return $this->cache; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + public function getScanner($path = '', $storage = null) { |
|
| 373 | + if (!$storage) { |
|
| 374 | + $storage = $this; |
|
| 375 | + } |
|
| 376 | + return new \OCA\Files_Sharing\Scanner($storage); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public function getOwner($path) { |
|
| 380 | + return $this->superShare->getShareOwner(); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * unshare complete storage, also the grouped shares |
|
| 385 | + * |
|
| 386 | + * @return bool |
|
| 387 | + */ |
|
| 388 | + public function unshareStorage() { |
|
| 389 | + foreach ($this->groupedShares as $share) { |
|
| 390 | + \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
| 391 | + } |
|
| 392 | + return true; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param string $path |
|
| 397 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 398 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 399 | + * @throws \OCP\Lock\LockedException |
|
| 400 | + */ |
|
| 401 | + public function acquireLock($path, $type, ILockingProvider $provider) { |
|
| 402 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 403 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 404 | + $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
| 405 | + // lock the parent folders of the owner when locking the share as recipient |
|
| 406 | + if ($path === '') { |
|
| 407 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 408 | + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * @param string $path |
|
| 414 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 415 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 416 | + */ |
|
| 417 | + public function releaseLock($path, $type, ILockingProvider $provider) { |
|
| 418 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 419 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 420 | + $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
| 421 | + // unlock the parent folders of the owner when unlocking the share as recipient |
|
| 422 | + if ($path === '') { |
|
| 423 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 424 | + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @param string $path |
|
| 430 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 431 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 432 | + */ |
|
| 433 | + public function changeLock($path, $type, ILockingProvider $provider) { |
|
| 434 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 435 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 436 | + $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @return array [ available, last_checked ] |
|
| 441 | + */ |
|
| 442 | + public function getAvailability() { |
|
| 443 | + // shares do not participate in availability logic |
|
| 444 | + return [ |
|
| 445 | + 'available' => true, |
|
| 446 | + 'last_checked' => 0 |
|
| 447 | + ]; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @param bool $available |
|
| 452 | + */ |
|
| 453 | + public function setAvailability($available) { |
|
| 454 | + // shares do not participate in availability logic |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + public function getSourceStorage() { |
|
| 458 | + $this->init(); |
|
| 459 | + return $this->nonMaskedStorage; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + public function getWrapperStorage() { |
|
| 463 | + $this->init(); |
|
| 464 | + return $this->storage; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + public function file_get_contents($path) { |
|
| 468 | + $info = [ |
|
| 469 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
| 470 | + 'source' => $this->getUnjailedPath($path), |
|
| 471 | + ]; |
|
| 472 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
| 473 | + return parent::file_get_contents($path); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + public function file_put_contents($path, $data) { |
|
| 477 | + $info = [ |
|
| 478 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
| 479 | + 'source' => $this->getUnjailedPath($path), |
|
| 480 | + ]; |
|
| 481 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
| 482 | + return parent::file_put_contents($path, $data); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + public function setMountOptions(array $options) { |
|
| 486 | + $this->mountOptions = $options; |
|
| 487 | + } |
|
| 488 | 488 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | protected function setSubjects(IEvent $event, $subject, array $parameters) { |
| 50 | 50 | $placeholders = $replacements = []; |
| 51 | 51 | foreach ($parameters as $placeholder => $parameter) { |
| 52 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 52 | + $placeholders[] = '{'.$placeholder.'}'; |
|
| 53 | 53 | $replacements[] = $parameter['name']; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -32,157 +32,157 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Provider implements IProvider { |
| 34 | 34 | |
| 35 | - const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
| 36 | - const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
| 37 | - const PASSWORD_RESET = 'password_changed'; |
|
| 38 | - const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
| 39 | - const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
| 40 | - const EMAIL_CHANGED = 'email_changed'; |
|
| 41 | - |
|
| 42 | - /** @var IFactory */ |
|
| 43 | - protected $languageFactory; |
|
| 44 | - |
|
| 45 | - /** @var IL10N */ |
|
| 46 | - protected $l; |
|
| 47 | - |
|
| 48 | - /** @var IURLGenerator */ |
|
| 49 | - protected $url; |
|
| 50 | - |
|
| 51 | - /** @var IUserManager */ |
|
| 52 | - protected $userManager; |
|
| 53 | - |
|
| 54 | - /** @var IManager */ |
|
| 55 | - private $activityManager; |
|
| 56 | - |
|
| 57 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
| 58 | - protected $displayNames = []; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param IFactory $languageFactory |
|
| 62 | - * @param IURLGenerator $url |
|
| 63 | - * @param IUserManager $userManager |
|
| 64 | - * @param IManager $activityManager |
|
| 65 | - */ |
|
| 66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
| 67 | - $this->languageFactory = $languageFactory; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->userManager = $userManager; |
|
| 70 | - $this->activityManager = $activityManager; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param string $language |
|
| 75 | - * @param IEvent $event |
|
| 76 | - * @param IEvent|null $previousEvent |
|
| 77 | - * @return IEvent |
|
| 78 | - * @throws \InvalidArgumentException |
|
| 79 | - * @since 11.0.0 |
|
| 80 | - */ |
|
| 81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 82 | - if ($event->getApp() !== 'settings') { |
|
| 83 | - throw new \InvalidArgumentException(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->l = $this->languageFactory->get('settings', $language); |
|
| 87 | - |
|
| 88 | - if ($this->activityManager->getRequirePNG()) { |
|
| 89 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
| 90 | - } else { |
|
| 91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
| 95 | - $subject = $this->l->t('{actor} changed your password'); |
|
| 96 | - } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
| 97 | - $subject = $this->l->t('You changed your password'); |
|
| 98 | - } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
| 99 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
| 100 | - |
|
| 101 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
| 102 | - $subject = $this->l->t('{actor} changed your email address'); |
|
| 103 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
| 104 | - $subject = $this->l->t('You changed your email address'); |
|
| 105 | - } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
| 106 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
| 107 | - |
|
| 108 | - } else { |
|
| 109 | - throw new \InvalidArgumentException(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $parsedParameters = $this->getParameters($event); |
|
| 113 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
| 114 | - |
|
| 115 | - return $event; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param IEvent $event |
|
| 120 | - * @return array |
|
| 121 | - * @throws \InvalidArgumentException |
|
| 122 | - */ |
|
| 123 | - protected function getParameters(IEvent $event) { |
|
| 124 | - $subject = $event->getSubject(); |
|
| 125 | - $parameters = $event->getSubjectParameters(); |
|
| 126 | - |
|
| 127 | - switch ($subject) { |
|
| 128 | - case self::PASSWORD_CHANGED_SELF: |
|
| 129 | - case self::PASSWORD_RESET: |
|
| 130 | - case self::EMAIL_CHANGED_SELF: |
|
| 131 | - case self::EMAIL_CHANGED: |
|
| 132 | - return []; |
|
| 133 | - case self::PASSWORD_CHANGED_BY: |
|
| 134 | - case self::EMAIL_CHANGED_BY: |
|
| 135 | - return [ |
|
| 136 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
| 137 | - ]; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - throw new \InvalidArgumentException(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param IEvent $event |
|
| 145 | - * @param string $subject |
|
| 146 | - * @param array $parameters |
|
| 147 | - * @throws \InvalidArgumentException |
|
| 148 | - */ |
|
| 149 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 150 | - $placeholders = $replacements = []; |
|
| 151 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 152 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 153 | - $replacements[] = $parameter['name']; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 157 | - ->setRichSubject($subject, $parameters); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $uid |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - protected function generateUserParameter($uid) { |
|
| 165 | - if (!isset($this->displayNames[$uid])) { |
|
| 166 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return [ |
|
| 170 | - 'type' => 'user', |
|
| 171 | - 'id' => $uid, |
|
| 172 | - 'name' => $this->displayNames[$uid], |
|
| 173 | - ]; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $uid |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - protected function getDisplayName($uid) { |
|
| 181 | - $user = $this->userManager->get($uid); |
|
| 182 | - if ($user instanceof IUser) { |
|
| 183 | - return $user->getDisplayName(); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - return $uid; |
|
| 187 | - } |
|
| 35 | + const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
| 36 | + const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
| 37 | + const PASSWORD_RESET = 'password_changed'; |
|
| 38 | + const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
| 39 | + const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
| 40 | + const EMAIL_CHANGED = 'email_changed'; |
|
| 41 | + |
|
| 42 | + /** @var IFactory */ |
|
| 43 | + protected $languageFactory; |
|
| 44 | + |
|
| 45 | + /** @var IL10N */ |
|
| 46 | + protected $l; |
|
| 47 | + |
|
| 48 | + /** @var IURLGenerator */ |
|
| 49 | + protected $url; |
|
| 50 | + |
|
| 51 | + /** @var IUserManager */ |
|
| 52 | + protected $userManager; |
|
| 53 | + |
|
| 54 | + /** @var IManager */ |
|
| 55 | + private $activityManager; |
|
| 56 | + |
|
| 57 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
| 58 | + protected $displayNames = []; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param IFactory $languageFactory |
|
| 62 | + * @param IURLGenerator $url |
|
| 63 | + * @param IUserManager $userManager |
|
| 64 | + * @param IManager $activityManager |
|
| 65 | + */ |
|
| 66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
| 67 | + $this->languageFactory = $languageFactory; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->userManager = $userManager; |
|
| 70 | + $this->activityManager = $activityManager; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param string $language |
|
| 75 | + * @param IEvent $event |
|
| 76 | + * @param IEvent|null $previousEvent |
|
| 77 | + * @return IEvent |
|
| 78 | + * @throws \InvalidArgumentException |
|
| 79 | + * @since 11.0.0 |
|
| 80 | + */ |
|
| 81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
| 82 | + if ($event->getApp() !== 'settings') { |
|
| 83 | + throw new \InvalidArgumentException(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->l = $this->languageFactory->get('settings', $language); |
|
| 87 | + |
|
| 88 | + if ($this->activityManager->getRequirePNG()) { |
|
| 89 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
| 90 | + } else { |
|
| 91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
| 95 | + $subject = $this->l->t('{actor} changed your password'); |
|
| 96 | + } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
| 97 | + $subject = $this->l->t('You changed your password'); |
|
| 98 | + } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
| 99 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
| 100 | + |
|
| 101 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
| 102 | + $subject = $this->l->t('{actor} changed your email address'); |
|
| 103 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
| 104 | + $subject = $this->l->t('You changed your email address'); |
|
| 105 | + } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
| 106 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
| 107 | + |
|
| 108 | + } else { |
|
| 109 | + throw new \InvalidArgumentException(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $parsedParameters = $this->getParameters($event); |
|
| 113 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
| 114 | + |
|
| 115 | + return $event; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param IEvent $event |
|
| 120 | + * @return array |
|
| 121 | + * @throws \InvalidArgumentException |
|
| 122 | + */ |
|
| 123 | + protected function getParameters(IEvent $event) { |
|
| 124 | + $subject = $event->getSubject(); |
|
| 125 | + $parameters = $event->getSubjectParameters(); |
|
| 126 | + |
|
| 127 | + switch ($subject) { |
|
| 128 | + case self::PASSWORD_CHANGED_SELF: |
|
| 129 | + case self::PASSWORD_RESET: |
|
| 130 | + case self::EMAIL_CHANGED_SELF: |
|
| 131 | + case self::EMAIL_CHANGED: |
|
| 132 | + return []; |
|
| 133 | + case self::PASSWORD_CHANGED_BY: |
|
| 134 | + case self::EMAIL_CHANGED_BY: |
|
| 135 | + return [ |
|
| 136 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
| 137 | + ]; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + throw new \InvalidArgumentException(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param IEvent $event |
|
| 145 | + * @param string $subject |
|
| 146 | + * @param array $parameters |
|
| 147 | + * @throws \InvalidArgumentException |
|
| 148 | + */ |
|
| 149 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
| 150 | + $placeholders = $replacements = []; |
|
| 151 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 152 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 153 | + $replacements[] = $parameter['name']; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
| 157 | + ->setRichSubject($subject, $parameters); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $uid |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + protected function generateUserParameter($uid) { |
|
| 165 | + if (!isset($this->displayNames[$uid])) { |
|
| 166 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return [ |
|
| 170 | + 'type' => 'user', |
|
| 171 | + 'id' => $uid, |
|
| 172 | + 'name' => $this->displayNames[$uid], |
|
| 173 | + ]; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $uid |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + protected function getDisplayName($uid) { |
|
| 181 | + $user = $this->userManager->get($uid); |
|
| 182 | + if ($user instanceof IUser) { |
|
| 183 | + return $user->getDisplayName(); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + return $uid; |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -25,28 +25,28 @@ |
||
| 25 | 25 | use OCP\AppFramework\Http\JSONResponse; |
| 26 | 26 | |
| 27 | 27 | class RateLimitTestController extends Controller { |
| 28 | - /** |
|
| 29 | - * @PublicPage |
|
| 30 | - * @NoCSRFRequired |
|
| 31 | - * |
|
| 32 | - * @UserRateThrottle(limit=5, period=100) |
|
| 33 | - * @AnonRateThrottle(limit=1, period=100) |
|
| 34 | - * |
|
| 35 | - * @return JSONResponse |
|
| 36 | - */ |
|
| 37 | - public function userAndAnonProtected() { |
|
| 38 | - return new JSONResponse(); |
|
| 39 | - } |
|
| 28 | + /** |
|
| 29 | + * @PublicPage |
|
| 30 | + * @NoCSRFRequired |
|
| 31 | + * |
|
| 32 | + * @UserRateThrottle(limit=5, period=100) |
|
| 33 | + * @AnonRateThrottle(limit=1, period=100) |
|
| 34 | + * |
|
| 35 | + * @return JSONResponse |
|
| 36 | + */ |
|
| 37 | + public function userAndAnonProtected() { |
|
| 38 | + return new JSONResponse(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @PublicPage |
|
| 43 | - * @NoCSRFRequired |
|
| 44 | - * |
|
| 45 | - * @AnonRateThrottle(limit=1, period=10) |
|
| 46 | - * |
|
| 47 | - * @return JSONResponse |
|
| 48 | - */ |
|
| 49 | - public function onlyAnonProtected() { |
|
| 50 | - return new JSONResponse(); |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * @PublicPage |
|
| 43 | + * @NoCSRFRequired |
|
| 44 | + * |
|
| 45 | + * @AnonRateThrottle(limit=1, period=10) |
|
| 46 | + * |
|
| 47 | + * @return JSONResponse |
|
| 48 | + */ |
|
| 49 | + public function onlyAnonProtected() { |
|
| 50 | + return new JSONResponse(); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | use OCP\AppFramework\Http; |
| 26 | 26 | |
| 27 | 27 | class RateLimitExceededException extends SecurityException { |
| 28 | - public function __construct() { |
|
| 29 | - parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
| 30 | - } |
|
| 28 | + public function __construct() { |
|
| 29 | + parent::__construct('Rate limit exceeded', Http::STATUS_TOO_MANY_REQUESTS); |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -48,87 +48,87 @@ |
||
| 48 | 48 | * @package OC\AppFramework\Middleware\Security |
| 49 | 49 | */ |
| 50 | 50 | class RateLimitingMiddleware extends Middleware { |
| 51 | - /** @var IRequest $request */ |
|
| 52 | - private $request; |
|
| 53 | - /** @var IUserSession */ |
|
| 54 | - private $userSession; |
|
| 55 | - /** @var ControllerMethodReflector */ |
|
| 56 | - private $reflector; |
|
| 57 | - /** @var Limiter */ |
|
| 58 | - private $limiter; |
|
| 51 | + /** @var IRequest $request */ |
|
| 52 | + private $request; |
|
| 53 | + /** @var IUserSession */ |
|
| 54 | + private $userSession; |
|
| 55 | + /** @var ControllerMethodReflector */ |
|
| 56 | + private $reflector; |
|
| 57 | + /** @var Limiter */ |
|
| 58 | + private $limiter; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param IRequest $request |
|
| 62 | - * @param IUserSession $userSession |
|
| 63 | - * @param ControllerMethodReflector $reflector |
|
| 64 | - * @param Limiter $limiter |
|
| 65 | - */ |
|
| 66 | - public function __construct(IRequest $request, |
|
| 67 | - IUserSession $userSession, |
|
| 68 | - ControllerMethodReflector $reflector, |
|
| 69 | - Limiter $limiter) { |
|
| 70 | - $this->request = $request; |
|
| 71 | - $this->userSession = $userSession; |
|
| 72 | - $this->reflector = $reflector; |
|
| 73 | - $this->limiter = $limiter; |
|
| 74 | - } |
|
| 60 | + /** |
|
| 61 | + * @param IRequest $request |
|
| 62 | + * @param IUserSession $userSession |
|
| 63 | + * @param ControllerMethodReflector $reflector |
|
| 64 | + * @param Limiter $limiter |
|
| 65 | + */ |
|
| 66 | + public function __construct(IRequest $request, |
|
| 67 | + IUserSession $userSession, |
|
| 68 | + ControllerMethodReflector $reflector, |
|
| 69 | + Limiter $limiter) { |
|
| 70 | + $this->request = $request; |
|
| 71 | + $this->userSession = $userSession; |
|
| 72 | + $this->reflector = $reflector; |
|
| 73 | + $this->limiter = $limiter; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * {@inheritDoc} |
|
| 78 | - * @throws RateLimitExceededException |
|
| 79 | - */ |
|
| 80 | - public function beforeController($controller, $methodName) { |
|
| 81 | - parent::beforeController($controller, $methodName); |
|
| 76 | + /** |
|
| 77 | + * {@inheritDoc} |
|
| 78 | + * @throws RateLimitExceededException |
|
| 79 | + */ |
|
| 80 | + public function beforeController($controller, $methodName) { |
|
| 81 | + parent::beforeController($controller, $methodName); |
|
| 82 | 82 | |
| 83 | - $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
| 84 | - $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
| 85 | - $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
| 86 | - $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
| 87 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
| 88 | - if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 89 | - $this->limiter->registerUserRequest( |
|
| 90 | - $rateLimitIdentifier, |
|
| 91 | - $userLimit, |
|
| 92 | - $userPeriod, |
|
| 93 | - $this->userSession->getUser() |
|
| 94 | - ); |
|
| 95 | - } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
| 96 | - $this->limiter->registerAnonRequest( |
|
| 97 | - $rateLimitIdentifier, |
|
| 98 | - $anonLimit, |
|
| 99 | - $anonPeriod, |
|
| 100 | - $this->request->getRemoteAddress() |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 83 | + $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
| 84 | + $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
| 85 | + $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
| 86 | + $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
| 87 | + $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
| 88 | + if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 89 | + $this->limiter->registerUserRequest( |
|
| 90 | + $rateLimitIdentifier, |
|
| 91 | + $userLimit, |
|
| 92 | + $userPeriod, |
|
| 93 | + $this->userSession->getUser() |
|
| 94 | + ); |
|
| 95 | + } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
| 96 | + $this->limiter->registerAnonRequest( |
|
| 97 | + $rateLimitIdentifier, |
|
| 98 | + $anonLimit, |
|
| 99 | + $anonPeriod, |
|
| 100 | + $this->request->getRemoteAddress() |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * {@inheritDoc} |
|
| 107 | - */ |
|
| 108 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 109 | - if($exception instanceof RateLimitExceededException) { |
|
| 110 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 111 | - $response = new JSONResponse( |
|
| 112 | - [ |
|
| 113 | - 'message' => $exception->getMessage(), |
|
| 114 | - ], |
|
| 115 | - $exception->getCode() |
|
| 116 | - ); |
|
| 117 | - } else { |
|
| 118 | - $response = new TemplateResponse( |
|
| 119 | - 'core', |
|
| 120 | - '403', |
|
| 121 | - [ |
|
| 122 | - 'file' => $exception->getMessage() |
|
| 123 | - ], |
|
| 124 | - 'guest' |
|
| 125 | - ); |
|
| 126 | - $response->setStatus($exception->getCode()); |
|
| 127 | - } |
|
| 105 | + /** |
|
| 106 | + * {@inheritDoc} |
|
| 107 | + */ |
|
| 108 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 109 | + if($exception instanceof RateLimitExceededException) { |
|
| 110 | + if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 111 | + $response = new JSONResponse( |
|
| 112 | + [ |
|
| 113 | + 'message' => $exception->getMessage(), |
|
| 114 | + ], |
|
| 115 | + $exception->getCode() |
|
| 116 | + ); |
|
| 117 | + } else { |
|
| 118 | + $response = new TemplateResponse( |
|
| 119 | + 'core', |
|
| 120 | + '403', |
|
| 121 | + [ |
|
| 122 | + 'file' => $exception->getMessage() |
|
| 123 | + ], |
|
| 124 | + 'guest' |
|
| 125 | + ); |
|
| 126 | + $response->setStatus($exception->getCode()); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return $response; |
|
| 130 | - } |
|
| 129 | + return $response; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - throw $exception; |
|
| 133 | - } |
|
| 132 | + throw $exception; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
| 85 | 85 | $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
| 86 | 86 | $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
| 87 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
| 88 | - if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 87 | + $rateLimitIdentifier = get_class($controller).'::'.$methodName; |
|
| 88 | + if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
| 89 | 89 | $this->limiter->registerUserRequest( |
| 90 | 90 | $rateLimitIdentifier, |
| 91 | 91 | $userLimit, |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * {@inheritDoc} |
| 107 | 107 | */ |
| 108 | 108 | public function afterException($controller, $methodName, \Exception $exception) { |
| 109 | - if($exception instanceof RateLimitExceededException) { |
|
| 110 | - if (stripos($this->request->getHeader('Accept'),'html') === false) { |
|
| 109 | + if ($exception instanceof RateLimitExceededException) { |
|
| 110 | + if (stripos($this->request->getHeader('Accept'), 'html') === false) { |
|
| 111 | 111 | $response = new JSONResponse( |
| 112 | 112 | [ |
| 113 | 113 | 'message' => $exception->getMessage(), |
@@ -26,71 +26,71 @@ |
||
| 26 | 26 | |
| 27 | 27 | class Setting implements ISetting { |
| 28 | 28 | |
| 29 | - /** @var IL10N */ |
|
| 30 | - protected $l; |
|
| 29 | + /** @var IL10N */ |
|
| 30 | + protected $l; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param IL10N $l10n |
|
| 34 | - */ |
|
| 35 | - public function __construct(IL10N $l10n) { |
|
| 36 | - $this->l = $l10n; |
|
| 37 | - } |
|
| 32 | + /** |
|
| 33 | + * @param IL10N $l10n |
|
| 34 | + */ |
|
| 35 | + public function __construct(IL10N $l10n) { |
|
| 36 | + $this->l = $l10n; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string Lowercase a-z and underscore only identifier |
|
| 41 | - * @since 11.0.0 |
|
| 42 | - */ |
|
| 43 | - public function getIdentifier() { |
|
| 44 | - return 'personal_settings'; |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * @return string Lowercase a-z and underscore only identifier |
|
| 41 | + * @since 11.0.0 |
|
| 42 | + */ |
|
| 43 | + public function getIdentifier() { |
|
| 44 | + return 'personal_settings'; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string A translated string |
|
| 49 | - * @since 11.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getName() { |
|
| 52 | - return $this->l->t('Your <strong>password</strong> or <strong>email</strong> was modified'); |
|
| 53 | - } |
|
| 47 | + /** |
|
| 48 | + * @return string A translated string |
|
| 49 | + * @since 11.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getName() { |
|
| 52 | + return $this->l->t('Your <strong>password</strong> or <strong>email</strong> was modified'); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return int whether the filter should be rather on the top or bottom of |
|
| 57 | - * the admin section. The filters are arranged in ascending order of the |
|
| 58 | - * priority values. It is required to return a value between 0 and 100. |
|
| 59 | - * @since 11.0.0 |
|
| 60 | - */ |
|
| 61 | - public function getPriority() { |
|
| 62 | - return 0; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * @return int whether the filter should be rather on the top or bottom of |
|
| 57 | + * the admin section. The filters are arranged in ascending order of the |
|
| 58 | + * priority values. It is required to return a value between 0 and 100. |
|
| 59 | + * @since 11.0.0 |
|
| 60 | + */ |
|
| 61 | + public function getPriority() { |
|
| 62 | + return 0; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return bool True when the option can be changed for the stream |
|
| 67 | - * @since 11.0.0 |
|
| 68 | - */ |
|
| 69 | - public function canChangeStream() { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 65 | + /** |
|
| 66 | + * @return bool True when the option can be changed for the stream |
|
| 67 | + * @since 11.0.0 |
|
| 68 | + */ |
|
| 69 | + public function canChangeStream() { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return bool True when the option can be changed for the stream |
|
| 75 | - * @since 11.0.0 |
|
| 76 | - */ |
|
| 77 | - public function isDefaultEnabledStream() { |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 73 | + /** |
|
| 74 | + * @return bool True when the option can be changed for the stream |
|
| 75 | + * @since 11.0.0 |
|
| 76 | + */ |
|
| 77 | + public function isDefaultEnabledStream() { |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return bool True when the option can be changed for the mail |
|
| 83 | - * @since 11.0.0 |
|
| 84 | - */ |
|
| 85 | - public function canChangeMail() { |
|
| 86 | - return false; |
|
| 87 | - } |
|
| 81 | + /** |
|
| 82 | + * @return bool True when the option can be changed for the mail |
|
| 83 | + * @since 11.0.0 |
|
| 84 | + */ |
|
| 85 | + public function canChangeMail() { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @return bool True when the option can be changed for the stream |
|
| 91 | - * @since 11.0.0 |
|
| 92 | - */ |
|
| 93 | - public function isDefaultEnabledMail() { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 89 | + /** |
|
| 90 | + * @return bool True when the option can be changed for the stream |
|
| 91 | + * @since 11.0.0 |
|
| 92 | + */ |
|
| 93 | + public function isDefaultEnabledMail() { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public function beforeController($controller, $methodName) { |
| 62 | 62 | parent::beforeController($controller, $methodName); |
| 63 | 63 | |
| 64 | - if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 64 | + if ($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 65 | 65 | $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
| 66 | 66 | $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
| 67 | 67 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * {@inheritDoc} |
| 72 | 72 | */ |
| 73 | 73 | public function afterController($controller, $methodName, Response $response) { |
| 74 | - if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 74 | + if ($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 75 | 75 | $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
| 76 | 76 | $ip = $this->request->getRemoteAddress(); |
| 77 | 77 | $this->throttler->sleepDelay($ip, $action); |
@@ -35,49 +35,49 @@ |
||
| 35 | 35 | * @package OC\AppFramework\Middleware\Security |
| 36 | 36 | */ |
| 37 | 37 | class BruteForceMiddleware extends Middleware { |
| 38 | - /** @var ControllerMethodReflector */ |
|
| 39 | - private $reflector; |
|
| 40 | - /** @var Throttler */ |
|
| 41 | - private $throttler; |
|
| 42 | - /** @var IRequest */ |
|
| 43 | - private $request; |
|
| 38 | + /** @var ControllerMethodReflector */ |
|
| 39 | + private $reflector; |
|
| 40 | + /** @var Throttler */ |
|
| 41 | + private $throttler; |
|
| 42 | + /** @var IRequest */ |
|
| 43 | + private $request; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param ControllerMethodReflector $controllerMethodReflector |
|
| 47 | - * @param Throttler $throttler |
|
| 48 | - * @param IRequest $request |
|
| 49 | - */ |
|
| 50 | - public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
| 51 | - Throttler $throttler, |
|
| 52 | - IRequest $request) { |
|
| 53 | - $this->reflector = $controllerMethodReflector; |
|
| 54 | - $this->throttler = $throttler; |
|
| 55 | - $this->request = $request; |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * @param ControllerMethodReflector $controllerMethodReflector |
|
| 47 | + * @param Throttler $throttler |
|
| 48 | + * @param IRequest $request |
|
| 49 | + */ |
|
| 50 | + public function __construct(ControllerMethodReflector $controllerMethodReflector, |
|
| 51 | + Throttler $throttler, |
|
| 52 | + IRequest $request) { |
|
| 53 | + $this->reflector = $controllerMethodReflector; |
|
| 54 | + $this->throttler = $throttler; |
|
| 55 | + $this->request = $request; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - */ |
|
| 61 | - public function beforeController($controller, $methodName) { |
|
| 62 | - parent::beforeController($controller, $methodName); |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + */ |
|
| 61 | + public function beforeController($controller, $methodName) { |
|
| 62 | + parent::beforeController($controller, $methodName); |
|
| 63 | 63 | |
| 64 | - if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 65 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 66 | - $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
| 67 | - } |
|
| 68 | - } |
|
| 64 | + if($this->reflector->hasAnnotation('BruteForceProtection')) { |
|
| 65 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 66 | + $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - */ |
|
| 73 | - public function afterController($controller, $methodName, Response $response) { |
|
| 74 | - if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 75 | - $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 76 | - $ip = $this->request->getRemoteAddress(); |
|
| 77 | - $this->throttler->sleepDelay($ip, $action); |
|
| 78 | - $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
| 79 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + */ |
|
| 73 | + public function afterController($controller, $methodName, Response $response) { |
|
| 74 | + if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { |
|
| 75 | + $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); |
|
| 76 | + $ip = $this->request->getRemoteAddress(); |
|
| 77 | + $this->throttler->sleepDelay($ip, $action); |
|
| 78 | + $this->throttler->registerAttempt($action, $ip, $response->getThrottleMetadata()); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return parent::afterController($controller, $methodName, $response); |
|
| 82 | - } |
|
| 81 | + return parent::afterController($controller, $methodName, $response); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -43,185 +43,185 @@ |
||
| 43 | 43 | * User storages controller |
| 44 | 44 | */ |
| 45 | 45 | class UserStoragesController extends StoragesController { |
| 46 | - /** |
|
| 47 | - * @var IUserSession |
|
| 48 | - */ |
|
| 49 | - private $userSession; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Creates a new user storages controller. |
|
| 53 | - * |
|
| 54 | - * @param string $AppName application name |
|
| 55 | - * @param IRequest $request request object |
|
| 56 | - * @param IL10N $l10n l10n service |
|
| 57 | - * @param UserStoragesService $userStoragesService storage service |
|
| 58 | - * @param IUserSession $userSession |
|
| 59 | - * @param ILogger $logger |
|
| 60 | - */ |
|
| 61 | - public function __construct( |
|
| 62 | - $AppName, |
|
| 63 | - IRequest $request, |
|
| 64 | - IL10N $l10n, |
|
| 65 | - UserStoragesService $userStoragesService, |
|
| 66 | - IUserSession $userSession, |
|
| 67 | - ILogger $logger |
|
| 68 | - ) { |
|
| 69 | - parent::__construct( |
|
| 70 | - $AppName, |
|
| 71 | - $request, |
|
| 72 | - $l10n, |
|
| 73 | - $userStoragesService, |
|
| 74 | - $logger |
|
| 75 | - ); |
|
| 76 | - $this->userSession = $userSession; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - protected function manipulateStorageConfig(StorageConfig $storage) { |
|
| 80 | - /** @var AuthMechanism */ |
|
| 81 | - $authMechanism = $storage->getAuthMechanism(); |
|
| 82 | - $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 83 | - /** @var Backend */ |
|
| 84 | - $backend = $storage->getBackend(); |
|
| 85 | - $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Get all storage entries |
|
| 90 | - * |
|
| 91 | - * @NoAdminRequired |
|
| 92 | - * |
|
| 93 | - * @return DataResponse |
|
| 94 | - */ |
|
| 95 | - public function index() { |
|
| 96 | - return parent::index(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Return storage |
|
| 101 | - * |
|
| 102 | - * @NoAdminRequired |
|
| 103 | - * |
|
| 104 | - * {@inheritdoc} |
|
| 105 | - */ |
|
| 106 | - public function show($id, $testOnly = true) { |
|
| 107 | - return parent::show($id, $testOnly); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Create an external storage entry. |
|
| 112 | - * |
|
| 113 | - * @param string $mountPoint storage mount point |
|
| 114 | - * @param string $backend backend identifier |
|
| 115 | - * @param string $authMechanism authentication mechanism identifier |
|
| 116 | - * @param array $backendOptions backend-specific options |
|
| 117 | - * @param array $mountOptions backend-specific mount options |
|
| 118 | - * |
|
| 119 | - * @return DataResponse |
|
| 120 | - * |
|
| 121 | - * @NoAdminRequired |
|
| 122 | - */ |
|
| 123 | - public function create( |
|
| 124 | - $mountPoint, |
|
| 125 | - $backend, |
|
| 126 | - $authMechanism, |
|
| 127 | - $backendOptions, |
|
| 128 | - $mountOptions |
|
| 129 | - ) { |
|
| 130 | - $newStorage = $this->createStorage( |
|
| 131 | - $mountPoint, |
|
| 132 | - $backend, |
|
| 133 | - $authMechanism, |
|
| 134 | - $backendOptions, |
|
| 135 | - $mountOptions |
|
| 136 | - ); |
|
| 137 | - if ($newStorage instanceOf DataResponse) { |
|
| 138 | - return $newStorage; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $response = $this->validate($newStorage); |
|
| 142 | - if (!empty($response)) { |
|
| 143 | - return $response; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $newStorage = $this->service->addStorage($newStorage); |
|
| 147 | - $this->updateStorageStatus($newStorage); |
|
| 148 | - |
|
| 149 | - return new DataResponse( |
|
| 150 | - $newStorage, |
|
| 151 | - Http::STATUS_CREATED |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Update an external storage entry. |
|
| 157 | - * |
|
| 158 | - * @param int $id storage id |
|
| 159 | - * @param string $mountPoint storage mount point |
|
| 160 | - * @param string $backend backend identifier |
|
| 161 | - * @param string $authMechanism authentication mechanism identifier |
|
| 162 | - * @param array $backendOptions backend-specific options |
|
| 163 | - * @param array $mountOptions backend-specific mount options |
|
| 164 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 165 | - * |
|
| 166 | - * @return DataResponse |
|
| 167 | - * |
|
| 168 | - * @NoAdminRequired |
|
| 169 | - */ |
|
| 170 | - public function update( |
|
| 171 | - $id, |
|
| 172 | - $mountPoint, |
|
| 173 | - $backend, |
|
| 174 | - $authMechanism, |
|
| 175 | - $backendOptions, |
|
| 176 | - $mountOptions, |
|
| 177 | - $testOnly = true |
|
| 178 | - ) { |
|
| 179 | - $storage = $this->createStorage( |
|
| 180 | - $mountPoint, |
|
| 181 | - $backend, |
|
| 182 | - $authMechanism, |
|
| 183 | - $backendOptions, |
|
| 184 | - $mountOptions |
|
| 185 | - ); |
|
| 186 | - if ($storage instanceOf DataResponse) { |
|
| 187 | - return $storage; |
|
| 188 | - } |
|
| 189 | - $storage->setId($id); |
|
| 190 | - |
|
| 191 | - $response = $this->validate($storage); |
|
| 192 | - if (!empty($response)) { |
|
| 193 | - return $response; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - try { |
|
| 197 | - $storage = $this->service->updateStorage($storage); |
|
| 198 | - } catch (NotFoundException $e) { |
|
| 199 | - return new DataResponse( |
|
| 200 | - [ |
|
| 201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 202 | - ], |
|
| 203 | - Http::STATUS_NOT_FOUND |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $this->updateStorageStatus($storage, $testOnly); |
|
| 208 | - |
|
| 209 | - return new DataResponse( |
|
| 210 | - $storage, |
|
| 211 | - Http::STATUS_OK |
|
| 212 | - ); |
|
| 213 | - |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Delete storage |
|
| 218 | - * |
|
| 219 | - * @NoAdminRequired |
|
| 220 | - * |
|
| 221 | - * {@inheritdoc} |
|
| 222 | - */ |
|
| 223 | - public function destroy($id) { |
|
| 224 | - return parent::destroy($id); |
|
| 225 | - } |
|
| 46 | + /** |
|
| 47 | + * @var IUserSession |
|
| 48 | + */ |
|
| 49 | + private $userSession; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Creates a new user storages controller. |
|
| 53 | + * |
|
| 54 | + * @param string $AppName application name |
|
| 55 | + * @param IRequest $request request object |
|
| 56 | + * @param IL10N $l10n l10n service |
|
| 57 | + * @param UserStoragesService $userStoragesService storage service |
|
| 58 | + * @param IUserSession $userSession |
|
| 59 | + * @param ILogger $logger |
|
| 60 | + */ |
|
| 61 | + public function __construct( |
|
| 62 | + $AppName, |
|
| 63 | + IRequest $request, |
|
| 64 | + IL10N $l10n, |
|
| 65 | + UserStoragesService $userStoragesService, |
|
| 66 | + IUserSession $userSession, |
|
| 67 | + ILogger $logger |
|
| 68 | + ) { |
|
| 69 | + parent::__construct( |
|
| 70 | + $AppName, |
|
| 71 | + $request, |
|
| 72 | + $l10n, |
|
| 73 | + $userStoragesService, |
|
| 74 | + $logger |
|
| 75 | + ); |
|
| 76 | + $this->userSession = $userSession; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + protected function manipulateStorageConfig(StorageConfig $storage) { |
|
| 80 | + /** @var AuthMechanism */ |
|
| 81 | + $authMechanism = $storage->getAuthMechanism(); |
|
| 82 | + $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 83 | + /** @var Backend */ |
|
| 84 | + $backend = $storage->getBackend(); |
|
| 85 | + $backend->manipulateStorageConfig($storage, $this->userSession->getUser()); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Get all storage entries |
|
| 90 | + * |
|
| 91 | + * @NoAdminRequired |
|
| 92 | + * |
|
| 93 | + * @return DataResponse |
|
| 94 | + */ |
|
| 95 | + public function index() { |
|
| 96 | + return parent::index(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Return storage |
|
| 101 | + * |
|
| 102 | + * @NoAdminRequired |
|
| 103 | + * |
|
| 104 | + * {@inheritdoc} |
|
| 105 | + */ |
|
| 106 | + public function show($id, $testOnly = true) { |
|
| 107 | + return parent::show($id, $testOnly); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Create an external storage entry. |
|
| 112 | + * |
|
| 113 | + * @param string $mountPoint storage mount point |
|
| 114 | + * @param string $backend backend identifier |
|
| 115 | + * @param string $authMechanism authentication mechanism identifier |
|
| 116 | + * @param array $backendOptions backend-specific options |
|
| 117 | + * @param array $mountOptions backend-specific mount options |
|
| 118 | + * |
|
| 119 | + * @return DataResponse |
|
| 120 | + * |
|
| 121 | + * @NoAdminRequired |
|
| 122 | + */ |
|
| 123 | + public function create( |
|
| 124 | + $mountPoint, |
|
| 125 | + $backend, |
|
| 126 | + $authMechanism, |
|
| 127 | + $backendOptions, |
|
| 128 | + $mountOptions |
|
| 129 | + ) { |
|
| 130 | + $newStorage = $this->createStorage( |
|
| 131 | + $mountPoint, |
|
| 132 | + $backend, |
|
| 133 | + $authMechanism, |
|
| 134 | + $backendOptions, |
|
| 135 | + $mountOptions |
|
| 136 | + ); |
|
| 137 | + if ($newStorage instanceOf DataResponse) { |
|
| 138 | + return $newStorage; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $response = $this->validate($newStorage); |
|
| 142 | + if (!empty($response)) { |
|
| 143 | + return $response; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $newStorage = $this->service->addStorage($newStorage); |
|
| 147 | + $this->updateStorageStatus($newStorage); |
|
| 148 | + |
|
| 149 | + return new DataResponse( |
|
| 150 | + $newStorage, |
|
| 151 | + Http::STATUS_CREATED |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Update an external storage entry. |
|
| 157 | + * |
|
| 158 | + * @param int $id storage id |
|
| 159 | + * @param string $mountPoint storage mount point |
|
| 160 | + * @param string $backend backend identifier |
|
| 161 | + * @param string $authMechanism authentication mechanism identifier |
|
| 162 | + * @param array $backendOptions backend-specific options |
|
| 163 | + * @param array $mountOptions backend-specific mount options |
|
| 164 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 165 | + * |
|
| 166 | + * @return DataResponse |
|
| 167 | + * |
|
| 168 | + * @NoAdminRequired |
|
| 169 | + */ |
|
| 170 | + public function update( |
|
| 171 | + $id, |
|
| 172 | + $mountPoint, |
|
| 173 | + $backend, |
|
| 174 | + $authMechanism, |
|
| 175 | + $backendOptions, |
|
| 176 | + $mountOptions, |
|
| 177 | + $testOnly = true |
|
| 178 | + ) { |
|
| 179 | + $storage = $this->createStorage( |
|
| 180 | + $mountPoint, |
|
| 181 | + $backend, |
|
| 182 | + $authMechanism, |
|
| 183 | + $backendOptions, |
|
| 184 | + $mountOptions |
|
| 185 | + ); |
|
| 186 | + if ($storage instanceOf DataResponse) { |
|
| 187 | + return $storage; |
|
| 188 | + } |
|
| 189 | + $storage->setId($id); |
|
| 190 | + |
|
| 191 | + $response = $this->validate($storage); |
|
| 192 | + if (!empty($response)) { |
|
| 193 | + return $response; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + try { |
|
| 197 | + $storage = $this->service->updateStorage($storage); |
|
| 198 | + } catch (NotFoundException $e) { |
|
| 199 | + return new DataResponse( |
|
| 200 | + [ |
|
| 201 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 202 | + ], |
|
| 203 | + Http::STATUS_NOT_FOUND |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $this->updateStorageStatus($storage, $testOnly); |
|
| 208 | + |
|
| 209 | + return new DataResponse( |
|
| 210 | + $storage, |
|
| 211 | + Http::STATUS_OK |
|
| 212 | + ); |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Delete storage |
|
| 218 | + * |
|
| 219 | + * @NoAdminRequired |
|
| 220 | + * |
|
| 221 | + * {@inheritdoc} |
|
| 222 | + */ |
|
| 223 | + public function destroy($id) { |
|
| 224 | + return parent::destroy($id); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | } |
@@ -198,7 +198,7 @@ |
||
| 198 | 198 | } catch (NotFoundException $e) { |
| 199 | 199 | return new DataResponse( |
| 200 | 200 | [ |
| 201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 201 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 202 | 202 | ], |
| 203 | 203 | Http::STATUS_NOT_FOUND |
| 204 | 204 | ); |
@@ -39,151 +39,151 @@ |
||
| 39 | 39 | * Global storages controller |
| 40 | 40 | */ |
| 41 | 41 | class GlobalStoragesController extends StoragesController { |
| 42 | - /** |
|
| 43 | - * Creates a new global storages controller. |
|
| 44 | - * |
|
| 45 | - * @param string $AppName application name |
|
| 46 | - * @param IRequest $request request object |
|
| 47 | - * @param IL10N $l10n l10n service |
|
| 48 | - * @param GlobalStoragesService $globalStoragesService storage service |
|
| 49 | - * @param ILogger $logger |
|
| 50 | - */ |
|
| 51 | - public function __construct( |
|
| 52 | - $AppName, |
|
| 53 | - IRequest $request, |
|
| 54 | - IL10N $l10n, |
|
| 55 | - GlobalStoragesService $globalStoragesService, |
|
| 56 | - ILogger $logger |
|
| 57 | - ) { |
|
| 58 | - parent::__construct( |
|
| 59 | - $AppName, |
|
| 60 | - $request, |
|
| 61 | - $l10n, |
|
| 62 | - $globalStoragesService, |
|
| 63 | - $logger |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Create an external storage entry. |
|
| 69 | - * |
|
| 70 | - * @param string $mountPoint storage mount point |
|
| 71 | - * @param string $backend backend identifier |
|
| 72 | - * @param string $authMechanism authentication mechanism identifier |
|
| 73 | - * @param array $backendOptions backend-specific options |
|
| 74 | - * @param array $mountOptions mount-specific options |
|
| 75 | - * @param array $applicableUsers users for which to mount the storage |
|
| 76 | - * @param array $applicableGroups groups for which to mount the storage |
|
| 77 | - * @param int $priority priority |
|
| 78 | - * |
|
| 79 | - * @return DataResponse |
|
| 80 | - */ |
|
| 81 | - public function create( |
|
| 82 | - $mountPoint, |
|
| 83 | - $backend, |
|
| 84 | - $authMechanism, |
|
| 85 | - $backendOptions, |
|
| 86 | - $mountOptions, |
|
| 87 | - $applicableUsers, |
|
| 88 | - $applicableGroups, |
|
| 89 | - $priority |
|
| 90 | - ) { |
|
| 91 | - $newStorage = $this->createStorage( |
|
| 92 | - $mountPoint, |
|
| 93 | - $backend, |
|
| 94 | - $authMechanism, |
|
| 95 | - $backendOptions, |
|
| 96 | - $mountOptions, |
|
| 97 | - $applicableUsers, |
|
| 98 | - $applicableGroups, |
|
| 99 | - $priority |
|
| 100 | - ); |
|
| 101 | - if ($newStorage instanceof DataResponse) { |
|
| 102 | - return $newStorage; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $response = $this->validate($newStorage); |
|
| 106 | - if (!empty($response)) { |
|
| 107 | - return $response; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $newStorage = $this->service->addStorage($newStorage); |
|
| 111 | - |
|
| 112 | - $this->updateStorageStatus($newStorage); |
|
| 113 | - |
|
| 114 | - return new DataResponse( |
|
| 115 | - $newStorage, |
|
| 116 | - Http::STATUS_CREATED |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Update an external storage entry. |
|
| 122 | - * |
|
| 123 | - * @param int $id storage id |
|
| 124 | - * @param string $mountPoint storage mount point |
|
| 125 | - * @param string $backend backend identifier |
|
| 126 | - * @param string $authMechanism authentication mechansim identifier |
|
| 127 | - * @param array $backendOptions backend-specific options |
|
| 128 | - * @param array $mountOptions mount-specific options |
|
| 129 | - * @param array $applicableUsers users for which to mount the storage |
|
| 130 | - * @param array $applicableGroups groups for which to mount the storage |
|
| 131 | - * @param int $priority priority |
|
| 132 | - * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 133 | - * |
|
| 134 | - * @return DataResponse |
|
| 135 | - */ |
|
| 136 | - public function update( |
|
| 137 | - $id, |
|
| 138 | - $mountPoint, |
|
| 139 | - $backend, |
|
| 140 | - $authMechanism, |
|
| 141 | - $backendOptions, |
|
| 142 | - $mountOptions, |
|
| 143 | - $applicableUsers, |
|
| 144 | - $applicableGroups, |
|
| 145 | - $priority, |
|
| 146 | - $testOnly = true |
|
| 147 | - ) { |
|
| 148 | - $storage = $this->createStorage( |
|
| 149 | - $mountPoint, |
|
| 150 | - $backend, |
|
| 151 | - $authMechanism, |
|
| 152 | - $backendOptions, |
|
| 153 | - $mountOptions, |
|
| 154 | - $applicableUsers, |
|
| 155 | - $applicableGroups, |
|
| 156 | - $priority |
|
| 157 | - ); |
|
| 158 | - if ($storage instanceof DataResponse) { |
|
| 159 | - return $storage; |
|
| 160 | - } |
|
| 161 | - $storage->setId($id); |
|
| 162 | - |
|
| 163 | - $response = $this->validate($storage); |
|
| 164 | - if (!empty($response)) { |
|
| 165 | - return $response; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - try { |
|
| 169 | - $storage = $this->service->updateStorage($storage); |
|
| 170 | - } catch (NotFoundException $e) { |
|
| 171 | - return new DataResponse( |
|
| 172 | - [ |
|
| 173 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 174 | - ], |
|
| 175 | - Http::STATUS_NOT_FOUND |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $this->updateStorageStatus($storage, $testOnly); |
|
| 180 | - |
|
| 181 | - return new DataResponse( |
|
| 182 | - $storage, |
|
| 183 | - Http::STATUS_OK |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - } |
|
| 42 | + /** |
|
| 43 | + * Creates a new global storages controller. |
|
| 44 | + * |
|
| 45 | + * @param string $AppName application name |
|
| 46 | + * @param IRequest $request request object |
|
| 47 | + * @param IL10N $l10n l10n service |
|
| 48 | + * @param GlobalStoragesService $globalStoragesService storage service |
|
| 49 | + * @param ILogger $logger |
|
| 50 | + */ |
|
| 51 | + public function __construct( |
|
| 52 | + $AppName, |
|
| 53 | + IRequest $request, |
|
| 54 | + IL10N $l10n, |
|
| 55 | + GlobalStoragesService $globalStoragesService, |
|
| 56 | + ILogger $logger |
|
| 57 | + ) { |
|
| 58 | + parent::__construct( |
|
| 59 | + $AppName, |
|
| 60 | + $request, |
|
| 61 | + $l10n, |
|
| 62 | + $globalStoragesService, |
|
| 63 | + $logger |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Create an external storage entry. |
|
| 69 | + * |
|
| 70 | + * @param string $mountPoint storage mount point |
|
| 71 | + * @param string $backend backend identifier |
|
| 72 | + * @param string $authMechanism authentication mechanism identifier |
|
| 73 | + * @param array $backendOptions backend-specific options |
|
| 74 | + * @param array $mountOptions mount-specific options |
|
| 75 | + * @param array $applicableUsers users for which to mount the storage |
|
| 76 | + * @param array $applicableGroups groups for which to mount the storage |
|
| 77 | + * @param int $priority priority |
|
| 78 | + * |
|
| 79 | + * @return DataResponse |
|
| 80 | + */ |
|
| 81 | + public function create( |
|
| 82 | + $mountPoint, |
|
| 83 | + $backend, |
|
| 84 | + $authMechanism, |
|
| 85 | + $backendOptions, |
|
| 86 | + $mountOptions, |
|
| 87 | + $applicableUsers, |
|
| 88 | + $applicableGroups, |
|
| 89 | + $priority |
|
| 90 | + ) { |
|
| 91 | + $newStorage = $this->createStorage( |
|
| 92 | + $mountPoint, |
|
| 93 | + $backend, |
|
| 94 | + $authMechanism, |
|
| 95 | + $backendOptions, |
|
| 96 | + $mountOptions, |
|
| 97 | + $applicableUsers, |
|
| 98 | + $applicableGroups, |
|
| 99 | + $priority |
|
| 100 | + ); |
|
| 101 | + if ($newStorage instanceof DataResponse) { |
|
| 102 | + return $newStorage; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $response = $this->validate($newStorage); |
|
| 106 | + if (!empty($response)) { |
|
| 107 | + return $response; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $newStorage = $this->service->addStorage($newStorage); |
|
| 111 | + |
|
| 112 | + $this->updateStorageStatus($newStorage); |
|
| 113 | + |
|
| 114 | + return new DataResponse( |
|
| 115 | + $newStorage, |
|
| 116 | + Http::STATUS_CREATED |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Update an external storage entry. |
|
| 122 | + * |
|
| 123 | + * @param int $id storage id |
|
| 124 | + * @param string $mountPoint storage mount point |
|
| 125 | + * @param string $backend backend identifier |
|
| 126 | + * @param string $authMechanism authentication mechansim identifier |
|
| 127 | + * @param array $backendOptions backend-specific options |
|
| 128 | + * @param array $mountOptions mount-specific options |
|
| 129 | + * @param array $applicableUsers users for which to mount the storage |
|
| 130 | + * @param array $applicableGroups groups for which to mount the storage |
|
| 131 | + * @param int $priority priority |
|
| 132 | + * @param bool $testOnly whether to storage should only test the connection or do more things |
|
| 133 | + * |
|
| 134 | + * @return DataResponse |
|
| 135 | + */ |
|
| 136 | + public function update( |
|
| 137 | + $id, |
|
| 138 | + $mountPoint, |
|
| 139 | + $backend, |
|
| 140 | + $authMechanism, |
|
| 141 | + $backendOptions, |
|
| 142 | + $mountOptions, |
|
| 143 | + $applicableUsers, |
|
| 144 | + $applicableGroups, |
|
| 145 | + $priority, |
|
| 146 | + $testOnly = true |
|
| 147 | + ) { |
|
| 148 | + $storage = $this->createStorage( |
|
| 149 | + $mountPoint, |
|
| 150 | + $backend, |
|
| 151 | + $authMechanism, |
|
| 152 | + $backendOptions, |
|
| 153 | + $mountOptions, |
|
| 154 | + $applicableUsers, |
|
| 155 | + $applicableGroups, |
|
| 156 | + $priority |
|
| 157 | + ); |
|
| 158 | + if ($storage instanceof DataResponse) { |
|
| 159 | + return $storage; |
|
| 160 | + } |
|
| 161 | + $storage->setId($id); |
|
| 162 | + |
|
| 163 | + $response = $this->validate($storage); |
|
| 164 | + if (!empty($response)) { |
|
| 165 | + return $response; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + try { |
|
| 169 | + $storage = $this->service->updateStorage($storage); |
|
| 170 | + } catch (NotFoundException $e) { |
|
| 171 | + return new DataResponse( |
|
| 172 | + [ |
|
| 173 | + 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 174 | + ], |
|
| 175 | + Http::STATUS_NOT_FOUND |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $this->updateStorageStatus($storage, $testOnly); |
|
| 180 | + |
|
| 181 | + return new DataResponse( |
|
| 182 | + $storage, |
|
| 183 | + Http::STATUS_OK |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | } |
@@ -198,7 +198,7 @@ |
||
| 198 | 198 | } catch (NotFoundException $e) { |
| 199 | 199 | return new DataResponse( |
| 200 | 200 | [ |
| 201 | - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 201 | + 'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id)) |
|
| 202 | 202 | ], |
| 203 | 203 | Http::STATUS_NOT_FOUND |
| 204 | 204 | ); |