@@ -32,448 +32,448 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Share implements \OCP\Share\IShare { |
| 34 | 34 | |
| 35 | - /** @var string */ |
|
| 36 | - private $id; |
|
| 37 | - /** @var string */ |
|
| 38 | - private $providerId; |
|
| 39 | - /** @var Node */ |
|
| 40 | - private $node; |
|
| 41 | - /** @var int */ |
|
| 42 | - private $fileId; |
|
| 43 | - /** @var string */ |
|
| 44 | - private $nodeType; |
|
| 45 | - /** @var int */ |
|
| 46 | - private $shareType; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $sharedWith; |
|
| 49 | - /** @var string */ |
|
| 50 | - private $sharedWithDisplayName; |
|
| 51 | - /** @var string */ |
|
| 52 | - private $sharedWithAvatar; |
|
| 53 | - /** @var string */ |
|
| 54 | - private $sharedBy; |
|
| 55 | - /** @var string */ |
|
| 56 | - private $shareOwner; |
|
| 57 | - /** @var int */ |
|
| 58 | - private $permissions; |
|
| 59 | - /** @var \DateTime */ |
|
| 60 | - private $expireDate; |
|
| 61 | - /** @var string */ |
|
| 62 | - private $password; |
|
| 63 | - /** @var string */ |
|
| 64 | - private $token; |
|
| 65 | - /** @var int */ |
|
| 66 | - private $parent; |
|
| 67 | - /** @var string */ |
|
| 68 | - private $target; |
|
| 69 | - /** @var \DateTime */ |
|
| 70 | - private $shareTime; |
|
| 71 | - /** @var bool */ |
|
| 72 | - private $mailSend; |
|
| 73 | - |
|
| 74 | - /** @var IRootFolder */ |
|
| 75 | - private $rootFolder; |
|
| 76 | - |
|
| 77 | - /** @var IUserManager */ |
|
| 78 | - private $userManager; |
|
| 79 | - |
|
| 80 | - /** @var ICacheEntry|null */ |
|
| 81 | - private $nodeCacheEntry; |
|
| 82 | - |
|
| 83 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 84 | - $this->rootFolder = $rootFolder; |
|
| 85 | - $this->userManager = $userManager; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @inheritdoc |
|
| 90 | - */ |
|
| 91 | - public function setId($id) { |
|
| 92 | - if (is_int($id)) { |
|
| 93 | - $id = (string)$id; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if(!is_string($id)) { |
|
| 97 | - throw new \InvalidArgumentException('String expected.'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if ($this->id !== null) { |
|
| 101 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->id = trim($id); |
|
| 105 | - return $this; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @inheritdoc |
|
| 110 | - */ |
|
| 111 | - public function getId() { |
|
| 112 | - return $this->id; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @inheritdoc |
|
| 117 | - */ |
|
| 118 | - public function getFullId() { |
|
| 119 | - if ($this->providerId === null || $this->id === null) { |
|
| 120 | - throw new \UnexpectedValueException; |
|
| 121 | - } |
|
| 122 | - return $this->providerId . ':' . $this->id; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @inheritdoc |
|
| 127 | - */ |
|
| 128 | - public function setProviderId($id) { |
|
| 129 | - if(!is_string($id)) { |
|
| 130 | - throw new \InvalidArgumentException('String expected.'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($this->providerId !== null) { |
|
| 134 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->providerId = trim($id); |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @inheritdoc |
|
| 143 | - */ |
|
| 144 | - public function setNode(Node $node) { |
|
| 145 | - $this->fileId = null; |
|
| 146 | - $this->nodeType = null; |
|
| 147 | - $this->node = $node; |
|
| 148 | - return $this; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @inheritdoc |
|
| 153 | - */ |
|
| 154 | - public function getNode() { |
|
| 155 | - if ($this->node === null) { |
|
| 156 | - |
|
| 157 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
| 158 | - throw new NotFoundException(); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // for federated shares the owner can be a remote user, in this |
|
| 162 | - // case we use the initiator |
|
| 163 | - if($this->userManager->userExists($this->shareOwner)) { |
|
| 164 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 165 | - } else { |
|
| 166 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $nodes = $userFolder->getById($this->fileId); |
|
| 170 | - if (empty($nodes)) { |
|
| 171 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $this->node = $nodes[0]; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $this->node; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @inheritdoc |
|
| 182 | - */ |
|
| 183 | - public function setNodeId($fileId) { |
|
| 184 | - $this->node = null; |
|
| 185 | - $this->fileId = $fileId; |
|
| 186 | - return $this; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @inheritdoc |
|
| 191 | - */ |
|
| 192 | - public function getNodeId() { |
|
| 193 | - if ($this->fileId === null) { |
|
| 194 | - $this->fileId = $this->getNode()->getId(); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $this->fileId; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @inheritdoc |
|
| 202 | - */ |
|
| 203 | - public function setNodeType($type) { |
|
| 204 | - if ($type !== 'file' && $type !== 'folder') { |
|
| 205 | - throw new \InvalidArgumentException(); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $this->nodeType = $type; |
|
| 209 | - return $this; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @inheritdoc |
|
| 214 | - */ |
|
| 215 | - public function getNodeType() { |
|
| 216 | - if ($this->nodeType === null) { |
|
| 217 | - $node = $this->getNode(); |
|
| 218 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - return $this->nodeType; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @inheritdoc |
|
| 226 | - */ |
|
| 227 | - public function setShareType($shareType) { |
|
| 228 | - $this->shareType = $shareType; |
|
| 229 | - return $this; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @inheritdoc |
|
| 234 | - */ |
|
| 235 | - public function getShareType() { |
|
| 236 | - return $this->shareType; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @inheritdoc |
|
| 241 | - */ |
|
| 242 | - public function setSharedWith($sharedWith) { |
|
| 243 | - if (!is_string($sharedWith)) { |
|
| 244 | - throw new \InvalidArgumentException(); |
|
| 245 | - } |
|
| 246 | - $this->sharedWith = $sharedWith; |
|
| 247 | - return $this; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @inheritdoc |
|
| 252 | - */ |
|
| 253 | - public function getSharedWith() { |
|
| 254 | - return $this->sharedWith; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @inheritdoc |
|
| 259 | - */ |
|
| 260 | - public function setSharedWithDisplayName($displayName) { |
|
| 261 | - if (!is_string($displayName)) { |
|
| 262 | - throw new \InvalidArgumentException(); |
|
| 263 | - } |
|
| 264 | - $this->sharedWithDisplayName = $displayName; |
|
| 265 | - return $this; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @inheritdoc |
|
| 270 | - */ |
|
| 271 | - public function getSharedWithDisplayName() { |
|
| 272 | - return $this->sharedWithDisplayName; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @inheritdoc |
|
| 277 | - */ |
|
| 278 | - public function setSharedWithAvatar($src) { |
|
| 279 | - if (!is_string($src)) { |
|
| 280 | - throw new \InvalidArgumentException(); |
|
| 281 | - } |
|
| 282 | - $this->sharedWithAvatar = $src; |
|
| 283 | - return $this; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @inheritdoc |
|
| 288 | - */ |
|
| 289 | - public function getSharedWithAvatar() { |
|
| 290 | - return $this->sharedWithAvatar; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @inheritdoc |
|
| 295 | - */ |
|
| 296 | - public function setPermissions($permissions) { |
|
| 297 | - //TODO checkes |
|
| 298 | - |
|
| 299 | - $this->permissions = $permissions; |
|
| 300 | - return $this; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * @inheritdoc |
|
| 305 | - */ |
|
| 306 | - public function getPermissions() { |
|
| 307 | - return $this->permissions; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @inheritdoc |
|
| 312 | - */ |
|
| 313 | - public function setExpirationDate($expireDate) { |
|
| 314 | - //TODO checks |
|
| 315 | - |
|
| 316 | - $this->expireDate = $expireDate; |
|
| 317 | - return $this; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @inheritdoc |
|
| 322 | - */ |
|
| 323 | - public function getExpirationDate() { |
|
| 324 | - return $this->expireDate; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @inheritdoc |
|
| 329 | - */ |
|
| 330 | - public function setSharedBy($sharedBy) { |
|
| 331 | - if (!is_string($sharedBy)) { |
|
| 332 | - throw new \InvalidArgumentException(); |
|
| 333 | - } |
|
| 334 | - //TODO checks |
|
| 335 | - $this->sharedBy = $sharedBy; |
|
| 336 | - |
|
| 337 | - return $this; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @inheritdoc |
|
| 342 | - */ |
|
| 343 | - public function getSharedBy() { |
|
| 344 | - //TODO check if set |
|
| 345 | - return $this->sharedBy; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * @inheritdoc |
|
| 350 | - */ |
|
| 351 | - public function setShareOwner($shareOwner) { |
|
| 352 | - if (!is_string($shareOwner)) { |
|
| 353 | - throw new \InvalidArgumentException(); |
|
| 354 | - } |
|
| 355 | - //TODO checks |
|
| 356 | - |
|
| 357 | - $this->shareOwner = $shareOwner; |
|
| 358 | - return $this; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @inheritdoc |
|
| 363 | - */ |
|
| 364 | - public function getShareOwner() { |
|
| 365 | - //TODO check if set |
|
| 366 | - return $this->shareOwner; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @inheritdoc |
|
| 371 | - */ |
|
| 372 | - public function setPassword($password) { |
|
| 373 | - $this->password = $password; |
|
| 374 | - return $this; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @inheritdoc |
|
| 379 | - */ |
|
| 380 | - public function getPassword() { |
|
| 381 | - return $this->password; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @inheritdoc |
|
| 386 | - */ |
|
| 387 | - public function setToken($token) { |
|
| 388 | - $this->token = $token; |
|
| 389 | - return $this; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * @inheritdoc |
|
| 394 | - */ |
|
| 395 | - public function getToken() { |
|
| 396 | - return $this->token; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Set the parent of this share |
|
| 401 | - * |
|
| 402 | - * @param int parent |
|
| 403 | - * @return \OCP\Share\IShare |
|
| 404 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 405 | - */ |
|
| 406 | - public function setParent($parent) { |
|
| 407 | - $this->parent = $parent; |
|
| 408 | - return $this; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Get the parent of this share. |
|
| 413 | - * |
|
| 414 | - * @return int |
|
| 415 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 416 | - */ |
|
| 417 | - public function getParent() { |
|
| 418 | - return $this->parent; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * @inheritdoc |
|
| 423 | - */ |
|
| 424 | - public function setTarget($target) { |
|
| 425 | - $this->target = $target; |
|
| 426 | - return $this; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @inheritdoc |
|
| 431 | - */ |
|
| 432 | - public function getTarget() { |
|
| 433 | - return $this->target; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @inheritdoc |
|
| 438 | - */ |
|
| 439 | - public function setShareTime(\DateTime $shareTime) { |
|
| 440 | - $this->shareTime = $shareTime; |
|
| 441 | - return $this; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * @inheritdoc |
|
| 446 | - */ |
|
| 447 | - public function getShareTime() { |
|
| 448 | - return $this->shareTime; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @inheritdoc |
|
| 453 | - */ |
|
| 454 | - public function setMailSend($mailSend) { |
|
| 455 | - $this->mailSend = $mailSend; |
|
| 456 | - return $this; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @inheritdoc |
|
| 461 | - */ |
|
| 462 | - public function getMailSend() { |
|
| 463 | - return $this->mailSend; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @inheritdoc |
|
| 468 | - */ |
|
| 469 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 470 | - $this->nodeCacheEntry = $entry; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @inheritdoc |
|
| 475 | - */ |
|
| 476 | - public function getNodeCacheEntry() { |
|
| 477 | - return $this->nodeCacheEntry; |
|
| 478 | - } |
|
| 35 | + /** @var string */ |
|
| 36 | + private $id; |
|
| 37 | + /** @var string */ |
|
| 38 | + private $providerId; |
|
| 39 | + /** @var Node */ |
|
| 40 | + private $node; |
|
| 41 | + /** @var int */ |
|
| 42 | + private $fileId; |
|
| 43 | + /** @var string */ |
|
| 44 | + private $nodeType; |
|
| 45 | + /** @var int */ |
|
| 46 | + private $shareType; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $sharedWith; |
|
| 49 | + /** @var string */ |
|
| 50 | + private $sharedWithDisplayName; |
|
| 51 | + /** @var string */ |
|
| 52 | + private $sharedWithAvatar; |
|
| 53 | + /** @var string */ |
|
| 54 | + private $sharedBy; |
|
| 55 | + /** @var string */ |
|
| 56 | + private $shareOwner; |
|
| 57 | + /** @var int */ |
|
| 58 | + private $permissions; |
|
| 59 | + /** @var \DateTime */ |
|
| 60 | + private $expireDate; |
|
| 61 | + /** @var string */ |
|
| 62 | + private $password; |
|
| 63 | + /** @var string */ |
|
| 64 | + private $token; |
|
| 65 | + /** @var int */ |
|
| 66 | + private $parent; |
|
| 67 | + /** @var string */ |
|
| 68 | + private $target; |
|
| 69 | + /** @var \DateTime */ |
|
| 70 | + private $shareTime; |
|
| 71 | + /** @var bool */ |
|
| 72 | + private $mailSend; |
|
| 73 | + |
|
| 74 | + /** @var IRootFolder */ |
|
| 75 | + private $rootFolder; |
|
| 76 | + |
|
| 77 | + /** @var IUserManager */ |
|
| 78 | + private $userManager; |
|
| 79 | + |
|
| 80 | + /** @var ICacheEntry|null */ |
|
| 81 | + private $nodeCacheEntry; |
|
| 82 | + |
|
| 83 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 84 | + $this->rootFolder = $rootFolder; |
|
| 85 | + $this->userManager = $userManager; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @inheritdoc |
|
| 90 | + */ |
|
| 91 | + public function setId($id) { |
|
| 92 | + if (is_int($id)) { |
|
| 93 | + $id = (string)$id; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if(!is_string($id)) { |
|
| 97 | + throw new \InvalidArgumentException('String expected.'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if ($this->id !== null) { |
|
| 101 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->id = trim($id); |
|
| 105 | + return $this; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @inheritdoc |
|
| 110 | + */ |
|
| 111 | + public function getId() { |
|
| 112 | + return $this->id; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @inheritdoc |
|
| 117 | + */ |
|
| 118 | + public function getFullId() { |
|
| 119 | + if ($this->providerId === null || $this->id === null) { |
|
| 120 | + throw new \UnexpectedValueException; |
|
| 121 | + } |
|
| 122 | + return $this->providerId . ':' . $this->id; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @inheritdoc |
|
| 127 | + */ |
|
| 128 | + public function setProviderId($id) { |
|
| 129 | + if(!is_string($id)) { |
|
| 130 | + throw new \InvalidArgumentException('String expected.'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($this->providerId !== null) { |
|
| 134 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->providerId = trim($id); |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @inheritdoc |
|
| 143 | + */ |
|
| 144 | + public function setNode(Node $node) { |
|
| 145 | + $this->fileId = null; |
|
| 146 | + $this->nodeType = null; |
|
| 147 | + $this->node = $node; |
|
| 148 | + return $this; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @inheritdoc |
|
| 153 | + */ |
|
| 154 | + public function getNode() { |
|
| 155 | + if ($this->node === null) { |
|
| 156 | + |
|
| 157 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
| 158 | + throw new NotFoundException(); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // for federated shares the owner can be a remote user, in this |
|
| 162 | + // case we use the initiator |
|
| 163 | + if($this->userManager->userExists($this->shareOwner)) { |
|
| 164 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 165 | + } else { |
|
| 166 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $nodes = $userFolder->getById($this->fileId); |
|
| 170 | + if (empty($nodes)) { |
|
| 171 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $this->node = $nodes[0]; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $this->node; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @inheritdoc |
|
| 182 | + */ |
|
| 183 | + public function setNodeId($fileId) { |
|
| 184 | + $this->node = null; |
|
| 185 | + $this->fileId = $fileId; |
|
| 186 | + return $this; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @inheritdoc |
|
| 191 | + */ |
|
| 192 | + public function getNodeId() { |
|
| 193 | + if ($this->fileId === null) { |
|
| 194 | + $this->fileId = $this->getNode()->getId(); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $this->fileId; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @inheritdoc |
|
| 202 | + */ |
|
| 203 | + public function setNodeType($type) { |
|
| 204 | + if ($type !== 'file' && $type !== 'folder') { |
|
| 205 | + throw new \InvalidArgumentException(); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $this->nodeType = $type; |
|
| 209 | + return $this; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @inheritdoc |
|
| 214 | + */ |
|
| 215 | + public function getNodeType() { |
|
| 216 | + if ($this->nodeType === null) { |
|
| 217 | + $node = $this->getNode(); |
|
| 218 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + return $this->nodeType; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @inheritdoc |
|
| 226 | + */ |
|
| 227 | + public function setShareType($shareType) { |
|
| 228 | + $this->shareType = $shareType; |
|
| 229 | + return $this; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @inheritdoc |
|
| 234 | + */ |
|
| 235 | + public function getShareType() { |
|
| 236 | + return $this->shareType; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @inheritdoc |
|
| 241 | + */ |
|
| 242 | + public function setSharedWith($sharedWith) { |
|
| 243 | + if (!is_string($sharedWith)) { |
|
| 244 | + throw new \InvalidArgumentException(); |
|
| 245 | + } |
|
| 246 | + $this->sharedWith = $sharedWith; |
|
| 247 | + return $this; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @inheritdoc |
|
| 252 | + */ |
|
| 253 | + public function getSharedWith() { |
|
| 254 | + return $this->sharedWith; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @inheritdoc |
|
| 259 | + */ |
|
| 260 | + public function setSharedWithDisplayName($displayName) { |
|
| 261 | + if (!is_string($displayName)) { |
|
| 262 | + throw new \InvalidArgumentException(); |
|
| 263 | + } |
|
| 264 | + $this->sharedWithDisplayName = $displayName; |
|
| 265 | + return $this; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @inheritdoc |
|
| 270 | + */ |
|
| 271 | + public function getSharedWithDisplayName() { |
|
| 272 | + return $this->sharedWithDisplayName; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @inheritdoc |
|
| 277 | + */ |
|
| 278 | + public function setSharedWithAvatar($src) { |
|
| 279 | + if (!is_string($src)) { |
|
| 280 | + throw new \InvalidArgumentException(); |
|
| 281 | + } |
|
| 282 | + $this->sharedWithAvatar = $src; |
|
| 283 | + return $this; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @inheritdoc |
|
| 288 | + */ |
|
| 289 | + public function getSharedWithAvatar() { |
|
| 290 | + return $this->sharedWithAvatar; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @inheritdoc |
|
| 295 | + */ |
|
| 296 | + public function setPermissions($permissions) { |
|
| 297 | + //TODO checkes |
|
| 298 | + |
|
| 299 | + $this->permissions = $permissions; |
|
| 300 | + return $this; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * @inheritdoc |
|
| 305 | + */ |
|
| 306 | + public function getPermissions() { |
|
| 307 | + return $this->permissions; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @inheritdoc |
|
| 312 | + */ |
|
| 313 | + public function setExpirationDate($expireDate) { |
|
| 314 | + //TODO checks |
|
| 315 | + |
|
| 316 | + $this->expireDate = $expireDate; |
|
| 317 | + return $this; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @inheritdoc |
|
| 322 | + */ |
|
| 323 | + public function getExpirationDate() { |
|
| 324 | + return $this->expireDate; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @inheritdoc |
|
| 329 | + */ |
|
| 330 | + public function setSharedBy($sharedBy) { |
|
| 331 | + if (!is_string($sharedBy)) { |
|
| 332 | + throw new \InvalidArgumentException(); |
|
| 333 | + } |
|
| 334 | + //TODO checks |
|
| 335 | + $this->sharedBy = $sharedBy; |
|
| 336 | + |
|
| 337 | + return $this; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @inheritdoc |
|
| 342 | + */ |
|
| 343 | + public function getSharedBy() { |
|
| 344 | + //TODO check if set |
|
| 345 | + return $this->sharedBy; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * @inheritdoc |
|
| 350 | + */ |
|
| 351 | + public function setShareOwner($shareOwner) { |
|
| 352 | + if (!is_string($shareOwner)) { |
|
| 353 | + throw new \InvalidArgumentException(); |
|
| 354 | + } |
|
| 355 | + //TODO checks |
|
| 356 | + |
|
| 357 | + $this->shareOwner = $shareOwner; |
|
| 358 | + return $this; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @inheritdoc |
|
| 363 | + */ |
|
| 364 | + public function getShareOwner() { |
|
| 365 | + //TODO check if set |
|
| 366 | + return $this->shareOwner; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @inheritdoc |
|
| 371 | + */ |
|
| 372 | + public function setPassword($password) { |
|
| 373 | + $this->password = $password; |
|
| 374 | + return $this; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @inheritdoc |
|
| 379 | + */ |
|
| 380 | + public function getPassword() { |
|
| 381 | + return $this->password; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @inheritdoc |
|
| 386 | + */ |
|
| 387 | + public function setToken($token) { |
|
| 388 | + $this->token = $token; |
|
| 389 | + return $this; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * @inheritdoc |
|
| 394 | + */ |
|
| 395 | + public function getToken() { |
|
| 396 | + return $this->token; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Set the parent of this share |
|
| 401 | + * |
|
| 402 | + * @param int parent |
|
| 403 | + * @return \OCP\Share\IShare |
|
| 404 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 405 | + */ |
|
| 406 | + public function setParent($parent) { |
|
| 407 | + $this->parent = $parent; |
|
| 408 | + return $this; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Get the parent of this share. |
|
| 413 | + * |
|
| 414 | + * @return int |
|
| 415 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 416 | + */ |
|
| 417 | + public function getParent() { |
|
| 418 | + return $this->parent; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @inheritdoc |
|
| 423 | + */ |
|
| 424 | + public function setTarget($target) { |
|
| 425 | + $this->target = $target; |
|
| 426 | + return $this; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @inheritdoc |
|
| 431 | + */ |
|
| 432 | + public function getTarget() { |
|
| 433 | + return $this->target; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @inheritdoc |
|
| 438 | + */ |
|
| 439 | + public function setShareTime(\DateTime $shareTime) { |
|
| 440 | + $this->shareTime = $shareTime; |
|
| 441 | + return $this; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * @inheritdoc |
|
| 446 | + */ |
|
| 447 | + public function getShareTime() { |
|
| 448 | + return $this->shareTime; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @inheritdoc |
|
| 453 | + */ |
|
| 454 | + public function setMailSend($mailSend) { |
|
| 455 | + $this->mailSend = $mailSend; |
|
| 456 | + return $this; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @inheritdoc |
|
| 461 | + */ |
|
| 462 | + public function getMailSend() { |
|
| 463 | + return $this->mailSend; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @inheritdoc |
|
| 468 | + */ |
|
| 469 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 470 | + $this->nodeCacheEntry = $entry; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @inheritdoc |
|
| 475 | + */ |
|
| 476 | + public function getNodeCacheEntry() { |
|
| 477 | + return $this->nodeCacheEntry; |
|
| 478 | + } |
|
| 479 | 479 | } |
@@ -37,342 +37,342 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | interface IShare { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the internal id of the share |
|
| 42 | - * It is only allowed to set the internal id of a share once. |
|
| 43 | - * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 44 | - * |
|
| 45 | - * @param string $id |
|
| 46 | - * @return \OCP\Share\IShare |
|
| 47 | - * @throws IllegalIDChangeException |
|
| 48 | - * @throws \InvalidArgumentException |
|
| 49 | - * @since 9.1.0 |
|
| 50 | - */ |
|
| 51 | - public function setId($id); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get the internal id of the share. |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - * @since 9.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getId(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get the full share id. This is the <providerid>:<internalid>. |
|
| 63 | - * The full id is unique in the system. |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - * @since 9.0.0 |
|
| 67 | - * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 68 | - */ |
|
| 69 | - public function getFullId(); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Set the provider id of the share |
|
| 73 | - * It is only allowed to set the provider id of a share once. |
|
| 74 | - * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 75 | - * |
|
| 76 | - * @param string $id |
|
| 77 | - * @return \OCP\Share\IShare |
|
| 78 | - * @throws IllegalIDChangeException |
|
| 79 | - * @throws \InvalidArgumentException |
|
| 80 | - * @since 9.1.0 |
|
| 81 | - */ |
|
| 82 | - public function setProviderId($id); |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Set the node of the file/folder that is shared |
|
| 86 | - * |
|
| 87 | - * @param Node $node |
|
| 88 | - * @return \OCP\Share\IShare The modified object |
|
| 89 | - * @since 9.0.0 |
|
| 90 | - */ |
|
| 91 | - public function setNode(Node $node); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Get the node of the file/folder that is shared |
|
| 95 | - * |
|
| 96 | - * @return File|Folder |
|
| 97 | - * @since 9.0.0 |
|
| 98 | - * @throws NotFoundException |
|
| 99 | - */ |
|
| 100 | - public function getNode(); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Set file id for lazy evaluation of the node |
|
| 104 | - * @param int $fileId |
|
| 105 | - * @return \OCP\Share\IShare The modified object |
|
| 106 | - * @since 9.0.0 |
|
| 107 | - */ |
|
| 108 | - public function setNodeId($fileId); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get the fileid of the node of this share |
|
| 112 | - * @return int |
|
| 113 | - * @since 9.0.0 |
|
| 114 | - * @throws NotFoundException |
|
| 115 | - */ |
|
| 116 | - public function getNodeId(); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Set the type of node (file/folder) |
|
| 120 | - * |
|
| 121 | - * @param string $type |
|
| 122 | - * @return \OCP\Share\IShare The modified object |
|
| 123 | - * @since 9.0.0 |
|
| 124 | - */ |
|
| 125 | - public function setNodeType($type); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get the type of node (file/folder) |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - * @since 9.0.0 |
|
| 132 | - * @throws NotFoundException |
|
| 133 | - */ |
|
| 134 | - public function getNodeType(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Set the shareType |
|
| 138 | - * |
|
| 139 | - * @param int $shareType |
|
| 140 | - * @return \OCP\Share\IShare The modified object |
|
| 141 | - * @since 9.0.0 |
|
| 142 | - */ |
|
| 143 | - public function setShareType($shareType); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Get the shareType |
|
| 147 | - * |
|
| 148 | - * @return int |
|
| 149 | - * @since 9.0.0 |
|
| 150 | - */ |
|
| 151 | - public function getShareType(); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Set the receiver of this share. |
|
| 155 | - * |
|
| 156 | - * @param string $sharedWith |
|
| 157 | - * @return \OCP\Share\IShare The modified object |
|
| 158 | - * @since 9.0.0 |
|
| 159 | - */ |
|
| 160 | - public function setSharedWith($sharedWith); |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the receiver of this share. |
|
| 164 | - * |
|
| 165 | - * @return string |
|
| 166 | - * @since 9.0.0 |
|
| 167 | - */ |
|
| 168 | - public function getSharedWith(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Set the display name of the receiver of this share. |
|
| 172 | - * |
|
| 173 | - * @param string $displayName |
|
| 174 | - * @return \OCP\Share\IShare The modified object |
|
| 175 | - * @since 9.0.0 |
|
| 176 | - */ |
|
| 177 | - public function setSharedWithDisplayName($displayName); |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the display name of the receiver of this share. |
|
| 181 | - * |
|
| 182 | - * @return string |
|
| 183 | - * @since 9.0.0 |
|
| 184 | - */ |
|
| 185 | - public function getSharedWithDisplayName(); |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Set the avatar of the receiver of this share. |
|
| 189 | - * |
|
| 190 | - * @param string $src |
|
| 191 | - * @return \OCP\Share\IShare The modified object |
|
| 192 | - * @since 9.0.0 |
|
| 193 | - */ |
|
| 194 | - public function setSharedWithAvatar($src); |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Get the display name of the receiver of this share. |
|
| 198 | - * |
|
| 199 | - * @return string |
|
| 200 | - * @since 9.0.0 |
|
| 201 | - */ |
|
| 202 | - public function getSharedWithAvatar(); |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Set the permissions. |
|
| 206 | - * See \OCP\Constants::PERMISSION_* |
|
| 207 | - * |
|
| 208 | - * @param int $permissions |
|
| 209 | - * @return \OCP\Share\IShare The modified object |
|
| 210 | - * @since 9.0.0 |
|
| 211 | - */ |
|
| 212 | - public function setPermissions($permissions); |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Get the share permissions |
|
| 216 | - * See \OCP\Constants::PERMISSION_* |
|
| 217 | - * |
|
| 218 | - * @return int |
|
| 219 | - * @since 9.0.0 |
|
| 220 | - */ |
|
| 221 | - public function getPermissions(); |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Set the expiration date |
|
| 225 | - * |
|
| 226 | - * @param null|\DateTime $expireDate |
|
| 227 | - * @return \OCP\Share\IShare The modified object |
|
| 228 | - * @since 9.0.0 |
|
| 229 | - */ |
|
| 230 | - public function setExpirationDate($expireDate); |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Get the expiration date |
|
| 234 | - * |
|
| 235 | - * @return \DateTime |
|
| 236 | - * @since 9.0.0 |
|
| 237 | - */ |
|
| 238 | - public function getExpirationDate(); |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Set the sharer of the path. |
|
| 242 | - * |
|
| 243 | - * @param string $sharedBy |
|
| 244 | - * @return \OCP\Share\IShare The modified object |
|
| 245 | - * @since 9.0.0 |
|
| 246 | - */ |
|
| 247 | - public function setSharedBy($sharedBy); |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Get share sharer |
|
| 251 | - * |
|
| 252 | - * @return string |
|
| 253 | - * @since 9.0.0 |
|
| 254 | - */ |
|
| 255 | - public function getSharedBy(); |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Set the original share owner (who owns the path that is shared) |
|
| 259 | - * |
|
| 260 | - * @param string $shareOwner |
|
| 261 | - * @return \OCP\Share\IShare The modified object |
|
| 262 | - * @since 9.0.0 |
|
| 263 | - */ |
|
| 264 | - public function setShareOwner($shareOwner); |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Get the original share owner (who owns the path that is shared) |
|
| 268 | - * |
|
| 269 | - * @return string |
|
| 270 | - * @since 9.0.0 |
|
| 271 | - */ |
|
| 272 | - public function getShareOwner(); |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Set the password for this share. |
|
| 276 | - * When the share is passed to the share manager to be created |
|
| 277 | - * or updated the password will be hashed. |
|
| 278 | - * |
|
| 279 | - * @param string $password |
|
| 280 | - * @return \OCP\Share\IShare The modified object |
|
| 281 | - * @since 9.0.0 |
|
| 282 | - */ |
|
| 283 | - public function setPassword($password); |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Get the password of this share. |
|
| 287 | - * If this share is obtained via a shareprovider the password is |
|
| 288 | - * hashed. |
|
| 289 | - * |
|
| 290 | - * @return string |
|
| 291 | - * @since 9.0.0 |
|
| 292 | - */ |
|
| 293 | - public function getPassword(); |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Set the public link token. |
|
| 297 | - * |
|
| 298 | - * @param string $token |
|
| 299 | - * @return \OCP\Share\IShare The modified object |
|
| 300 | - * @since 9.0.0 |
|
| 301 | - */ |
|
| 302 | - public function setToken($token); |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Get the public link token. |
|
| 306 | - * |
|
| 307 | - * @return string |
|
| 308 | - * @since 9.0.0 |
|
| 309 | - */ |
|
| 310 | - public function getToken(); |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Set the target path of this share relative to the recipients user folder. |
|
| 314 | - * |
|
| 315 | - * @param string $target |
|
| 316 | - * @return \OCP\Share\IShare The modified object |
|
| 317 | - * @since 9.0.0 |
|
| 318 | - */ |
|
| 319 | - public function setTarget($target); |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get the target path of this share relative to the recipients user folder. |
|
| 323 | - * |
|
| 324 | - * @return string |
|
| 325 | - * @since 9.0.0 |
|
| 326 | - */ |
|
| 327 | - public function getTarget(); |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Set the time this share was created |
|
| 331 | - * |
|
| 332 | - * @param \DateTime $shareTime |
|
| 333 | - * @return \OCP\Share\IShare The modified object |
|
| 334 | - * @since 9.0.0 |
|
| 335 | - */ |
|
| 336 | - public function setShareTime(\DateTime $shareTime); |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Get the timestamp this share was created |
|
| 340 | - * |
|
| 341 | - * @return \DateTime |
|
| 342 | - * @since 9.0.0 |
|
| 343 | - */ |
|
| 344 | - public function getShareTime(); |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Set if the recipient is informed by mail about the share. |
|
| 348 | - * |
|
| 349 | - * @param bool $mailSend |
|
| 350 | - * @return \OCP\Share\IShare The modified object |
|
| 351 | - * @since 9.0.0 |
|
| 352 | - */ |
|
| 353 | - public function setMailSend($mailSend); |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Get if the recipient informed by mail about the share. |
|
| 357 | - * |
|
| 358 | - * @return bool |
|
| 359 | - * @since 9.0.0 |
|
| 360 | - */ |
|
| 361 | - public function getMailSend(); |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Set the cache entry for the shared node |
|
| 365 | - * |
|
| 366 | - * @param ICacheEntry $entry |
|
| 367 | - * @since 11.0.0 |
|
| 368 | - */ |
|
| 369 | - public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Get the cache entry for the shared node |
|
| 373 | - * |
|
| 374 | - * @return null|ICacheEntry |
|
| 375 | - * @since 11.0.0 |
|
| 376 | - */ |
|
| 377 | - public function getNodeCacheEntry(); |
|
| 40 | + /** |
|
| 41 | + * Set the internal id of the share |
|
| 42 | + * It is only allowed to set the internal id of a share once. |
|
| 43 | + * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 44 | + * |
|
| 45 | + * @param string $id |
|
| 46 | + * @return \OCP\Share\IShare |
|
| 47 | + * @throws IllegalIDChangeException |
|
| 48 | + * @throws \InvalidArgumentException |
|
| 49 | + * @since 9.1.0 |
|
| 50 | + */ |
|
| 51 | + public function setId($id); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get the internal id of the share. |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + * @since 9.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getId(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get the full share id. This is the <providerid>:<internalid>. |
|
| 63 | + * The full id is unique in the system. |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + * @since 9.0.0 |
|
| 67 | + * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 68 | + */ |
|
| 69 | + public function getFullId(); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Set the provider id of the share |
|
| 73 | + * It is only allowed to set the provider id of a share once. |
|
| 74 | + * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 75 | + * |
|
| 76 | + * @param string $id |
|
| 77 | + * @return \OCP\Share\IShare |
|
| 78 | + * @throws IllegalIDChangeException |
|
| 79 | + * @throws \InvalidArgumentException |
|
| 80 | + * @since 9.1.0 |
|
| 81 | + */ |
|
| 82 | + public function setProviderId($id); |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Set the node of the file/folder that is shared |
|
| 86 | + * |
|
| 87 | + * @param Node $node |
|
| 88 | + * @return \OCP\Share\IShare The modified object |
|
| 89 | + * @since 9.0.0 |
|
| 90 | + */ |
|
| 91 | + public function setNode(Node $node); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Get the node of the file/folder that is shared |
|
| 95 | + * |
|
| 96 | + * @return File|Folder |
|
| 97 | + * @since 9.0.0 |
|
| 98 | + * @throws NotFoundException |
|
| 99 | + */ |
|
| 100 | + public function getNode(); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Set file id for lazy evaluation of the node |
|
| 104 | + * @param int $fileId |
|
| 105 | + * @return \OCP\Share\IShare The modified object |
|
| 106 | + * @since 9.0.0 |
|
| 107 | + */ |
|
| 108 | + public function setNodeId($fileId); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get the fileid of the node of this share |
|
| 112 | + * @return int |
|
| 113 | + * @since 9.0.0 |
|
| 114 | + * @throws NotFoundException |
|
| 115 | + */ |
|
| 116 | + public function getNodeId(); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Set the type of node (file/folder) |
|
| 120 | + * |
|
| 121 | + * @param string $type |
|
| 122 | + * @return \OCP\Share\IShare The modified object |
|
| 123 | + * @since 9.0.0 |
|
| 124 | + */ |
|
| 125 | + public function setNodeType($type); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get the type of node (file/folder) |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + * @since 9.0.0 |
|
| 132 | + * @throws NotFoundException |
|
| 133 | + */ |
|
| 134 | + public function getNodeType(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Set the shareType |
|
| 138 | + * |
|
| 139 | + * @param int $shareType |
|
| 140 | + * @return \OCP\Share\IShare The modified object |
|
| 141 | + * @since 9.0.0 |
|
| 142 | + */ |
|
| 143 | + public function setShareType($shareType); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Get the shareType |
|
| 147 | + * |
|
| 148 | + * @return int |
|
| 149 | + * @since 9.0.0 |
|
| 150 | + */ |
|
| 151 | + public function getShareType(); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Set the receiver of this share. |
|
| 155 | + * |
|
| 156 | + * @param string $sharedWith |
|
| 157 | + * @return \OCP\Share\IShare The modified object |
|
| 158 | + * @since 9.0.0 |
|
| 159 | + */ |
|
| 160 | + public function setSharedWith($sharedWith); |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the receiver of this share. |
|
| 164 | + * |
|
| 165 | + * @return string |
|
| 166 | + * @since 9.0.0 |
|
| 167 | + */ |
|
| 168 | + public function getSharedWith(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Set the display name of the receiver of this share. |
|
| 172 | + * |
|
| 173 | + * @param string $displayName |
|
| 174 | + * @return \OCP\Share\IShare The modified object |
|
| 175 | + * @since 9.0.0 |
|
| 176 | + */ |
|
| 177 | + public function setSharedWithDisplayName($displayName); |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the display name of the receiver of this share. |
|
| 181 | + * |
|
| 182 | + * @return string |
|
| 183 | + * @since 9.0.0 |
|
| 184 | + */ |
|
| 185 | + public function getSharedWithDisplayName(); |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Set the avatar of the receiver of this share. |
|
| 189 | + * |
|
| 190 | + * @param string $src |
|
| 191 | + * @return \OCP\Share\IShare The modified object |
|
| 192 | + * @since 9.0.0 |
|
| 193 | + */ |
|
| 194 | + public function setSharedWithAvatar($src); |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Get the display name of the receiver of this share. |
|
| 198 | + * |
|
| 199 | + * @return string |
|
| 200 | + * @since 9.0.0 |
|
| 201 | + */ |
|
| 202 | + public function getSharedWithAvatar(); |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Set the permissions. |
|
| 206 | + * See \OCP\Constants::PERMISSION_* |
|
| 207 | + * |
|
| 208 | + * @param int $permissions |
|
| 209 | + * @return \OCP\Share\IShare The modified object |
|
| 210 | + * @since 9.0.0 |
|
| 211 | + */ |
|
| 212 | + public function setPermissions($permissions); |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Get the share permissions |
|
| 216 | + * See \OCP\Constants::PERMISSION_* |
|
| 217 | + * |
|
| 218 | + * @return int |
|
| 219 | + * @since 9.0.0 |
|
| 220 | + */ |
|
| 221 | + public function getPermissions(); |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Set the expiration date |
|
| 225 | + * |
|
| 226 | + * @param null|\DateTime $expireDate |
|
| 227 | + * @return \OCP\Share\IShare The modified object |
|
| 228 | + * @since 9.0.0 |
|
| 229 | + */ |
|
| 230 | + public function setExpirationDate($expireDate); |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Get the expiration date |
|
| 234 | + * |
|
| 235 | + * @return \DateTime |
|
| 236 | + * @since 9.0.0 |
|
| 237 | + */ |
|
| 238 | + public function getExpirationDate(); |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Set the sharer of the path. |
|
| 242 | + * |
|
| 243 | + * @param string $sharedBy |
|
| 244 | + * @return \OCP\Share\IShare The modified object |
|
| 245 | + * @since 9.0.0 |
|
| 246 | + */ |
|
| 247 | + public function setSharedBy($sharedBy); |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Get share sharer |
|
| 251 | + * |
|
| 252 | + * @return string |
|
| 253 | + * @since 9.0.0 |
|
| 254 | + */ |
|
| 255 | + public function getSharedBy(); |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Set the original share owner (who owns the path that is shared) |
|
| 259 | + * |
|
| 260 | + * @param string $shareOwner |
|
| 261 | + * @return \OCP\Share\IShare The modified object |
|
| 262 | + * @since 9.0.0 |
|
| 263 | + */ |
|
| 264 | + public function setShareOwner($shareOwner); |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Get the original share owner (who owns the path that is shared) |
|
| 268 | + * |
|
| 269 | + * @return string |
|
| 270 | + * @since 9.0.0 |
|
| 271 | + */ |
|
| 272 | + public function getShareOwner(); |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Set the password for this share. |
|
| 276 | + * When the share is passed to the share manager to be created |
|
| 277 | + * or updated the password will be hashed. |
|
| 278 | + * |
|
| 279 | + * @param string $password |
|
| 280 | + * @return \OCP\Share\IShare The modified object |
|
| 281 | + * @since 9.0.0 |
|
| 282 | + */ |
|
| 283 | + public function setPassword($password); |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Get the password of this share. |
|
| 287 | + * If this share is obtained via a shareprovider the password is |
|
| 288 | + * hashed. |
|
| 289 | + * |
|
| 290 | + * @return string |
|
| 291 | + * @since 9.0.0 |
|
| 292 | + */ |
|
| 293 | + public function getPassword(); |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Set the public link token. |
|
| 297 | + * |
|
| 298 | + * @param string $token |
|
| 299 | + * @return \OCP\Share\IShare The modified object |
|
| 300 | + * @since 9.0.0 |
|
| 301 | + */ |
|
| 302 | + public function setToken($token); |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Get the public link token. |
|
| 306 | + * |
|
| 307 | + * @return string |
|
| 308 | + * @since 9.0.0 |
|
| 309 | + */ |
|
| 310 | + public function getToken(); |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Set the target path of this share relative to the recipients user folder. |
|
| 314 | + * |
|
| 315 | + * @param string $target |
|
| 316 | + * @return \OCP\Share\IShare The modified object |
|
| 317 | + * @since 9.0.0 |
|
| 318 | + */ |
|
| 319 | + public function setTarget($target); |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get the target path of this share relative to the recipients user folder. |
|
| 323 | + * |
|
| 324 | + * @return string |
|
| 325 | + * @since 9.0.0 |
|
| 326 | + */ |
|
| 327 | + public function getTarget(); |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Set the time this share was created |
|
| 331 | + * |
|
| 332 | + * @param \DateTime $shareTime |
|
| 333 | + * @return \OCP\Share\IShare The modified object |
|
| 334 | + * @since 9.0.0 |
|
| 335 | + */ |
|
| 336 | + public function setShareTime(\DateTime $shareTime); |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Get the timestamp this share was created |
|
| 340 | + * |
|
| 341 | + * @return \DateTime |
|
| 342 | + * @since 9.0.0 |
|
| 343 | + */ |
|
| 344 | + public function getShareTime(); |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Set if the recipient is informed by mail about the share. |
|
| 348 | + * |
|
| 349 | + * @param bool $mailSend |
|
| 350 | + * @return \OCP\Share\IShare The modified object |
|
| 351 | + * @since 9.0.0 |
|
| 352 | + */ |
|
| 353 | + public function setMailSend($mailSend); |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Get if the recipient informed by mail about the share. |
|
| 357 | + * |
|
| 358 | + * @return bool |
|
| 359 | + * @since 9.0.0 |
|
| 360 | + */ |
|
| 361 | + public function getMailSend(); |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Set the cache entry for the shared node |
|
| 365 | + * |
|
| 366 | + * @param ICacheEntry $entry |
|
| 367 | + * @since 11.0.0 |
|
| 368 | + */ |
|
| 369 | + public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Get the cache entry for the shared node |
|
| 373 | + * |
|
| 374 | + * @return null|ICacheEntry |
|
| 375 | + * @since 11.0.0 |
|
| 376 | + */ |
|
| 377 | + public function getNodeCacheEntry(); |
|
| 378 | 378 | } |
@@ -52,895 +52,895 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | class ShareAPIController extends OCSController { |
| 54 | 54 | |
| 55 | - /** @var IManager */ |
|
| 56 | - private $shareManager; |
|
| 57 | - /** @var IGroupManager */ |
|
| 58 | - private $groupManager; |
|
| 59 | - /** @var IUserManager */ |
|
| 60 | - private $userManager; |
|
| 61 | - /** @var IRequest */ |
|
| 62 | - protected $request; |
|
| 63 | - /** @var IRootFolder */ |
|
| 64 | - private $rootFolder; |
|
| 65 | - /** @var IURLGenerator */ |
|
| 66 | - private $urlGenerator; |
|
| 67 | - /** @var string */ |
|
| 68 | - private $currentUser; |
|
| 69 | - /** @var IL10N */ |
|
| 70 | - private $l; |
|
| 71 | - /** @var \OCP\Files\Node */ |
|
| 72 | - private $lockedNode; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Share20OCS constructor. |
|
| 76 | - * |
|
| 77 | - * @param string $appName |
|
| 78 | - * @param IRequest $request |
|
| 79 | - * @param IManager $shareManager |
|
| 80 | - * @param IGroupManager $groupManager |
|
| 81 | - * @param IUserManager $userManager |
|
| 82 | - * @param IRootFolder $rootFolder |
|
| 83 | - * @param IURLGenerator $urlGenerator |
|
| 84 | - * @param string $userId |
|
| 85 | - * @param IL10N $l10n |
|
| 86 | - */ |
|
| 87 | - public function __construct( |
|
| 88 | - $appName, |
|
| 89 | - IRequest $request, |
|
| 90 | - IManager $shareManager, |
|
| 91 | - IGroupManager $groupManager, |
|
| 92 | - IUserManager $userManager, |
|
| 93 | - IRootFolder $rootFolder, |
|
| 94 | - IURLGenerator $urlGenerator, |
|
| 95 | - $userId, |
|
| 96 | - IL10N $l10n |
|
| 97 | - ) { |
|
| 98 | - parent::__construct($appName, $request); |
|
| 99 | - |
|
| 100 | - $this->shareManager = $shareManager; |
|
| 101 | - $this->userManager = $userManager; |
|
| 102 | - $this->groupManager = $groupManager; |
|
| 103 | - $this->request = $request; |
|
| 104 | - $this->rootFolder = $rootFolder; |
|
| 105 | - $this->urlGenerator = $urlGenerator; |
|
| 106 | - $this->currentUser = $userId; |
|
| 107 | - $this->l = $l10n; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Convert an IShare to an array for OCS output |
|
| 112 | - * |
|
| 113 | - * @param \OCP\Share\IShare $share |
|
| 114 | - * @param Node|null $recipientNode |
|
| 115 | - * @return array |
|
| 116 | - * @throws NotFoundException In case the node can't be resolved. |
|
| 117 | - */ |
|
| 118 | - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 119 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 120 | - $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 121 | - |
|
| 122 | - $result = [ |
|
| 123 | - 'id' => $share->getId(), |
|
| 124 | - 'share_type' => $share->getShareType(), |
|
| 125 | - 'uid_owner' => $share->getSharedBy(), |
|
| 126 | - 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 127 | - 'permissions' => $share->getPermissions(), |
|
| 128 | - 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 129 | - 'parent' => null, |
|
| 130 | - 'expiration' => null, |
|
| 131 | - 'token' => null, |
|
| 132 | - 'uid_file_owner' => $share->getShareOwner(), |
|
| 133 | - 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 134 | - ]; |
|
| 135 | - |
|
| 136 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 137 | - if ($recipientNode) { |
|
| 138 | - $node = $recipientNode; |
|
| 139 | - } else { |
|
| 140 | - $nodes = $userFolder->getById($share->getNodeId()); |
|
| 141 | - |
|
| 142 | - if (empty($nodes)) { |
|
| 143 | - // fallback to guessing the path |
|
| 144 | - $node = $userFolder->get($share->getTarget()); |
|
| 145 | - if ($node === null) { |
|
| 146 | - throw new NotFoundException(); |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $node = $nodes[0]; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 154 | - if ($node instanceOf \OCP\Files\Folder) { |
|
| 155 | - $result['item_type'] = 'folder'; |
|
| 156 | - } else { |
|
| 157 | - $result['item_type'] = 'file'; |
|
| 158 | - } |
|
| 159 | - $result['mimetype'] = $node->getMimetype(); |
|
| 160 | - $result['storage_id'] = $node->getStorage()->getId(); |
|
| 161 | - $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 162 | - $result['item_source'] = $node->getId(); |
|
| 163 | - $result['file_source'] = $node->getId(); |
|
| 164 | - $result['file_parent'] = $node->getParent()->getId(); |
|
| 165 | - $result['file_target'] = $share->getTarget(); |
|
| 166 | - |
|
| 167 | - $expiration = $share->getExpirationDate(); |
|
| 168 | - if ($expiration !== null) { |
|
| 169 | - $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 173 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 174 | - $result['share_with'] = $share->getSharedWith(); |
|
| 175 | - $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 176 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 177 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
| 178 | - $result['share_with'] = $share->getSharedWith(); |
|
| 179 | - $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 180 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 181 | - |
|
| 182 | - $result['share_with'] = $share->getPassword(); |
|
| 183 | - $result['share_with_displayname'] = $share->getPassword(); |
|
| 184 | - |
|
| 185 | - $result['token'] = $share->getToken(); |
|
| 186 | - $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 187 | - |
|
| 188 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 189 | - $result['share_with'] = $share->getSharedWith(); |
|
| 190 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 191 | - $result['token'] = $share->getToken(); |
|
| 192 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 193 | - $result['share_with'] = $share->getSharedWith(); |
|
| 194 | - $result['password'] = $share->getPassword(); |
|
| 195 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 196 | - $result['token'] = $share->getToken(); |
|
| 197 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 198 | - if ($share->getSharedWithDisplayName() !== '') { |
|
| 199 | - $result['share_with_displayname'] = $share->getSharedWithDisplayName(); |
|
| 200 | - $result['share_with_avatar'] = $share->getSharedWithAvatar(); |
|
| 201 | - $result['share_with'] = $share->getSharedWith(); |
|
| 202 | - } else { |
|
| 203 | - $result['share_with_displayname'] = $share->getSharedWith(); |
|
| 204 | - $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 210 | - |
|
| 211 | - return $result; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Check if one of the users address books knows the exact property, if |
|
| 216 | - * yes we return the full name. |
|
| 217 | - * |
|
| 218 | - * @param string $query |
|
| 219 | - * @param string $property |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - private function getDisplayNameFromAddressBook($query, $property) { |
|
| 223 | - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 224 | - $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 225 | - foreach ($result as $r) { |
|
| 226 | - foreach($r[$property] as $value) { |
|
| 227 | - if ($value === $query) { |
|
| 228 | - return $r['FN']; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return $query; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Get a specific share by id |
|
| 238 | - * |
|
| 239 | - * @NoAdminRequired |
|
| 240 | - * |
|
| 241 | - * @param string $id |
|
| 242 | - * @return DataResponse |
|
| 243 | - * @throws OCSNotFoundException |
|
| 244 | - */ |
|
| 245 | - public function getShare($id) { |
|
| 246 | - try { |
|
| 247 | - $share = $this->getShareById($id); |
|
| 248 | - } catch (ShareNotFound $e) { |
|
| 249 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if ($this->canAccessShare($share)) { |
|
| 253 | - try { |
|
| 254 | - $share = $this->formatShare($share); |
|
| 255 | - return new DataResponse([$share]); |
|
| 256 | - } catch (NotFoundException $e) { |
|
| 257 | - //Fall trough |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Delete a share |
|
| 266 | - * |
|
| 267 | - * @NoAdminRequired |
|
| 268 | - * |
|
| 269 | - * @param string $id |
|
| 270 | - * @return DataResponse |
|
| 271 | - * @throws OCSNotFoundException |
|
| 272 | - */ |
|
| 273 | - public function deleteShare($id) { |
|
| 274 | - try { |
|
| 275 | - $share = $this->getShareById($id); |
|
| 276 | - } catch (ShareNotFound $e) { |
|
| 277 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - try { |
|
| 281 | - $this->lock($share->getNode()); |
|
| 282 | - } catch (LockedException $e) { |
|
| 283 | - throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if (!$this->canAccessShare($share)) { |
|
| 287 | - throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 291 | - $share->getShareOwner() !== $this->currentUser && |
|
| 292 | - $share->getSharedBy() !== $this->currentUser) { |
|
| 293 | - $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 294 | - } else { |
|
| 295 | - $this->shareManager->deleteShare($share); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return new DataResponse(); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * @NoAdminRequired |
|
| 303 | - * |
|
| 304 | - * @param string $path |
|
| 305 | - * @param int $permissions |
|
| 306 | - * @param int $shareType |
|
| 307 | - * @param string $shareWith |
|
| 308 | - * @param string $publicUpload |
|
| 309 | - * @param string $password |
|
| 310 | - * @param string $expireDate |
|
| 311 | - * |
|
| 312 | - * @return DataResponse |
|
| 313 | - * @throws OCSNotFoundException |
|
| 314 | - * @throws OCSForbiddenException |
|
| 315 | - * @throws OCSBadRequestException |
|
| 316 | - * @throws OCSException |
|
| 317 | - */ |
|
| 318 | - public function createShare( |
|
| 319 | - $path = null, |
|
| 320 | - $permissions = \OCP\Constants::PERMISSION_ALL, |
|
| 321 | - $shareType = -1, |
|
| 322 | - $shareWith = null, |
|
| 323 | - $publicUpload = 'false', |
|
| 324 | - $password = '', |
|
| 325 | - $expireDate = '' |
|
| 326 | - ) { |
|
| 327 | - $share = $this->shareManager->newShare(); |
|
| 328 | - |
|
| 329 | - // Verify path |
|
| 330 | - if ($path === null) { |
|
| 331 | - throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 335 | - try { |
|
| 336 | - $path = $userFolder->get($path); |
|
| 337 | - } catch (NotFoundException $e) { |
|
| 338 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - $share->setNode($path); |
|
| 342 | - |
|
| 343 | - try { |
|
| 344 | - $this->lock($share->getNode()); |
|
| 345 | - } catch (LockedException $e) { |
|
| 346 | - throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { |
|
| 350 | - throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // Shares always require read permissions |
|
| 354 | - $permissions |= \OCP\Constants::PERMISSION_READ; |
|
| 355 | - |
|
| 356 | - if ($path instanceof \OCP\Files\File) { |
|
| 357 | - // Single file shares should never have delete or create permissions |
|
| 358 | - $permissions &= ~\OCP\Constants::PERMISSION_DELETE; |
|
| 359 | - $permissions &= ~\OCP\Constants::PERMISSION_CREATE; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /* |
|
| 55 | + /** @var IManager */ |
|
| 56 | + private $shareManager; |
|
| 57 | + /** @var IGroupManager */ |
|
| 58 | + private $groupManager; |
|
| 59 | + /** @var IUserManager */ |
|
| 60 | + private $userManager; |
|
| 61 | + /** @var IRequest */ |
|
| 62 | + protected $request; |
|
| 63 | + /** @var IRootFolder */ |
|
| 64 | + private $rootFolder; |
|
| 65 | + /** @var IURLGenerator */ |
|
| 66 | + private $urlGenerator; |
|
| 67 | + /** @var string */ |
|
| 68 | + private $currentUser; |
|
| 69 | + /** @var IL10N */ |
|
| 70 | + private $l; |
|
| 71 | + /** @var \OCP\Files\Node */ |
|
| 72 | + private $lockedNode; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Share20OCS constructor. |
|
| 76 | + * |
|
| 77 | + * @param string $appName |
|
| 78 | + * @param IRequest $request |
|
| 79 | + * @param IManager $shareManager |
|
| 80 | + * @param IGroupManager $groupManager |
|
| 81 | + * @param IUserManager $userManager |
|
| 82 | + * @param IRootFolder $rootFolder |
|
| 83 | + * @param IURLGenerator $urlGenerator |
|
| 84 | + * @param string $userId |
|
| 85 | + * @param IL10N $l10n |
|
| 86 | + */ |
|
| 87 | + public function __construct( |
|
| 88 | + $appName, |
|
| 89 | + IRequest $request, |
|
| 90 | + IManager $shareManager, |
|
| 91 | + IGroupManager $groupManager, |
|
| 92 | + IUserManager $userManager, |
|
| 93 | + IRootFolder $rootFolder, |
|
| 94 | + IURLGenerator $urlGenerator, |
|
| 95 | + $userId, |
|
| 96 | + IL10N $l10n |
|
| 97 | + ) { |
|
| 98 | + parent::__construct($appName, $request); |
|
| 99 | + |
|
| 100 | + $this->shareManager = $shareManager; |
|
| 101 | + $this->userManager = $userManager; |
|
| 102 | + $this->groupManager = $groupManager; |
|
| 103 | + $this->request = $request; |
|
| 104 | + $this->rootFolder = $rootFolder; |
|
| 105 | + $this->urlGenerator = $urlGenerator; |
|
| 106 | + $this->currentUser = $userId; |
|
| 107 | + $this->l = $l10n; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Convert an IShare to an array for OCS output |
|
| 112 | + * |
|
| 113 | + * @param \OCP\Share\IShare $share |
|
| 114 | + * @param Node|null $recipientNode |
|
| 115 | + * @return array |
|
| 116 | + * @throws NotFoundException In case the node can't be resolved. |
|
| 117 | + */ |
|
| 118 | + protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 119 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 120 | + $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 121 | + |
|
| 122 | + $result = [ |
|
| 123 | + 'id' => $share->getId(), |
|
| 124 | + 'share_type' => $share->getShareType(), |
|
| 125 | + 'uid_owner' => $share->getSharedBy(), |
|
| 126 | + 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 127 | + 'permissions' => $share->getPermissions(), |
|
| 128 | + 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 129 | + 'parent' => null, |
|
| 130 | + 'expiration' => null, |
|
| 131 | + 'token' => null, |
|
| 132 | + 'uid_file_owner' => $share->getShareOwner(), |
|
| 133 | + 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 134 | + ]; |
|
| 135 | + |
|
| 136 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 137 | + if ($recipientNode) { |
|
| 138 | + $node = $recipientNode; |
|
| 139 | + } else { |
|
| 140 | + $nodes = $userFolder->getById($share->getNodeId()); |
|
| 141 | + |
|
| 142 | + if (empty($nodes)) { |
|
| 143 | + // fallback to guessing the path |
|
| 144 | + $node = $userFolder->get($share->getTarget()); |
|
| 145 | + if ($node === null) { |
|
| 146 | + throw new NotFoundException(); |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $node = $nodes[0]; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 154 | + if ($node instanceOf \OCP\Files\Folder) { |
|
| 155 | + $result['item_type'] = 'folder'; |
|
| 156 | + } else { |
|
| 157 | + $result['item_type'] = 'file'; |
|
| 158 | + } |
|
| 159 | + $result['mimetype'] = $node->getMimetype(); |
|
| 160 | + $result['storage_id'] = $node->getStorage()->getId(); |
|
| 161 | + $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 162 | + $result['item_source'] = $node->getId(); |
|
| 163 | + $result['file_source'] = $node->getId(); |
|
| 164 | + $result['file_parent'] = $node->getParent()->getId(); |
|
| 165 | + $result['file_target'] = $share->getTarget(); |
|
| 166 | + |
|
| 167 | + $expiration = $share->getExpirationDate(); |
|
| 168 | + if ($expiration !== null) { |
|
| 169 | + $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 173 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 174 | + $result['share_with'] = $share->getSharedWith(); |
|
| 175 | + $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 176 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 177 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
| 178 | + $result['share_with'] = $share->getSharedWith(); |
|
| 179 | + $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 180 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 181 | + |
|
| 182 | + $result['share_with'] = $share->getPassword(); |
|
| 183 | + $result['share_with_displayname'] = $share->getPassword(); |
|
| 184 | + |
|
| 185 | + $result['token'] = $share->getToken(); |
|
| 186 | + $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 187 | + |
|
| 188 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 189 | + $result['share_with'] = $share->getSharedWith(); |
|
| 190 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 191 | + $result['token'] = $share->getToken(); |
|
| 192 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 193 | + $result['share_with'] = $share->getSharedWith(); |
|
| 194 | + $result['password'] = $share->getPassword(); |
|
| 195 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 196 | + $result['token'] = $share->getToken(); |
|
| 197 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 198 | + if ($share->getSharedWithDisplayName() !== '') { |
|
| 199 | + $result['share_with_displayname'] = $share->getSharedWithDisplayName(); |
|
| 200 | + $result['share_with_avatar'] = $share->getSharedWithAvatar(); |
|
| 201 | + $result['share_with'] = $share->getSharedWith(); |
|
| 202 | + } else { |
|
| 203 | + $result['share_with_displayname'] = $share->getSharedWith(); |
|
| 204 | + $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 210 | + |
|
| 211 | + return $result; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Check if one of the users address books knows the exact property, if |
|
| 216 | + * yes we return the full name. |
|
| 217 | + * |
|
| 218 | + * @param string $query |
|
| 219 | + * @param string $property |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + private function getDisplayNameFromAddressBook($query, $property) { |
|
| 223 | + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 224 | + $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 225 | + foreach ($result as $r) { |
|
| 226 | + foreach($r[$property] as $value) { |
|
| 227 | + if ($value === $query) { |
|
| 228 | + return $r['FN']; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return $query; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Get a specific share by id |
|
| 238 | + * |
|
| 239 | + * @NoAdminRequired |
|
| 240 | + * |
|
| 241 | + * @param string $id |
|
| 242 | + * @return DataResponse |
|
| 243 | + * @throws OCSNotFoundException |
|
| 244 | + */ |
|
| 245 | + public function getShare($id) { |
|
| 246 | + try { |
|
| 247 | + $share = $this->getShareById($id); |
|
| 248 | + } catch (ShareNotFound $e) { |
|
| 249 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if ($this->canAccessShare($share)) { |
|
| 253 | + try { |
|
| 254 | + $share = $this->formatShare($share); |
|
| 255 | + return new DataResponse([$share]); |
|
| 256 | + } catch (NotFoundException $e) { |
|
| 257 | + //Fall trough |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Delete a share |
|
| 266 | + * |
|
| 267 | + * @NoAdminRequired |
|
| 268 | + * |
|
| 269 | + * @param string $id |
|
| 270 | + * @return DataResponse |
|
| 271 | + * @throws OCSNotFoundException |
|
| 272 | + */ |
|
| 273 | + public function deleteShare($id) { |
|
| 274 | + try { |
|
| 275 | + $share = $this->getShareById($id); |
|
| 276 | + } catch (ShareNotFound $e) { |
|
| 277 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + try { |
|
| 281 | + $this->lock($share->getNode()); |
|
| 282 | + } catch (LockedException $e) { |
|
| 283 | + throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if (!$this->canAccessShare($share)) { |
|
| 287 | + throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 291 | + $share->getShareOwner() !== $this->currentUser && |
|
| 292 | + $share->getSharedBy() !== $this->currentUser) { |
|
| 293 | + $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 294 | + } else { |
|
| 295 | + $this->shareManager->deleteShare($share); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return new DataResponse(); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * @NoAdminRequired |
|
| 303 | + * |
|
| 304 | + * @param string $path |
|
| 305 | + * @param int $permissions |
|
| 306 | + * @param int $shareType |
|
| 307 | + * @param string $shareWith |
|
| 308 | + * @param string $publicUpload |
|
| 309 | + * @param string $password |
|
| 310 | + * @param string $expireDate |
|
| 311 | + * |
|
| 312 | + * @return DataResponse |
|
| 313 | + * @throws OCSNotFoundException |
|
| 314 | + * @throws OCSForbiddenException |
|
| 315 | + * @throws OCSBadRequestException |
|
| 316 | + * @throws OCSException |
|
| 317 | + */ |
|
| 318 | + public function createShare( |
|
| 319 | + $path = null, |
|
| 320 | + $permissions = \OCP\Constants::PERMISSION_ALL, |
|
| 321 | + $shareType = -1, |
|
| 322 | + $shareWith = null, |
|
| 323 | + $publicUpload = 'false', |
|
| 324 | + $password = '', |
|
| 325 | + $expireDate = '' |
|
| 326 | + ) { |
|
| 327 | + $share = $this->shareManager->newShare(); |
|
| 328 | + |
|
| 329 | + // Verify path |
|
| 330 | + if ($path === null) { |
|
| 331 | + throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 335 | + try { |
|
| 336 | + $path = $userFolder->get($path); |
|
| 337 | + } catch (NotFoundException $e) { |
|
| 338 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + $share->setNode($path); |
|
| 342 | + |
|
| 343 | + try { |
|
| 344 | + $this->lock($share->getNode()); |
|
| 345 | + } catch (LockedException $e) { |
|
| 346 | + throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) { |
|
| 350 | + throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // Shares always require read permissions |
|
| 354 | + $permissions |= \OCP\Constants::PERMISSION_READ; |
|
| 355 | + |
|
| 356 | + if ($path instanceof \OCP\Files\File) { |
|
| 357 | + // Single file shares should never have delete or create permissions |
|
| 358 | + $permissions &= ~\OCP\Constants::PERMISSION_DELETE; |
|
| 359 | + $permissions &= ~\OCP\Constants::PERMISSION_CREATE; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /* |
|
| 363 | 363 | * Hack for https://github.com/owncloud/core/issues/22587 |
| 364 | 364 | * We check the permissions via webdav. But the permissions of the mount point |
| 365 | 365 | * do not equal the share permissions. Here we fix that for federated mounts. |
| 366 | 366 | */ |
| 367 | - if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 368 | - $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 372 | - // Valid user is required to share |
|
| 373 | - if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 374 | - throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 375 | - } |
|
| 376 | - $share->setSharedWith($shareWith); |
|
| 377 | - $share->setPermissions($permissions); |
|
| 378 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 379 | - if (!$this->shareManager->allowGroupSharing()) { |
|
| 380 | - throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - // Valid group is required to share |
|
| 384 | - if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 385 | - throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 386 | - } |
|
| 387 | - $share->setSharedWith($shareWith); |
|
| 388 | - $share->setPermissions($permissions); |
|
| 389 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 390 | - //Can we even share links? |
|
| 391 | - if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 392 | - throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /* |
|
| 367 | + if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 368 | + $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 372 | + // Valid user is required to share |
|
| 373 | + if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 374 | + throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 375 | + } |
|
| 376 | + $share->setSharedWith($shareWith); |
|
| 377 | + $share->setPermissions($permissions); |
|
| 378 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 379 | + if (!$this->shareManager->allowGroupSharing()) { |
|
| 380 | + throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + // Valid group is required to share |
|
| 384 | + if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 385 | + throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 386 | + } |
|
| 387 | + $share->setSharedWith($shareWith); |
|
| 388 | + $share->setPermissions($permissions); |
|
| 389 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 390 | + //Can we even share links? |
|
| 391 | + if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 392 | + throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /* |
|
| 396 | 396 | * For now we only allow 1 link share. |
| 397 | 397 | * Return the existing link share if this is a duplicate |
| 398 | 398 | */ |
| 399 | - $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 400 | - if (!empty($existingShares)) { |
|
| 401 | - return new DataResponse($this->formatShare($existingShares[0])); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($publicUpload === 'true') { |
|
| 405 | - // Check if public upload is allowed |
|
| 406 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 407 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - // Public upload can only be set for folders |
|
| 411 | - if ($path instanceof \OCP\Files\File) { |
|
| 412 | - throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - $share->setPermissions( |
|
| 416 | - \OCP\Constants::PERMISSION_READ | |
|
| 417 | - \OCP\Constants::PERMISSION_CREATE | |
|
| 418 | - \OCP\Constants::PERMISSION_UPDATE | |
|
| 419 | - \OCP\Constants::PERMISSION_DELETE |
|
| 420 | - ); |
|
| 421 | - } else { |
|
| 422 | - $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - // Set password |
|
| 426 | - if ($password !== '') { |
|
| 427 | - $share->setPassword($password); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - //Expire date |
|
| 431 | - if ($expireDate !== '') { |
|
| 432 | - try { |
|
| 433 | - $expireDate = $this->parseDate($expireDate); |
|
| 434 | - $share->setExpirationDate($expireDate); |
|
| 435 | - } catch (\Exception $e) { |
|
| 436 | - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 441 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 442 | - throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - $share->setSharedWith($shareWith); |
|
| 446 | - $share->setPermissions($permissions); |
|
| 447 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 448 | - if ($share->getNodeType() === 'file') { |
|
| 449 | - $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 450 | - } else { |
|
| 451 | - $share->setPermissions( |
|
| 452 | - \OCP\Constants::PERMISSION_READ | |
|
| 453 | - \OCP\Constants::PERMISSION_CREATE | |
|
| 454 | - \OCP\Constants::PERMISSION_UPDATE | |
|
| 455 | - \OCP\Constants::PERMISSION_DELETE); |
|
| 456 | - } |
|
| 457 | - $share->setSharedWith($shareWith); |
|
| 458 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 459 | - if (!\OCP\App::isEnabled('circles')) { |
|
| 460 | - throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - $circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith); |
|
| 464 | - |
|
| 465 | - // Valid circle is required to share |
|
| 466 | - if ($circle === null) { |
|
| 467 | - throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 468 | - } |
|
| 469 | - $share->setSharedWith($shareWith); |
|
| 470 | - $share->setPermissions($permissions); |
|
| 471 | - } else { |
|
| 472 | - throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - $share->setShareType($shareType); |
|
| 476 | - $share->setSharedBy($this->currentUser); |
|
| 477 | - |
|
| 478 | - try { |
|
| 479 | - $share = $this->shareManager->createShare($share); |
|
| 480 | - } catch (GenericShareException $e) { |
|
| 481 | - $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 482 | - throw new OCSException($e->getHint(), $code); |
|
| 483 | - } catch (\Exception $e) { |
|
| 484 | - throw new OCSForbiddenException($e->getMessage()); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - $output = $this->formatShare($share); |
|
| 488 | - |
|
| 489 | - return new DataResponse($output); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 494 | - * @param boolean $includeTags |
|
| 495 | - * @return DataResponse |
|
| 496 | - */ |
|
| 497 | - private function getSharedWithMe($node = null, $includeTags) { |
|
| 498 | - |
|
| 499 | - $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 500 | - $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 501 | - $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 502 | - |
|
| 503 | - $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 504 | - |
|
| 505 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 506 | - return $share->getShareOwner() !== $this->currentUser; |
|
| 507 | - }); |
|
| 508 | - |
|
| 509 | - $formatted = []; |
|
| 510 | - foreach ($shares as $share) { |
|
| 511 | - if ($this->canAccessShare($share)) { |
|
| 512 | - try { |
|
| 513 | - $formatted[] = $this->formatShare($share); |
|
| 514 | - } catch (NotFoundException $e) { |
|
| 515 | - // Ignore this share |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - if ($includeTags) { |
|
| 521 | - $formatted = Helper::populateTags($formatted, 'file_source'); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - return new DataResponse($formatted); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * @param \OCP\Files\Folder $folder |
|
| 529 | - * @return DataResponse |
|
| 530 | - * @throws OCSBadRequestException |
|
| 531 | - */ |
|
| 532 | - private function getSharesInDir($folder) { |
|
| 533 | - if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 534 | - throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - $nodes = $folder->getDirectoryListing(); |
|
| 538 | - /** @var \OCP\Share\IShare[] $shares */ |
|
| 539 | - $shares = []; |
|
| 540 | - foreach ($nodes as $node) { |
|
| 541 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 542 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 543 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 544 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 545 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 546 | - } |
|
| 547 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 548 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $formatted = []; |
|
| 553 | - foreach ($shares as $share) { |
|
| 554 | - try { |
|
| 555 | - $formatted[] = $this->formatShare($share); |
|
| 556 | - } catch (NotFoundException $e) { |
|
| 557 | - //Ignore this share |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return new DataResponse($formatted); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * The getShares function. |
|
| 566 | - * |
|
| 567 | - * @NoAdminRequired |
|
| 568 | - * |
|
| 569 | - * @param string $shared_with_me |
|
| 570 | - * @param string $reshares |
|
| 571 | - * @param string $subfiles |
|
| 572 | - * @param string $path |
|
| 573 | - * |
|
| 574 | - * - Get shares by the current user |
|
| 575 | - * - Get shares by the current user and reshares (?reshares=true) |
|
| 576 | - * - Get shares with the current user (?shared_with_me=true) |
|
| 577 | - * - Get shares for a specific path (?path=...) |
|
| 578 | - * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 579 | - * |
|
| 580 | - * @return DataResponse |
|
| 581 | - * @throws OCSNotFoundException |
|
| 582 | - */ |
|
| 583 | - public function getShares( |
|
| 584 | - $shared_with_me = 'false', |
|
| 585 | - $reshares = 'false', |
|
| 586 | - $subfiles = 'false', |
|
| 587 | - $path = null, |
|
| 588 | - $include_tags = 'false' |
|
| 589 | - ) { |
|
| 590 | - |
|
| 591 | - if ($path !== null) { |
|
| 592 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 593 | - try { |
|
| 594 | - $path = $userFolder->get($path); |
|
| 595 | - $this->lock($path); |
|
| 596 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 597 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 598 | - } catch (LockedException $e) { |
|
| 599 | - throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - if ($shared_with_me === 'true') { |
|
| 604 | - $result = $this->getSharedWithMe($path, $include_tags); |
|
| 605 | - return $result; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - if ($subfiles === 'true') { |
|
| 609 | - $result = $this->getSharesInDir($path); |
|
| 610 | - return $result; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - if ($reshares === 'true') { |
|
| 614 | - $reshares = true; |
|
| 615 | - } else { |
|
| 616 | - $reshares = false; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - // Get all shares |
|
| 620 | - $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 621 | - $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 622 | - $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 623 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 624 | - $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 625 | - } else { |
|
| 626 | - $mailShares = []; |
|
| 627 | - } |
|
| 628 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 629 | - $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 630 | - } else { |
|
| 631 | - $circleShares = []; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 635 | - |
|
| 636 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 637 | - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 638 | - $shares = array_merge($shares, $federatedShares); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - $formatted = []; |
|
| 642 | - foreach ($shares as $share) { |
|
| 643 | - try { |
|
| 644 | - $formatted[] = $this->formatShare($share, $path); |
|
| 645 | - } catch (NotFoundException $e) { |
|
| 646 | - //Ignore share |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - if ($include_tags) { |
|
| 651 | - $formatted = Helper::populateTags($formatted, 'file_source'); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return new DataResponse($formatted); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * @NoAdminRequired |
|
| 659 | - * |
|
| 660 | - * @param int $id |
|
| 661 | - * @param int $permissions |
|
| 662 | - * @param string $password |
|
| 663 | - * @param string $publicUpload |
|
| 664 | - * @param string $expireDate |
|
| 665 | - * @return DataResponse |
|
| 666 | - * @throws OCSNotFoundException |
|
| 667 | - * @throws OCSBadRequestException |
|
| 668 | - * @throws OCSForbiddenException |
|
| 669 | - */ |
|
| 670 | - public function updateShare( |
|
| 671 | - $id, |
|
| 672 | - $permissions = null, |
|
| 673 | - $password = null, |
|
| 674 | - $publicUpload = null, |
|
| 675 | - $expireDate = null |
|
| 676 | - ) { |
|
| 677 | - try { |
|
| 678 | - $share = $this->getShareById($id); |
|
| 679 | - } catch (ShareNotFound $e) { |
|
| 680 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - $this->lock($share->getNode()); |
|
| 684 | - |
|
| 685 | - if (!$this->canAccessShare($share, false)) { |
|
| 686 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 690 | - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /* |
|
| 399 | + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 400 | + if (!empty($existingShares)) { |
|
| 401 | + return new DataResponse($this->formatShare($existingShares[0])); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($publicUpload === 'true') { |
|
| 405 | + // Check if public upload is allowed |
|
| 406 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 407 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + // Public upload can only be set for folders |
|
| 411 | + if ($path instanceof \OCP\Files\File) { |
|
| 412 | + throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + $share->setPermissions( |
|
| 416 | + \OCP\Constants::PERMISSION_READ | |
|
| 417 | + \OCP\Constants::PERMISSION_CREATE | |
|
| 418 | + \OCP\Constants::PERMISSION_UPDATE | |
|
| 419 | + \OCP\Constants::PERMISSION_DELETE |
|
| 420 | + ); |
|
| 421 | + } else { |
|
| 422 | + $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + // Set password |
|
| 426 | + if ($password !== '') { |
|
| 427 | + $share->setPassword($password); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + //Expire date |
|
| 431 | + if ($expireDate !== '') { |
|
| 432 | + try { |
|
| 433 | + $expireDate = $this->parseDate($expireDate); |
|
| 434 | + $share->setExpirationDate($expireDate); |
|
| 435 | + } catch (\Exception $e) { |
|
| 436 | + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 441 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 442 | + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + $share->setSharedWith($shareWith); |
|
| 446 | + $share->setPermissions($permissions); |
|
| 447 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 448 | + if ($share->getNodeType() === 'file') { |
|
| 449 | + $share->setPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 450 | + } else { |
|
| 451 | + $share->setPermissions( |
|
| 452 | + \OCP\Constants::PERMISSION_READ | |
|
| 453 | + \OCP\Constants::PERMISSION_CREATE | |
|
| 454 | + \OCP\Constants::PERMISSION_UPDATE | |
|
| 455 | + \OCP\Constants::PERMISSION_DELETE); |
|
| 456 | + } |
|
| 457 | + $share->setSharedWith($shareWith); |
|
| 458 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 459 | + if (!\OCP\App::isEnabled('circles')) { |
|
| 460 | + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + $circle = \OCA\Circles\Api\Circles::detailsCircle($shareWith); |
|
| 464 | + |
|
| 465 | + // Valid circle is required to share |
|
| 466 | + if ($circle === null) { |
|
| 467 | + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 468 | + } |
|
| 469 | + $share->setSharedWith($shareWith); |
|
| 470 | + $share->setPermissions($permissions); |
|
| 471 | + } else { |
|
| 472 | + throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + $share->setShareType($shareType); |
|
| 476 | + $share->setSharedBy($this->currentUser); |
|
| 477 | + |
|
| 478 | + try { |
|
| 479 | + $share = $this->shareManager->createShare($share); |
|
| 480 | + } catch (GenericShareException $e) { |
|
| 481 | + $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 482 | + throw new OCSException($e->getHint(), $code); |
|
| 483 | + } catch (\Exception $e) { |
|
| 484 | + throw new OCSForbiddenException($e->getMessage()); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + $output = $this->formatShare($share); |
|
| 488 | + |
|
| 489 | + return new DataResponse($output); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 494 | + * @param boolean $includeTags |
|
| 495 | + * @return DataResponse |
|
| 496 | + */ |
|
| 497 | + private function getSharedWithMe($node = null, $includeTags) { |
|
| 498 | + |
|
| 499 | + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 500 | + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 501 | + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 502 | + |
|
| 503 | + $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 504 | + |
|
| 505 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 506 | + return $share->getShareOwner() !== $this->currentUser; |
|
| 507 | + }); |
|
| 508 | + |
|
| 509 | + $formatted = []; |
|
| 510 | + foreach ($shares as $share) { |
|
| 511 | + if ($this->canAccessShare($share)) { |
|
| 512 | + try { |
|
| 513 | + $formatted[] = $this->formatShare($share); |
|
| 514 | + } catch (NotFoundException $e) { |
|
| 515 | + // Ignore this share |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + if ($includeTags) { |
|
| 521 | + $formatted = Helper::populateTags($formatted, 'file_source'); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + return new DataResponse($formatted); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * @param \OCP\Files\Folder $folder |
|
| 529 | + * @return DataResponse |
|
| 530 | + * @throws OCSBadRequestException |
|
| 531 | + */ |
|
| 532 | + private function getSharesInDir($folder) { |
|
| 533 | + if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 534 | + throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + $nodes = $folder->getDirectoryListing(); |
|
| 538 | + /** @var \OCP\Share\IShare[] $shares */ |
|
| 539 | + $shares = []; |
|
| 540 | + foreach ($nodes as $node) { |
|
| 541 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 542 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 543 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 544 | + if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 545 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 546 | + } |
|
| 547 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 548 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $formatted = []; |
|
| 553 | + foreach ($shares as $share) { |
|
| 554 | + try { |
|
| 555 | + $formatted[] = $this->formatShare($share); |
|
| 556 | + } catch (NotFoundException $e) { |
|
| 557 | + //Ignore this share |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return new DataResponse($formatted); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * The getShares function. |
|
| 566 | + * |
|
| 567 | + * @NoAdminRequired |
|
| 568 | + * |
|
| 569 | + * @param string $shared_with_me |
|
| 570 | + * @param string $reshares |
|
| 571 | + * @param string $subfiles |
|
| 572 | + * @param string $path |
|
| 573 | + * |
|
| 574 | + * - Get shares by the current user |
|
| 575 | + * - Get shares by the current user and reshares (?reshares=true) |
|
| 576 | + * - Get shares with the current user (?shared_with_me=true) |
|
| 577 | + * - Get shares for a specific path (?path=...) |
|
| 578 | + * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 579 | + * |
|
| 580 | + * @return DataResponse |
|
| 581 | + * @throws OCSNotFoundException |
|
| 582 | + */ |
|
| 583 | + public function getShares( |
|
| 584 | + $shared_with_me = 'false', |
|
| 585 | + $reshares = 'false', |
|
| 586 | + $subfiles = 'false', |
|
| 587 | + $path = null, |
|
| 588 | + $include_tags = 'false' |
|
| 589 | + ) { |
|
| 590 | + |
|
| 591 | + if ($path !== null) { |
|
| 592 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 593 | + try { |
|
| 594 | + $path = $userFolder->get($path); |
|
| 595 | + $this->lock($path); |
|
| 596 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 597 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 598 | + } catch (LockedException $e) { |
|
| 599 | + throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + if ($shared_with_me === 'true') { |
|
| 604 | + $result = $this->getSharedWithMe($path, $include_tags); |
|
| 605 | + return $result; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + if ($subfiles === 'true') { |
|
| 609 | + $result = $this->getSharesInDir($path); |
|
| 610 | + return $result; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + if ($reshares === 'true') { |
|
| 614 | + $reshares = true; |
|
| 615 | + } else { |
|
| 616 | + $reshares = false; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + // Get all shares |
|
| 620 | + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 621 | + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 622 | + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 623 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 624 | + $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 625 | + } else { |
|
| 626 | + $mailShares = []; |
|
| 627 | + } |
|
| 628 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 629 | + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 630 | + } else { |
|
| 631 | + $circleShares = []; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 635 | + |
|
| 636 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 637 | + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 638 | + $shares = array_merge($shares, $federatedShares); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + $formatted = []; |
|
| 642 | + foreach ($shares as $share) { |
|
| 643 | + try { |
|
| 644 | + $formatted[] = $this->formatShare($share, $path); |
|
| 645 | + } catch (NotFoundException $e) { |
|
| 646 | + //Ignore share |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + if ($include_tags) { |
|
| 651 | + $formatted = Helper::populateTags($formatted, 'file_source'); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return new DataResponse($formatted); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * @NoAdminRequired |
|
| 659 | + * |
|
| 660 | + * @param int $id |
|
| 661 | + * @param int $permissions |
|
| 662 | + * @param string $password |
|
| 663 | + * @param string $publicUpload |
|
| 664 | + * @param string $expireDate |
|
| 665 | + * @return DataResponse |
|
| 666 | + * @throws OCSNotFoundException |
|
| 667 | + * @throws OCSBadRequestException |
|
| 668 | + * @throws OCSForbiddenException |
|
| 669 | + */ |
|
| 670 | + public function updateShare( |
|
| 671 | + $id, |
|
| 672 | + $permissions = null, |
|
| 673 | + $password = null, |
|
| 674 | + $publicUpload = null, |
|
| 675 | + $expireDate = null |
|
| 676 | + ) { |
|
| 677 | + try { |
|
| 678 | + $share = $this->getShareById($id); |
|
| 679 | + } catch (ShareNotFound $e) { |
|
| 680 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + $this->lock($share->getNode()); |
|
| 684 | + |
|
| 685 | + if (!$this->canAccessShare($share, false)) { |
|
| 686 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 690 | + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /* |
|
| 694 | 694 | * expirationdate, password and publicUpload only make sense for link shares |
| 695 | 695 | */ |
| 696 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 697 | - |
|
| 698 | - $newPermissions = null; |
|
| 699 | - if ($publicUpload === 'true') { |
|
| 700 | - $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
| 701 | - } else if ($publicUpload === 'false') { |
|
| 702 | - $newPermissions = \OCP\Constants::PERMISSION_READ; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - if ($permissions !== null) { |
|
| 706 | - $newPermissions = (int)$permissions; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($newPermissions !== null && |
|
| 710 | - !in_array($newPermissions, [ |
|
| 711 | - \OCP\Constants::PERMISSION_READ, |
|
| 712 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy |
|
| 713 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct |
|
| 714 | - \OCP\Constants::PERMISSION_CREATE, // hidden file list |
|
| 715 | - \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 716 | - ]) |
|
| 717 | - ) { |
|
| 718 | - throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - if ( |
|
| 722 | - // legacy |
|
| 723 | - $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) || |
|
| 724 | - // correct |
|
| 725 | - $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE) |
|
| 726 | - ) { |
|
| 727 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 728 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 732 | - throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - // normalize to correct public upload permissions |
|
| 736 | - $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if ($newPermissions !== null) { |
|
| 740 | - $share->setPermissions($newPermissions); |
|
| 741 | - $permissions = $newPermissions; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - if ($expireDate === '') { |
|
| 745 | - $share->setExpirationDate(null); |
|
| 746 | - } else if ($expireDate !== null) { |
|
| 747 | - try { |
|
| 748 | - $expireDate = $this->parseDate($expireDate); |
|
| 749 | - } catch (\Exception $e) { |
|
| 750 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 751 | - } |
|
| 752 | - $share->setExpirationDate($expireDate); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - if ($password === '') { |
|
| 756 | - $share->setPassword(null); |
|
| 757 | - } else if ($password !== null) { |
|
| 758 | - $share->setPassword($password); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - } else { |
|
| 762 | - if ($permissions !== null) { |
|
| 763 | - $permissions = (int)$permissions; |
|
| 764 | - $share->setPermissions($permissions); |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 768 | - if ($password === '') { |
|
| 769 | - $share->setPassword(null); |
|
| 770 | - } else if ($password !== null) { |
|
| 771 | - $share->setPassword($password); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if ($expireDate === '') { |
|
| 776 | - $share->setExpirationDate(null); |
|
| 777 | - } else if ($expireDate !== null) { |
|
| 778 | - try { |
|
| 779 | - $expireDate = $this->parseDate($expireDate); |
|
| 780 | - } catch (\Exception $e) { |
|
| 781 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 782 | - } |
|
| 783 | - $share->setExpirationDate($expireDate); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 789 | - /* Check if this is an incomming share */ |
|
| 790 | - $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 791 | - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 792 | - |
|
| 793 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 794 | - if (!empty($incomingShares)) { |
|
| 795 | - $maxPermissions = 0; |
|
| 796 | - foreach ($incomingShares as $incomingShare) { |
|
| 797 | - $maxPermissions |= $incomingShare->getPermissions(); |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - if ($share->getPermissions() & ~$maxPermissions) { |
|
| 801 | - throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - try { |
|
| 808 | - $share = $this->shareManager->updateShare($share); |
|
| 809 | - } catch (\Exception $e) { |
|
| 810 | - throw new OCSBadRequestException($e->getMessage()); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - return new DataResponse($this->formatShare($share)); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * @param \OCP\Share\IShare $share |
|
| 818 | - * @return bool |
|
| 819 | - */ |
|
| 820 | - protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 821 | - // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 822 | - if ($share->getPermissions() === 0) { |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - // Owner of the file and the sharer of the file can always get share |
|
| 827 | - if ($share->getShareOwner() === $this->currentUser || |
|
| 828 | - $share->getSharedBy() === $this->currentUser |
|
| 829 | - ) { |
|
| 830 | - return true; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - // If the share is shared with you (or a group you are a member of) |
|
| 834 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 835 | - $share->getSharedWith() === $this->currentUser |
|
| 836 | - ) { |
|
| 837 | - return true; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 841 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 842 | - $user = $this->userManager->get($this->currentUser); |
|
| 843 | - if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 844 | - return true; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 849 | - // TODO: have a sanity check like above? |
|
| 850 | - return true; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - return false; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * Make sure that the passed date is valid ISO 8601 |
|
| 858 | - * So YYYY-MM-DD |
|
| 859 | - * If not throw an exception |
|
| 860 | - * |
|
| 861 | - * @param string $expireDate |
|
| 862 | - * |
|
| 863 | - * @throws \Exception |
|
| 864 | - * @return \DateTime |
|
| 865 | - */ |
|
| 866 | - private function parseDate($expireDate) { |
|
| 867 | - try { |
|
| 868 | - $date = new \DateTime($expireDate); |
|
| 869 | - } catch (\Exception $e) { |
|
| 870 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - if ($date === false) { |
|
| 874 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - $date->setTime(0, 0, 0); |
|
| 878 | - |
|
| 879 | - return $date; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Since we have multiple providers but the OCS Share API v1 does |
|
| 884 | - * not support this we need to check all backends. |
|
| 885 | - * |
|
| 886 | - * @param string $id |
|
| 887 | - * @return \OCP\Share\IShare |
|
| 888 | - * @throws ShareNotFound |
|
| 889 | - */ |
|
| 890 | - private function getShareById($id) { |
|
| 891 | - $share = null; |
|
| 892 | - |
|
| 893 | - // First check if it is an internal share. |
|
| 894 | - try { |
|
| 895 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 896 | - return $share; |
|
| 897 | - } catch (ShareNotFound $e) { |
|
| 898 | - // Do nothing, just try the other share type |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - try { |
|
| 903 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 904 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 905 | - return $share; |
|
| 906 | - } |
|
| 907 | - } catch (ShareNotFound $e) { |
|
| 908 | - // Do nothing, just try the other share type |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - try { |
|
| 912 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 913 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 914 | - return $share; |
|
| 915 | - } |
|
| 916 | - } catch (ShareNotFound $e) { |
|
| 917 | - // Do nothing, just try the other share type |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 921 | - throw new ShareNotFound(); |
|
| 922 | - } |
|
| 923 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 924 | - |
|
| 925 | - return $share; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Lock a Node |
|
| 930 | - * |
|
| 931 | - * @param \OCP\Files\Node $node |
|
| 932 | - */ |
|
| 933 | - private function lock(\OCP\Files\Node $node) { |
|
| 934 | - $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 935 | - $this->lockedNode = $node; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Cleanup the remaining locks |
|
| 940 | - */ |
|
| 941 | - public function cleanup() { |
|
| 942 | - if ($this->lockedNode !== null) { |
|
| 943 | - $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 944 | - } |
|
| 945 | - } |
|
| 696 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 697 | + |
|
| 698 | + $newPermissions = null; |
|
| 699 | + if ($publicUpload === 'true') { |
|
| 700 | + $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
| 701 | + } else if ($publicUpload === 'false') { |
|
| 702 | + $newPermissions = \OCP\Constants::PERMISSION_READ; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + if ($permissions !== null) { |
|
| 706 | + $newPermissions = (int)$permissions; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($newPermissions !== null && |
|
| 710 | + !in_array($newPermissions, [ |
|
| 711 | + \OCP\Constants::PERMISSION_READ, |
|
| 712 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE, // legacy |
|
| 713 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE, // correct |
|
| 714 | + \OCP\Constants::PERMISSION_CREATE, // hidden file list |
|
| 715 | + \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 716 | + ]) |
|
| 717 | + ) { |
|
| 718 | + throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + if ( |
|
| 722 | + // legacy |
|
| 723 | + $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE) || |
|
| 724 | + // correct |
|
| 725 | + $newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE) |
|
| 726 | + ) { |
|
| 727 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 728 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 732 | + throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + // normalize to correct public upload permissions |
|
| 736 | + $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if ($newPermissions !== null) { |
|
| 740 | + $share->setPermissions($newPermissions); |
|
| 741 | + $permissions = $newPermissions; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + if ($expireDate === '') { |
|
| 745 | + $share->setExpirationDate(null); |
|
| 746 | + } else if ($expireDate !== null) { |
|
| 747 | + try { |
|
| 748 | + $expireDate = $this->parseDate($expireDate); |
|
| 749 | + } catch (\Exception $e) { |
|
| 750 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 751 | + } |
|
| 752 | + $share->setExpirationDate($expireDate); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + if ($password === '') { |
|
| 756 | + $share->setPassword(null); |
|
| 757 | + } else if ($password !== null) { |
|
| 758 | + $share->setPassword($password); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + } else { |
|
| 762 | + if ($permissions !== null) { |
|
| 763 | + $permissions = (int)$permissions; |
|
| 764 | + $share->setPermissions($permissions); |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 768 | + if ($password === '') { |
|
| 769 | + $share->setPassword(null); |
|
| 770 | + } else if ($password !== null) { |
|
| 771 | + $share->setPassword($password); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if ($expireDate === '') { |
|
| 776 | + $share->setExpirationDate(null); |
|
| 777 | + } else if ($expireDate !== null) { |
|
| 778 | + try { |
|
| 779 | + $expireDate = $this->parseDate($expireDate); |
|
| 780 | + } catch (\Exception $e) { |
|
| 781 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 782 | + } |
|
| 783 | + $share->setExpirationDate($expireDate); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 789 | + /* Check if this is an incomming share */ |
|
| 790 | + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 791 | + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 792 | + |
|
| 793 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 794 | + if (!empty($incomingShares)) { |
|
| 795 | + $maxPermissions = 0; |
|
| 796 | + foreach ($incomingShares as $incomingShare) { |
|
| 797 | + $maxPermissions |= $incomingShare->getPermissions(); |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + if ($share->getPermissions() & ~$maxPermissions) { |
|
| 801 | + throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + try { |
|
| 808 | + $share = $this->shareManager->updateShare($share); |
|
| 809 | + } catch (\Exception $e) { |
|
| 810 | + throw new OCSBadRequestException($e->getMessage()); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + return new DataResponse($this->formatShare($share)); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * @param \OCP\Share\IShare $share |
|
| 818 | + * @return bool |
|
| 819 | + */ |
|
| 820 | + protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 821 | + // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 822 | + if ($share->getPermissions() === 0) { |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + // Owner of the file and the sharer of the file can always get share |
|
| 827 | + if ($share->getShareOwner() === $this->currentUser || |
|
| 828 | + $share->getSharedBy() === $this->currentUser |
|
| 829 | + ) { |
|
| 830 | + return true; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + // If the share is shared with you (or a group you are a member of) |
|
| 834 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 835 | + $share->getSharedWith() === $this->currentUser |
|
| 836 | + ) { |
|
| 837 | + return true; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 841 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 842 | + $user = $this->userManager->get($this->currentUser); |
|
| 843 | + if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 844 | + return true; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 849 | + // TODO: have a sanity check like above? |
|
| 850 | + return true; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + return false; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * Make sure that the passed date is valid ISO 8601 |
|
| 858 | + * So YYYY-MM-DD |
|
| 859 | + * If not throw an exception |
|
| 860 | + * |
|
| 861 | + * @param string $expireDate |
|
| 862 | + * |
|
| 863 | + * @throws \Exception |
|
| 864 | + * @return \DateTime |
|
| 865 | + */ |
|
| 866 | + private function parseDate($expireDate) { |
|
| 867 | + try { |
|
| 868 | + $date = new \DateTime($expireDate); |
|
| 869 | + } catch (\Exception $e) { |
|
| 870 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + if ($date === false) { |
|
| 874 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + $date->setTime(0, 0, 0); |
|
| 878 | + |
|
| 879 | + return $date; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Since we have multiple providers but the OCS Share API v1 does |
|
| 884 | + * not support this we need to check all backends. |
|
| 885 | + * |
|
| 886 | + * @param string $id |
|
| 887 | + * @return \OCP\Share\IShare |
|
| 888 | + * @throws ShareNotFound |
|
| 889 | + */ |
|
| 890 | + private function getShareById($id) { |
|
| 891 | + $share = null; |
|
| 892 | + |
|
| 893 | + // First check if it is an internal share. |
|
| 894 | + try { |
|
| 895 | + $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 896 | + return $share; |
|
| 897 | + } catch (ShareNotFound $e) { |
|
| 898 | + // Do nothing, just try the other share type |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + try { |
|
| 903 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 904 | + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 905 | + return $share; |
|
| 906 | + } |
|
| 907 | + } catch (ShareNotFound $e) { |
|
| 908 | + // Do nothing, just try the other share type |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + try { |
|
| 912 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 913 | + $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 914 | + return $share; |
|
| 915 | + } |
|
| 916 | + } catch (ShareNotFound $e) { |
|
| 917 | + // Do nothing, just try the other share type |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 921 | + throw new ShareNotFound(); |
|
| 922 | + } |
|
| 923 | + $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 924 | + |
|
| 925 | + return $share; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Lock a Node |
|
| 930 | + * |
|
| 931 | + * @param \OCP\Files\Node $node |
|
| 932 | + */ |
|
| 933 | + private function lock(\OCP\Files\Node $node) { |
|
| 934 | + $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 935 | + $this->lockedNode = $node; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Cleanup the remaining locks |
|
| 940 | + */ |
|
| 941 | + public function cleanup() { |
|
| 942 | + if ($this->lockedNode !== null) { |
|
| 943 | + $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | 946 | } |