@@ -25,524 +25,524 @@ |
||
| 25 | 25 | * @since 9.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface IManager { |
| 28 | - /** |
|
| 29 | - * Create a Share |
|
| 30 | - * |
|
| 31 | - * @param IShare $share |
|
| 32 | - * @return IShare The share object |
|
| 33 | - * @throws \Exception |
|
| 34 | - * @since 9.0.0 |
|
| 35 | - */ |
|
| 36 | - public function createShare(IShare $share); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Update a share. |
|
| 40 | - * The target of the share can't be changed this way: use moveShare |
|
| 41 | - * The share can't be removed this way (permission 0): use deleteShare |
|
| 42 | - * The state can't be changed this way: use acceptShare |
|
| 43 | - * |
|
| 44 | - * @param IShare $share |
|
| 45 | - * @param bool $onlyValid Only updates valid shares, invalid shares will be deleted automatically and are not updated |
|
| 46 | - * @return IShare The share object |
|
| 47 | - * @throws \InvalidArgumentException |
|
| 48 | - * @since 9.0.0 |
|
| 49 | - */ |
|
| 50 | - public function updateShare(IShare $share, bool $onlyValid = true); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Accept a share. |
|
| 54 | - * |
|
| 55 | - * @param IShare $share |
|
| 56 | - * @param string $recipientId |
|
| 57 | - * @return IShare The share object |
|
| 58 | - * @throws \InvalidArgumentException |
|
| 59 | - * @since 18.0.0 |
|
| 60 | - */ |
|
| 61 | - public function acceptShare(IShare $share, string $recipientId): IShare; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Delete a share |
|
| 65 | - * |
|
| 66 | - * @param IShare $share |
|
| 67 | - * @throws ShareNotFound |
|
| 68 | - * @throws \InvalidArgumentException |
|
| 69 | - * @since 9.0.0 |
|
| 70 | - */ |
|
| 71 | - public function deleteShare(IShare $share); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Unshare a file as the recipient. |
|
| 75 | - * This can be different from a regular delete for example when one of |
|
| 76 | - * the users in a groups deletes that share. But the provider should |
|
| 77 | - * handle this. |
|
| 78 | - * |
|
| 79 | - * @param IShare $share |
|
| 80 | - * @param string $recipientId |
|
| 81 | - * @since 9.0.0 |
|
| 82 | - */ |
|
| 83 | - public function deleteFromSelf(IShare $share, $recipientId); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Restore the share when it has been deleted |
|
| 87 | - * Certain share types can be restored when they have been deleted |
|
| 88 | - * but the provider should properly handle this\ |
|
| 89 | - * |
|
| 90 | - * @param IShare $share The share to restore |
|
| 91 | - * @param string $recipientId The user to restore the share for |
|
| 92 | - * @return IShare The restored share object |
|
| 93 | - * @throws GenericShareException In case restoring the share failed |
|
| 94 | - * |
|
| 95 | - * @since 14.0.0 |
|
| 96 | - */ |
|
| 97 | - public function restoreShare(IShare $share, string $recipientId): IShare; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Move the share as a recipient of the share. |
|
| 101 | - * This is updating the share target. So where the recipient has the share mounted. |
|
| 102 | - * |
|
| 103 | - * @param IShare $share |
|
| 104 | - * @param string $recipientId |
|
| 105 | - * @return IShare |
|
| 106 | - * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
| 107 | - * @since 9.0.0 |
|
| 108 | - */ |
|
| 109 | - public function moveShare(IShare $share, $recipientId); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Get all shares shared by (initiated) by the provided user in a folder. |
|
| 113 | - * |
|
| 114 | - * @param string $userId |
|
| 115 | - * @param Folder $node |
|
| 116 | - * @param bool $reshares |
|
| 117 | - * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders. |
|
| 118 | - * @return IShare[][] [$fileId => IShare[], ...] |
|
| 119 | - * @since 11.0.0 |
|
| 120 | - */ |
|
| 121 | - public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true); |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get shares shared by (initiated) by the provided user. |
|
| 125 | - * |
|
| 126 | - * @param string $userId |
|
| 127 | - * @param int $shareType |
|
| 128 | - * @param Node|null $path |
|
| 129 | - * @param bool $reshares |
|
| 130 | - * @param int $limit The maximum number of returned results, -1 for all results |
|
| 131 | - * @param int $offset |
|
| 132 | - * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned |
|
| 133 | - * @return IShare[] |
|
| 134 | - * @since 9.0.0 |
|
| 135 | - */ |
|
| 136 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true); |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Get shares shared with $user. |
|
| 140 | - * Filter by $node if provided |
|
| 141 | - * |
|
| 142 | - * @param string $userId |
|
| 143 | - * @param int $shareType |
|
| 144 | - * @param Node|null $node |
|
| 145 | - * @param int $limit The maximum number of shares returned, -1 for all |
|
| 146 | - * @param int $offset |
|
| 147 | - * @return IShare[] |
|
| 148 | - * @since 9.0.0 |
|
| 149 | - */ |
|
| 150 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Get deleted shares shared with $user. |
|
| 154 | - * Filter by $node if provided |
|
| 155 | - * |
|
| 156 | - * @param string $userId |
|
| 157 | - * @param int $shareType |
|
| 158 | - * @param Node|null $node |
|
| 159 | - * @param int $limit The maximum number of shares returned, -1 for all |
|
| 160 | - * @param int $offset |
|
| 161 | - * @return IShare[] |
|
| 162 | - * @since 14.0.0 |
|
| 163 | - */ |
|
| 164 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Retrieve a share by the share id. |
|
| 168 | - * If the recipient is set make sure to retrieve the file for that user. |
|
| 169 | - * This makes sure that if a user has moved/deleted a group share this |
|
| 170 | - * is reflected. |
|
| 171 | - * |
|
| 172 | - * @param string $id |
|
| 173 | - * @param string|null $recipient userID of the recipient |
|
| 174 | - * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned |
|
| 175 | - * @return IShare |
|
| 176 | - * @throws ShareNotFound |
|
| 177 | - * @since 9.0.0 |
|
| 178 | - */ |
|
| 179 | - public function getShareById($id, $recipient = null, bool $onlyValid = true); |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the share by token possible with password |
|
| 183 | - * |
|
| 184 | - * @param string $token |
|
| 185 | - * @return IShare |
|
| 186 | - * @throws ShareNotFound |
|
| 187 | - * @since 9.0.0 |
|
| 188 | - */ |
|
| 189 | - public function getShareByToken($token); |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Verify the password of a public share |
|
| 193 | - * |
|
| 194 | - * @param IShare $share |
|
| 195 | - * @param ?string $password |
|
| 196 | - * @return bool |
|
| 197 | - * @since 9.0.0 |
|
| 198 | - */ |
|
| 199 | - public function checkPassword(IShare $share, $password); |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * The user with UID is deleted. |
|
| 203 | - * All share providers have to cleanup the shares with this user as well |
|
| 204 | - * as shares owned by this user. |
|
| 205 | - * Shares only initiated by this user are fine. |
|
| 206 | - * |
|
| 207 | - * @param string $uid |
|
| 208 | - * @since 9.1.0 |
|
| 209 | - */ |
|
| 210 | - public function userDeleted($uid); |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * The group with $gid is deleted |
|
| 214 | - * We need to clear up all shares to this group |
|
| 215 | - * |
|
| 216 | - * @param string $gid |
|
| 217 | - * @since 9.1.0 |
|
| 218 | - */ |
|
| 219 | - public function groupDeleted($gid); |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * The user $uid is deleted from the group $gid |
|
| 223 | - * All user specific group shares have to be removed |
|
| 224 | - * |
|
| 225 | - * @param string $uid |
|
| 226 | - * @param string $gid |
|
| 227 | - * @since 9.1.0 |
|
| 228 | - */ |
|
| 229 | - public function userDeletedFromGroup($uid, $gid); |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Get access list to a path. This means |
|
| 233 | - * all the users that can access a given path. |
|
| 234 | - * |
|
| 235 | - * Consider: |
|
| 236 | - * -root |
|
| 237 | - * |-folder1 (23) |
|
| 238 | - * |-folder2 (32) |
|
| 239 | - * |-fileA (42) |
|
| 240 | - * |
|
| 241 | - * fileA is shared with user1 and user1@server1 and email1@maildomain1 |
|
| 242 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
| 243 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 244 | - * and email2@maildomain2 |
|
| 245 | - * |
|
| 246 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 247 | - * [ |
|
| 248 | - * users => [ |
|
| 249 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 250 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 251 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 252 | - * ], |
|
| 253 | - * remote => [ |
|
| 254 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 255 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 256 | - * ], |
|
| 257 | - * public => bool |
|
| 258 | - * mail => [ |
|
| 259 | - * 'email1@maildomain1' => ['node_id' => 42, 'token' => 'aBcDeFg'], |
|
| 260 | - * 'email2@maildomain2' => ['node_id' => 23, 'token' => 'hIjKlMn'], |
|
| 261 | - * ] |
|
| 262 | - * |
|
| 263 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 264 | - * [ |
|
| 265 | - * users => ['user1', 'user2', 'user4'], |
|
| 266 | - * remote => bool, |
|
| 267 | - * public => bool |
|
| 268 | - * mail => ['email1@maildomain1', 'email2@maildomain2'] |
|
| 269 | - * ] |
|
| 270 | - * |
|
| 271 | - * This is required for encryption/activity |
|
| 272 | - * |
|
| 273 | - * @param \OCP\Files\Node $path |
|
| 274 | - * @param bool $recursive Should we check all parent folders as well |
|
| 275 | - * @param bool $currentAccess Should the user have currently access to the file |
|
| 276 | - * @return array |
|
| 277 | - * @since 12 |
|
| 278 | - */ |
|
| 279 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Instantiates a new share object. This is to be passed to |
|
| 283 | - * createShare. |
|
| 284 | - * |
|
| 285 | - * @return IShare |
|
| 286 | - * @since 9.0.0 |
|
| 287 | - */ |
|
| 288 | - public function newShare(); |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Is the share API enabled |
|
| 292 | - * |
|
| 293 | - * @return bool |
|
| 294 | - * @since 9.0.0 |
|
| 295 | - */ |
|
| 296 | - public function shareApiEnabled(); |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Is public link sharing enabled |
|
| 300 | - * |
|
| 301 | - * @return bool |
|
| 302 | - * @since 9.0.0 |
|
| 303 | - */ |
|
| 304 | - public function shareApiAllowLinks(); |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Is password on public link required |
|
| 308 | - * |
|
| 309 | - * @param bool $checkGroupMembership Check group membership exclusion |
|
| 310 | - * @return bool |
|
| 311 | - * @since 9.0.0 |
|
| 312 | - * @since 24.0.0 Added optional $checkGroupMembership parameter |
|
| 313 | - */ |
|
| 314 | - public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true); |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Is default expire date enabled |
|
| 318 | - * |
|
| 319 | - * @return bool |
|
| 320 | - * @since 9.0.0 |
|
| 321 | - */ |
|
| 322 | - public function shareApiLinkDefaultExpireDate(); |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Is default expire date enforced |
|
| 326 | - *` |
|
| 327 | - * @return bool |
|
| 328 | - * @since 9.0.0 |
|
| 329 | - */ |
|
| 330 | - public function shareApiLinkDefaultExpireDateEnforced(); |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Number of default expire days |
|
| 334 | - * |
|
| 335 | - * @return int |
|
| 336 | - * @since 9.0.0 |
|
| 337 | - */ |
|
| 338 | - public function shareApiLinkDefaultExpireDays(); |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Is default internal expire date enabled |
|
| 342 | - * |
|
| 343 | - * @return bool |
|
| 344 | - * @since 22.0.0 |
|
| 345 | - */ |
|
| 346 | - public function shareApiInternalDefaultExpireDate(): bool; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Is default remote expire date enabled |
|
| 350 | - * |
|
| 351 | - * @return bool |
|
| 352 | - * @since 22.0.0 |
|
| 353 | - */ |
|
| 354 | - public function shareApiRemoteDefaultExpireDate(): bool; |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Is default expire date enforced |
|
| 358 | - * |
|
| 359 | - * @return bool |
|
| 360 | - * @since 22.0.0 |
|
| 361 | - */ |
|
| 362 | - public function shareApiInternalDefaultExpireDateEnforced(): bool; |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Is default expire date enforced for remote shares |
|
| 366 | - * |
|
| 367 | - * @return bool |
|
| 368 | - * @since 22.0.0 |
|
| 369 | - */ |
|
| 370 | - public function shareApiRemoteDefaultExpireDateEnforced(): bool; |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Number of default expire days |
|
| 374 | - * |
|
| 375 | - * @return int |
|
| 376 | - * @since 22.0.0 |
|
| 377 | - */ |
|
| 378 | - public function shareApiInternalDefaultExpireDays(): int; |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Number of default expire days for remote shares |
|
| 382 | - * |
|
| 383 | - * @return int |
|
| 384 | - * @since 22.0.0 |
|
| 385 | - */ |
|
| 386 | - public function shareApiRemoteDefaultExpireDays(): int; |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Allow public upload on link shares |
|
| 390 | - * |
|
| 391 | - * @return bool |
|
| 392 | - * @since 9.0.0 |
|
| 393 | - */ |
|
| 394 | - public function shareApiLinkAllowPublicUpload(); |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * check if user can only share with group members |
|
| 398 | - * @return bool |
|
| 399 | - * @since 9.0.0 |
|
| 400 | - */ |
|
| 401 | - public function shareWithGroupMembersOnly(); |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * If shareWithGroupMembersOnly is enabled, return an optional |
|
| 405 | - * list of groups that must be excluded from the principle of |
|
| 406 | - * belonging to the same group. |
|
| 407 | - * @return array |
|
| 408 | - * @since 27.0.0 |
|
| 409 | - */ |
|
| 410 | - public function shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Check if users can share with groups |
|
| 414 | - * @return bool |
|
| 415 | - * @since 9.0.1 |
|
| 416 | - */ |
|
| 417 | - public function allowGroupSharing(); |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Check if user enumeration is allowed |
|
| 421 | - * |
|
| 422 | - * @return bool |
|
| 423 | - * @since 19.0.0 |
|
| 424 | - */ |
|
| 425 | - public function allowEnumeration(): bool; |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Check if user enumeration is limited to the users groups |
|
| 429 | - * |
|
| 430 | - * @return bool |
|
| 431 | - * @since 19.0.0 |
|
| 432 | - */ |
|
| 433 | - public function limitEnumerationToGroups(): bool; |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Check if user enumeration is limited to the phonebook matches |
|
| 437 | - * |
|
| 438 | - * @return bool |
|
| 439 | - * @since 21.0.1 |
|
| 440 | - */ |
|
| 441 | - public function limitEnumerationToPhone(): bool; |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Check if user enumeration is allowed to return on full match |
|
| 445 | - * |
|
| 446 | - * @return bool |
|
| 447 | - * @since 21.0.1 |
|
| 448 | - */ |
|
| 449 | - public function allowEnumerationFullMatch(): bool; |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Check if the search should match the email |
|
| 453 | - * |
|
| 454 | - * @return bool |
|
| 455 | - * @since 25.0.0 |
|
| 456 | - */ |
|
| 457 | - public function matchEmail(): bool; |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Check if the search should ignore the second in parentheses display name if there is any |
|
| 461 | - * |
|
| 462 | - * @return bool |
|
| 463 | - * @since 25.0.0 |
|
| 464 | - */ |
|
| 465 | - public function ignoreSecondDisplayName(): bool; |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Check if custom tokens are allowed |
|
| 470 | - * |
|
| 471 | - * @since 31.0.0 |
|
| 472 | - */ |
|
| 473 | - public function allowCustomTokens(): bool; |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Check if the current user can view the share |
|
| 477 | - * even if the download is disabled. |
|
| 478 | - * |
|
| 479 | - * @since 32.0.0 |
|
| 480 | - */ |
|
| 481 | - public function allowViewWithoutDownload(): bool; |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Check if the current user can enumerate the target user |
|
| 485 | - * |
|
| 486 | - * @param IUser|null $currentUser |
|
| 487 | - * @param IUser $targetUser |
|
| 488 | - * @return bool |
|
| 489 | - * @since 23.0.0 |
|
| 490 | - */ |
|
| 491 | - public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool; |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Check if sharing is disabled for the given user |
|
| 495 | - * |
|
| 496 | - * @since 9.0.0 |
|
| 497 | - */ |
|
| 498 | - public function sharingDisabledForUser(?string $userId): bool; |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Check if outgoing server2server shares are allowed |
|
| 502 | - * @return bool |
|
| 503 | - * @since 9.0.0 |
|
| 504 | - */ |
|
| 505 | - public function outgoingServer2ServerSharesAllowed(); |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Check if outgoing server2server shares are allowed |
|
| 509 | - * @return bool |
|
| 510 | - * @since 14.0.0 |
|
| 511 | - */ |
|
| 512 | - public function outgoingServer2ServerGroupSharesAllowed(); |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Check if a given share provider exists |
|
| 517 | - * @param int $shareType |
|
| 518 | - * @return bool |
|
| 519 | - * @since 11.0.0 |
|
| 520 | - */ |
|
| 521 | - public function shareProviderExists($shareType); |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * @param string $shareProviderClass |
|
| 525 | - * @since 21.0.0 |
|
| 526 | - */ |
|
| 527 | - public function registerShareProvider(string $shareProviderClass): void; |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * @Internal |
|
| 531 | - * |
|
| 532 | - * Get all the shares as iterable to reduce memory overhead |
|
| 533 | - * Note, since this opens up database cursors the iterable should |
|
| 534 | - * be fully itterated. |
|
| 535 | - * |
|
| 536 | - * @return iterable |
|
| 537 | - * @since 18.0.0 |
|
| 538 | - */ |
|
| 539 | - public function getAllShares(): iterable; |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Generate a unique share token |
|
| 543 | - * |
|
| 544 | - * @throws ShareTokenException Failed to generate a unique token |
|
| 545 | - * @since 31.0.0 |
|
| 546 | - */ |
|
| 547 | - public function generateToken(): string; |
|
| 28 | + /** |
|
| 29 | + * Create a Share |
|
| 30 | + * |
|
| 31 | + * @param IShare $share |
|
| 32 | + * @return IShare The share object |
|
| 33 | + * @throws \Exception |
|
| 34 | + * @since 9.0.0 |
|
| 35 | + */ |
|
| 36 | + public function createShare(IShare $share); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Update a share. |
|
| 40 | + * The target of the share can't be changed this way: use moveShare |
|
| 41 | + * The share can't be removed this way (permission 0): use deleteShare |
|
| 42 | + * The state can't be changed this way: use acceptShare |
|
| 43 | + * |
|
| 44 | + * @param IShare $share |
|
| 45 | + * @param bool $onlyValid Only updates valid shares, invalid shares will be deleted automatically and are not updated |
|
| 46 | + * @return IShare The share object |
|
| 47 | + * @throws \InvalidArgumentException |
|
| 48 | + * @since 9.0.0 |
|
| 49 | + */ |
|
| 50 | + public function updateShare(IShare $share, bool $onlyValid = true); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Accept a share. |
|
| 54 | + * |
|
| 55 | + * @param IShare $share |
|
| 56 | + * @param string $recipientId |
|
| 57 | + * @return IShare The share object |
|
| 58 | + * @throws \InvalidArgumentException |
|
| 59 | + * @since 18.0.0 |
|
| 60 | + */ |
|
| 61 | + public function acceptShare(IShare $share, string $recipientId): IShare; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Delete a share |
|
| 65 | + * |
|
| 66 | + * @param IShare $share |
|
| 67 | + * @throws ShareNotFound |
|
| 68 | + * @throws \InvalidArgumentException |
|
| 69 | + * @since 9.0.0 |
|
| 70 | + */ |
|
| 71 | + public function deleteShare(IShare $share); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Unshare a file as the recipient. |
|
| 75 | + * This can be different from a regular delete for example when one of |
|
| 76 | + * the users in a groups deletes that share. But the provider should |
|
| 77 | + * handle this. |
|
| 78 | + * |
|
| 79 | + * @param IShare $share |
|
| 80 | + * @param string $recipientId |
|
| 81 | + * @since 9.0.0 |
|
| 82 | + */ |
|
| 83 | + public function deleteFromSelf(IShare $share, $recipientId); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Restore the share when it has been deleted |
|
| 87 | + * Certain share types can be restored when they have been deleted |
|
| 88 | + * but the provider should properly handle this\ |
|
| 89 | + * |
|
| 90 | + * @param IShare $share The share to restore |
|
| 91 | + * @param string $recipientId The user to restore the share for |
|
| 92 | + * @return IShare The restored share object |
|
| 93 | + * @throws GenericShareException In case restoring the share failed |
|
| 94 | + * |
|
| 95 | + * @since 14.0.0 |
|
| 96 | + */ |
|
| 97 | + public function restoreShare(IShare $share, string $recipientId): IShare; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Move the share as a recipient of the share. |
|
| 101 | + * This is updating the share target. So where the recipient has the share mounted. |
|
| 102 | + * |
|
| 103 | + * @param IShare $share |
|
| 104 | + * @param string $recipientId |
|
| 105 | + * @return IShare |
|
| 106 | + * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match |
|
| 107 | + * @since 9.0.0 |
|
| 108 | + */ |
|
| 109 | + public function moveShare(IShare $share, $recipientId); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Get all shares shared by (initiated) by the provided user in a folder. |
|
| 113 | + * |
|
| 114 | + * @param string $userId |
|
| 115 | + * @param Folder $node |
|
| 116 | + * @param bool $reshares |
|
| 117 | + * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders. |
|
| 118 | + * @return IShare[][] [$fileId => IShare[], ...] |
|
| 119 | + * @since 11.0.0 |
|
| 120 | + */ |
|
| 121 | + public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true); |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get shares shared by (initiated) by the provided user. |
|
| 125 | + * |
|
| 126 | + * @param string $userId |
|
| 127 | + * @param int $shareType |
|
| 128 | + * @param Node|null $path |
|
| 129 | + * @param bool $reshares |
|
| 130 | + * @param int $limit The maximum number of returned results, -1 for all results |
|
| 131 | + * @param int $offset |
|
| 132 | + * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned |
|
| 133 | + * @return IShare[] |
|
| 134 | + * @since 9.0.0 |
|
| 135 | + */ |
|
| 136 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true); |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Get shares shared with $user. |
|
| 140 | + * Filter by $node if provided |
|
| 141 | + * |
|
| 142 | + * @param string $userId |
|
| 143 | + * @param int $shareType |
|
| 144 | + * @param Node|null $node |
|
| 145 | + * @param int $limit The maximum number of shares returned, -1 for all |
|
| 146 | + * @param int $offset |
|
| 147 | + * @return IShare[] |
|
| 148 | + * @since 9.0.0 |
|
| 149 | + */ |
|
| 150 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Get deleted shares shared with $user. |
|
| 154 | + * Filter by $node if provided |
|
| 155 | + * |
|
| 156 | + * @param string $userId |
|
| 157 | + * @param int $shareType |
|
| 158 | + * @param Node|null $node |
|
| 159 | + * @param int $limit The maximum number of shares returned, -1 for all |
|
| 160 | + * @param int $offset |
|
| 161 | + * @return IShare[] |
|
| 162 | + * @since 14.0.0 |
|
| 163 | + */ |
|
| 164 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0); |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Retrieve a share by the share id. |
|
| 168 | + * If the recipient is set make sure to retrieve the file for that user. |
|
| 169 | + * This makes sure that if a user has moved/deleted a group share this |
|
| 170 | + * is reflected. |
|
| 171 | + * |
|
| 172 | + * @param string $id |
|
| 173 | + * @param string|null $recipient userID of the recipient |
|
| 174 | + * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned |
|
| 175 | + * @return IShare |
|
| 176 | + * @throws ShareNotFound |
|
| 177 | + * @since 9.0.0 |
|
| 178 | + */ |
|
| 179 | + public function getShareById($id, $recipient = null, bool $onlyValid = true); |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the share by token possible with password |
|
| 183 | + * |
|
| 184 | + * @param string $token |
|
| 185 | + * @return IShare |
|
| 186 | + * @throws ShareNotFound |
|
| 187 | + * @since 9.0.0 |
|
| 188 | + */ |
|
| 189 | + public function getShareByToken($token); |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Verify the password of a public share |
|
| 193 | + * |
|
| 194 | + * @param IShare $share |
|
| 195 | + * @param ?string $password |
|
| 196 | + * @return bool |
|
| 197 | + * @since 9.0.0 |
|
| 198 | + */ |
|
| 199 | + public function checkPassword(IShare $share, $password); |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * The user with UID is deleted. |
|
| 203 | + * All share providers have to cleanup the shares with this user as well |
|
| 204 | + * as shares owned by this user. |
|
| 205 | + * Shares only initiated by this user are fine. |
|
| 206 | + * |
|
| 207 | + * @param string $uid |
|
| 208 | + * @since 9.1.0 |
|
| 209 | + */ |
|
| 210 | + public function userDeleted($uid); |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * The group with $gid is deleted |
|
| 214 | + * We need to clear up all shares to this group |
|
| 215 | + * |
|
| 216 | + * @param string $gid |
|
| 217 | + * @since 9.1.0 |
|
| 218 | + */ |
|
| 219 | + public function groupDeleted($gid); |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * The user $uid is deleted from the group $gid |
|
| 223 | + * All user specific group shares have to be removed |
|
| 224 | + * |
|
| 225 | + * @param string $uid |
|
| 226 | + * @param string $gid |
|
| 227 | + * @since 9.1.0 |
|
| 228 | + */ |
|
| 229 | + public function userDeletedFromGroup($uid, $gid); |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Get access list to a path. This means |
|
| 233 | + * all the users that can access a given path. |
|
| 234 | + * |
|
| 235 | + * Consider: |
|
| 236 | + * -root |
|
| 237 | + * |-folder1 (23) |
|
| 238 | + * |-folder2 (32) |
|
| 239 | + * |-fileA (42) |
|
| 240 | + * |
|
| 241 | + * fileA is shared with user1 and user1@server1 and email1@maildomain1 |
|
| 242 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
| 243 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 244 | + * and email2@maildomain2 |
|
| 245 | + * |
|
| 246 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 247 | + * [ |
|
| 248 | + * users => [ |
|
| 249 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 250 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 251 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 252 | + * ], |
|
| 253 | + * remote => [ |
|
| 254 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 255 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 256 | + * ], |
|
| 257 | + * public => bool |
|
| 258 | + * mail => [ |
|
| 259 | + * 'email1@maildomain1' => ['node_id' => 42, 'token' => 'aBcDeFg'], |
|
| 260 | + * 'email2@maildomain2' => ['node_id' => 23, 'token' => 'hIjKlMn'], |
|
| 261 | + * ] |
|
| 262 | + * |
|
| 263 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 264 | + * [ |
|
| 265 | + * users => ['user1', 'user2', 'user4'], |
|
| 266 | + * remote => bool, |
|
| 267 | + * public => bool |
|
| 268 | + * mail => ['email1@maildomain1', 'email2@maildomain2'] |
|
| 269 | + * ] |
|
| 270 | + * |
|
| 271 | + * This is required for encryption/activity |
|
| 272 | + * |
|
| 273 | + * @param \OCP\Files\Node $path |
|
| 274 | + * @param bool $recursive Should we check all parent folders as well |
|
| 275 | + * @param bool $currentAccess Should the user have currently access to the file |
|
| 276 | + * @return array |
|
| 277 | + * @since 12 |
|
| 278 | + */ |
|
| 279 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false); |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Instantiates a new share object. This is to be passed to |
|
| 283 | + * createShare. |
|
| 284 | + * |
|
| 285 | + * @return IShare |
|
| 286 | + * @since 9.0.0 |
|
| 287 | + */ |
|
| 288 | + public function newShare(); |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Is the share API enabled |
|
| 292 | + * |
|
| 293 | + * @return bool |
|
| 294 | + * @since 9.0.0 |
|
| 295 | + */ |
|
| 296 | + public function shareApiEnabled(); |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Is public link sharing enabled |
|
| 300 | + * |
|
| 301 | + * @return bool |
|
| 302 | + * @since 9.0.0 |
|
| 303 | + */ |
|
| 304 | + public function shareApiAllowLinks(); |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Is password on public link required |
|
| 308 | + * |
|
| 309 | + * @param bool $checkGroupMembership Check group membership exclusion |
|
| 310 | + * @return bool |
|
| 311 | + * @since 9.0.0 |
|
| 312 | + * @since 24.0.0 Added optional $checkGroupMembership parameter |
|
| 313 | + */ |
|
| 314 | + public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true); |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Is default expire date enabled |
|
| 318 | + * |
|
| 319 | + * @return bool |
|
| 320 | + * @since 9.0.0 |
|
| 321 | + */ |
|
| 322 | + public function shareApiLinkDefaultExpireDate(); |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Is default expire date enforced |
|
| 326 | + *` |
|
| 327 | + * @return bool |
|
| 328 | + * @since 9.0.0 |
|
| 329 | + */ |
|
| 330 | + public function shareApiLinkDefaultExpireDateEnforced(); |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Number of default expire days |
|
| 334 | + * |
|
| 335 | + * @return int |
|
| 336 | + * @since 9.0.0 |
|
| 337 | + */ |
|
| 338 | + public function shareApiLinkDefaultExpireDays(); |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Is default internal expire date enabled |
|
| 342 | + * |
|
| 343 | + * @return bool |
|
| 344 | + * @since 22.0.0 |
|
| 345 | + */ |
|
| 346 | + public function shareApiInternalDefaultExpireDate(): bool; |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Is default remote expire date enabled |
|
| 350 | + * |
|
| 351 | + * @return bool |
|
| 352 | + * @since 22.0.0 |
|
| 353 | + */ |
|
| 354 | + public function shareApiRemoteDefaultExpireDate(): bool; |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Is default expire date enforced |
|
| 358 | + * |
|
| 359 | + * @return bool |
|
| 360 | + * @since 22.0.0 |
|
| 361 | + */ |
|
| 362 | + public function shareApiInternalDefaultExpireDateEnforced(): bool; |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Is default expire date enforced for remote shares |
|
| 366 | + * |
|
| 367 | + * @return bool |
|
| 368 | + * @since 22.0.0 |
|
| 369 | + */ |
|
| 370 | + public function shareApiRemoteDefaultExpireDateEnforced(): bool; |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Number of default expire days |
|
| 374 | + * |
|
| 375 | + * @return int |
|
| 376 | + * @since 22.0.0 |
|
| 377 | + */ |
|
| 378 | + public function shareApiInternalDefaultExpireDays(): int; |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Number of default expire days for remote shares |
|
| 382 | + * |
|
| 383 | + * @return int |
|
| 384 | + * @since 22.0.0 |
|
| 385 | + */ |
|
| 386 | + public function shareApiRemoteDefaultExpireDays(): int; |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Allow public upload on link shares |
|
| 390 | + * |
|
| 391 | + * @return bool |
|
| 392 | + * @since 9.0.0 |
|
| 393 | + */ |
|
| 394 | + public function shareApiLinkAllowPublicUpload(); |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * check if user can only share with group members |
|
| 398 | + * @return bool |
|
| 399 | + * @since 9.0.0 |
|
| 400 | + */ |
|
| 401 | + public function shareWithGroupMembersOnly(); |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * If shareWithGroupMembersOnly is enabled, return an optional |
|
| 405 | + * list of groups that must be excluded from the principle of |
|
| 406 | + * belonging to the same group. |
|
| 407 | + * @return array |
|
| 408 | + * @since 27.0.0 |
|
| 409 | + */ |
|
| 410 | + public function shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Check if users can share with groups |
|
| 414 | + * @return bool |
|
| 415 | + * @since 9.0.1 |
|
| 416 | + */ |
|
| 417 | + public function allowGroupSharing(); |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Check if user enumeration is allowed |
|
| 421 | + * |
|
| 422 | + * @return bool |
|
| 423 | + * @since 19.0.0 |
|
| 424 | + */ |
|
| 425 | + public function allowEnumeration(): bool; |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Check if user enumeration is limited to the users groups |
|
| 429 | + * |
|
| 430 | + * @return bool |
|
| 431 | + * @since 19.0.0 |
|
| 432 | + */ |
|
| 433 | + public function limitEnumerationToGroups(): bool; |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Check if user enumeration is limited to the phonebook matches |
|
| 437 | + * |
|
| 438 | + * @return bool |
|
| 439 | + * @since 21.0.1 |
|
| 440 | + */ |
|
| 441 | + public function limitEnumerationToPhone(): bool; |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Check if user enumeration is allowed to return on full match |
|
| 445 | + * |
|
| 446 | + * @return bool |
|
| 447 | + * @since 21.0.1 |
|
| 448 | + */ |
|
| 449 | + public function allowEnumerationFullMatch(): bool; |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Check if the search should match the email |
|
| 453 | + * |
|
| 454 | + * @return bool |
|
| 455 | + * @since 25.0.0 |
|
| 456 | + */ |
|
| 457 | + public function matchEmail(): bool; |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Check if the search should ignore the second in parentheses display name if there is any |
|
| 461 | + * |
|
| 462 | + * @return bool |
|
| 463 | + * @since 25.0.0 |
|
| 464 | + */ |
|
| 465 | + public function ignoreSecondDisplayName(): bool; |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Check if custom tokens are allowed |
|
| 470 | + * |
|
| 471 | + * @since 31.0.0 |
|
| 472 | + */ |
|
| 473 | + public function allowCustomTokens(): bool; |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Check if the current user can view the share |
|
| 477 | + * even if the download is disabled. |
|
| 478 | + * |
|
| 479 | + * @since 32.0.0 |
|
| 480 | + */ |
|
| 481 | + public function allowViewWithoutDownload(): bool; |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Check if the current user can enumerate the target user |
|
| 485 | + * |
|
| 486 | + * @param IUser|null $currentUser |
|
| 487 | + * @param IUser $targetUser |
|
| 488 | + * @return bool |
|
| 489 | + * @since 23.0.0 |
|
| 490 | + */ |
|
| 491 | + public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool; |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Check if sharing is disabled for the given user |
|
| 495 | + * |
|
| 496 | + * @since 9.0.0 |
|
| 497 | + */ |
|
| 498 | + public function sharingDisabledForUser(?string $userId): bool; |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Check if outgoing server2server shares are allowed |
|
| 502 | + * @return bool |
|
| 503 | + * @since 9.0.0 |
|
| 504 | + */ |
|
| 505 | + public function outgoingServer2ServerSharesAllowed(); |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Check if outgoing server2server shares are allowed |
|
| 509 | + * @return bool |
|
| 510 | + * @since 14.0.0 |
|
| 511 | + */ |
|
| 512 | + public function outgoingServer2ServerGroupSharesAllowed(); |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Check if a given share provider exists |
|
| 517 | + * @param int $shareType |
|
| 518 | + * @return bool |
|
| 519 | + * @since 11.0.0 |
|
| 520 | + */ |
|
| 521 | + public function shareProviderExists($shareType); |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * @param string $shareProviderClass |
|
| 525 | + * @since 21.0.0 |
|
| 526 | + */ |
|
| 527 | + public function registerShareProvider(string $shareProviderClass): void; |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * @Internal |
|
| 531 | + * |
|
| 532 | + * Get all the shares as iterable to reduce memory overhead |
|
| 533 | + * Note, since this opens up database cursors the iterable should |
|
| 534 | + * be fully itterated. |
|
| 535 | + * |
|
| 536 | + * @return iterable |
|
| 537 | + * @since 18.0.0 |
|
| 538 | + */ |
|
| 539 | + public function getAllShares(): iterable; |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Generate a unique share token |
|
| 543 | + * |
|
| 544 | + * @throws ShareTokenException Failed to generate a unique token |
|
| 545 | + * @since 31.0.0 |
|
| 546 | + */ |
|
| 547 | + public function generateToken(): string; |
|
| 548 | 548 | } |
@@ -22,622 +22,622 @@ |
||
| 22 | 22 | * @since 9.0.0 |
| 23 | 23 | */ |
| 24 | 24 | interface IShare { |
| 25 | - /** |
|
| 26 | - * @since 17.0.0 |
|
| 27 | - */ |
|
| 28 | - public const TYPE_USER = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @since 17.0.0 |
|
| 32 | - */ |
|
| 33 | - public const TYPE_GROUP = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @internal |
|
| 37 | - * @since 18.0.0 |
|
| 38 | - */ |
|
| 39 | - public const TYPE_USERGROUP = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @since 17.0.0 |
|
| 43 | - */ |
|
| 44 | - public const TYPE_LINK = 3; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @since 17.0.0 |
|
| 48 | - */ |
|
| 49 | - public const TYPE_EMAIL = 4; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * ToDo Check if it is still in use otherwise remove it |
|
| 53 | - * @since 17.0.0 |
|
| 54 | - */ |
|
| 55 | - // public const TYPE_CONTACT = 5; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @since 17.0.0 |
|
| 59 | - */ |
|
| 60 | - public const TYPE_REMOTE = 6; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @since 17.0.0 |
|
| 64 | - */ |
|
| 65 | - public const TYPE_CIRCLE = 7; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @since 17.0.0 |
|
| 69 | - */ |
|
| 70 | - public const TYPE_GUEST = 8; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @since 17.0.0 |
|
| 74 | - */ |
|
| 75 | - public const TYPE_REMOTE_GROUP = 9; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @since 17.0.0 |
|
| 79 | - */ |
|
| 80 | - public const TYPE_ROOM = 10; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Internal type used by RoomShareProvider |
|
| 84 | - * @since 17.0.0 |
|
| 85 | - */ |
|
| 86 | - // const TYPE_USERROOM = 11; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @since 21.0.0 |
|
| 90 | - */ |
|
| 91 | - public const TYPE_DECK = 12; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @internal |
|
| 95 | - * @since 21.0.0 |
|
| 96 | - */ |
|
| 97 | - public const TYPE_DECK_USER = 13; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @since 26.0.0 |
|
| 101 | - */ |
|
| 102 | - public const TYPE_SCIENCEMESH = 15; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @since 18.0.0 |
|
| 106 | - */ |
|
| 107 | - public const STATUS_PENDING = 0; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @since 18.0.0 |
|
| 111 | - */ |
|
| 112 | - public const STATUS_ACCEPTED = 1; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @since 18.0.0 |
|
| 116 | - */ |
|
| 117 | - public const STATUS_REJECTED = 2; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Set the internal id of the share |
|
| 121 | - * It is only allowed to set the internal id of a share once. |
|
| 122 | - * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 123 | - * |
|
| 124 | - * @param string $id |
|
| 125 | - * @return \OCP\Share\IShare |
|
| 126 | - * @throws IllegalIDChangeException |
|
| 127 | - * @throws \InvalidArgumentException |
|
| 128 | - * @since 9.1.0 |
|
| 129 | - */ |
|
| 130 | - public function setId($id); |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Get the internal id of the share. |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - * @since 9.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getId(); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Get the full share id. This is the <providerid>:<internalid>. |
|
| 142 | - * The full id is unique in the system. |
|
| 143 | - * |
|
| 144 | - * @return string |
|
| 145 | - * @since 9.0.0 |
|
| 146 | - * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 147 | - */ |
|
| 148 | - public function getFullId(); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set the provider id of the share |
|
| 152 | - * It is only allowed to set the provider id of a share once. |
|
| 153 | - * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 154 | - * |
|
| 155 | - * @param string $id |
|
| 156 | - * @return \OCP\Share\IShare |
|
| 157 | - * @throws IllegalIDChangeException |
|
| 158 | - * @throws \InvalidArgumentException |
|
| 159 | - * @since 9.1.0 |
|
| 160 | - */ |
|
| 161 | - public function setProviderId($id); |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set the node of the file/folder that is shared |
|
| 165 | - * |
|
| 166 | - * @param Node $node |
|
| 167 | - * @return \OCP\Share\IShare The modified object |
|
| 168 | - * @since 9.0.0 |
|
| 169 | - */ |
|
| 170 | - public function setNode(Node $node); |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Get the node of the file/folder that is shared |
|
| 174 | - * |
|
| 175 | - * @return File|Folder |
|
| 176 | - * @since 9.0.0 |
|
| 177 | - * @throws NotFoundException |
|
| 178 | - */ |
|
| 179 | - public function getNode(); |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Set file id for lazy evaluation of the node |
|
| 183 | - * @param int $fileId |
|
| 184 | - * @return \OCP\Share\IShare The modified object |
|
| 185 | - * @since 9.0.0 |
|
| 186 | - */ |
|
| 187 | - public function setNodeId($fileId); |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the fileid of the node of this share |
|
| 191 | - * @return int |
|
| 192 | - * @since 9.0.0 |
|
| 193 | - * @throws NotFoundException |
|
| 194 | - */ |
|
| 195 | - public function getNodeId(): int; |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Set the type of node (file/folder) |
|
| 199 | - * |
|
| 200 | - * @param string $type |
|
| 201 | - * @return \OCP\Share\IShare The modified object |
|
| 202 | - * @since 9.0.0 |
|
| 203 | - */ |
|
| 204 | - public function setNodeType($type); |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Get the type of node (file/folder) |
|
| 208 | - * |
|
| 209 | - * @return string |
|
| 210 | - * @since 9.0.0 |
|
| 211 | - * @throws NotFoundException |
|
| 212 | - */ |
|
| 213 | - public function getNodeType(); |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Set the shareType |
|
| 217 | - * |
|
| 218 | - * @param int $shareType |
|
| 219 | - * @return \OCP\Share\IShare The modified object |
|
| 220 | - * @since 9.0.0 |
|
| 221 | - */ |
|
| 222 | - public function setShareType($shareType); |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Get the shareType |
|
| 226 | - * |
|
| 227 | - * @return int |
|
| 228 | - * @since 9.0.0 |
|
| 229 | - */ |
|
| 230 | - public function getShareType(); |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Set the receiver of this share. |
|
| 234 | - * |
|
| 235 | - * @param string $sharedWith |
|
| 236 | - * @return \OCP\Share\IShare The modified object |
|
| 237 | - * @since 9.0.0 |
|
| 238 | - */ |
|
| 239 | - public function setSharedWith($sharedWith); |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Get the receiver of this share. |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - * @since 9.0.0 |
|
| 246 | - */ |
|
| 247 | - public function getSharedWith(); |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Set the display name of the receiver of this share. |
|
| 251 | - * |
|
| 252 | - * @param string $displayName |
|
| 253 | - * @return \OCP\Share\IShare The modified object |
|
| 254 | - * @since 14.0.0 |
|
| 255 | - */ |
|
| 256 | - public function setSharedWithDisplayName($displayName); |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Get the display name of the receiver of this share. |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - * @since 14.0.0 |
|
| 263 | - */ |
|
| 264 | - public function getSharedWithDisplayName(); |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Set the avatar of the receiver of this share. |
|
| 268 | - * |
|
| 269 | - * @param string $src |
|
| 270 | - * @return \OCP\Share\IShare The modified object |
|
| 271 | - * @since 14.0.0 |
|
| 272 | - */ |
|
| 273 | - public function setSharedWithAvatar($src); |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Get the avatar of the receiver of this share. |
|
| 277 | - * |
|
| 278 | - * @return string |
|
| 279 | - * @since 14.0.0 |
|
| 280 | - */ |
|
| 281 | - public function getSharedWithAvatar(); |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Set the permissions. |
|
| 285 | - * See \OCP\Constants::PERMISSION_* |
|
| 286 | - * |
|
| 287 | - * @param int $permissions |
|
| 288 | - * @return IShare The modified object |
|
| 289 | - * @since 9.0.0 |
|
| 290 | - */ |
|
| 291 | - public function setPermissions($permissions); |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the share permissions |
|
| 295 | - * See \OCP\Constants::PERMISSION_* |
|
| 296 | - * |
|
| 297 | - * @return int |
|
| 298 | - * @since 9.0.0 |
|
| 299 | - */ |
|
| 300 | - public function getPermissions(); |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Create share attributes object |
|
| 304 | - * |
|
| 305 | - * @since 25.0.0 |
|
| 306 | - * @return IAttributes |
|
| 307 | - */ |
|
| 308 | - public function newAttributes(): IAttributes; |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Set share attributes |
|
| 312 | - * |
|
| 313 | - * @param ?IAttributes $attributes |
|
| 314 | - * @since 25.0.0 |
|
| 315 | - * @return IShare The modified object |
|
| 316 | - */ |
|
| 317 | - public function setAttributes(?IAttributes $attributes); |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get share attributes |
|
| 321 | - * |
|
| 322 | - * @since 25.0.0 |
|
| 323 | - * @return ?IAttributes |
|
| 324 | - */ |
|
| 325 | - public function getAttributes(): ?IAttributes; |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Set the accepted status |
|
| 329 | - * See self::STATUS_* |
|
| 330 | - * |
|
| 331 | - * @param int $status |
|
| 332 | - * @return IShare The modified object |
|
| 333 | - * @since 18.0.0 |
|
| 334 | - */ |
|
| 335 | - public function setStatus(int $status): IShare; |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get the accepted status |
|
| 339 | - * See self::STATUS_* |
|
| 340 | - * |
|
| 341 | - * @return int |
|
| 342 | - * @since 18.0.0 |
|
| 343 | - */ |
|
| 344 | - public function getStatus(): int; |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Attach a note to a share |
|
| 348 | - * |
|
| 349 | - * @param string $note |
|
| 350 | - * @return \OCP\Share\IShare The modified object |
|
| 351 | - * @since 14.0.0 |
|
| 352 | - */ |
|
| 353 | - public function setNote($note); |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Get note attached to a share |
|
| 357 | - * |
|
| 358 | - * @return string |
|
| 359 | - * @since 14.0.0 |
|
| 360 | - */ |
|
| 361 | - public function getNote(); |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Set the expiration date |
|
| 366 | - * |
|
| 367 | - * @param \DateTime|null $expireDate |
|
| 368 | - * @return \OCP\Share\IShare The modified object |
|
| 369 | - * @since 9.0.0 |
|
| 370 | - */ |
|
| 371 | - public function setExpirationDate(?\DateTime $expireDate); |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Get the expiration date |
|
| 375 | - * |
|
| 376 | - * @return \DateTime|null |
|
| 377 | - * @since 9.0.0 |
|
| 378 | - */ |
|
| 379 | - public function getExpirationDate(); |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Set overwrite flag for falsy expiry date values |
|
| 383 | - * |
|
| 384 | - * @param bool $noExpirationDate |
|
| 385 | - * @return \OCP\Share\IShare The modified object |
|
| 386 | - * @since 30.0.0 |
|
| 387 | - */ |
|
| 388 | - public function setNoExpirationDate(bool $noExpirationDate); |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Get value of overwrite falsy expiry date flag |
|
| 393 | - * |
|
| 394 | - * @return bool |
|
| 395 | - * @since 30.0.0 |
|
| 396 | - */ |
|
| 397 | - public function getNoExpirationDate(); |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Is the share expired ? |
|
| 401 | - * |
|
| 402 | - * @return boolean |
|
| 403 | - * @since 18.0.0 |
|
| 404 | - */ |
|
| 405 | - public function isExpired(); |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * set a label for a share, some shares, e.g. public links can have a label |
|
| 409 | - * |
|
| 410 | - * @param string $label |
|
| 411 | - * @return \OCP\Share\IShare The modified object |
|
| 412 | - * @since 15.0.0 |
|
| 413 | - */ |
|
| 414 | - public function setLabel($label); |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * get label for the share, some shares, e.g. public links can have a label |
|
| 418 | - * |
|
| 419 | - * @return string |
|
| 420 | - * @since 15.0.0 |
|
| 421 | - */ |
|
| 422 | - public function getLabel(); |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Set the sharer of the path. |
|
| 426 | - * |
|
| 427 | - * @param string $sharedBy |
|
| 428 | - * @return \OCP\Share\IShare The modified object |
|
| 429 | - * @since 9.0.0 |
|
| 430 | - */ |
|
| 431 | - public function setSharedBy($sharedBy); |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Get share sharer |
|
| 435 | - * |
|
| 436 | - * @return string |
|
| 437 | - * @since 9.0.0 |
|
| 438 | - */ |
|
| 439 | - public function getSharedBy(); |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Set the original share owner (who owns the path that is shared) |
|
| 443 | - * |
|
| 444 | - * @param string $shareOwner |
|
| 445 | - * @return \OCP\Share\IShare The modified object |
|
| 446 | - * @since 9.0.0 |
|
| 447 | - */ |
|
| 448 | - public function setShareOwner($shareOwner); |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Get the original share owner (who owns the path that is shared) |
|
| 452 | - * |
|
| 453 | - * @return string |
|
| 454 | - * @since 9.0.0 |
|
| 455 | - */ |
|
| 456 | - public function getShareOwner(); |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Set the password for this share. |
|
| 460 | - * When the share is passed to the share manager to be created |
|
| 461 | - * or updated the password will be hashed. |
|
| 462 | - * |
|
| 463 | - * @param string|null $password |
|
| 464 | - * @return \OCP\Share\IShare The modified object |
|
| 465 | - * @since 9.0.0 |
|
| 466 | - */ |
|
| 467 | - public function setPassword($password); |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get the password of this share. |
|
| 471 | - * If this share is obtained via a shareprovider the password is |
|
| 472 | - * hashed. |
|
| 473 | - * |
|
| 474 | - * @return string|null |
|
| 475 | - * @since 9.0.0 |
|
| 476 | - */ |
|
| 477 | - public function getPassword(); |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Set the password's expiration time of this share. |
|
| 481 | - * |
|
| 482 | - * @return self The modified object |
|
| 483 | - * @since 24.0.0 |
|
| 484 | - */ |
|
| 485 | - public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare; |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Get the password's expiration time of this share. |
|
| 489 | - * @since 24.0.0 |
|
| 490 | - */ |
|
| 491 | - public function getPasswordExpirationTime(): ?\DateTimeInterface; |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Set if the recipient can start a conversation with the owner to get the |
|
| 495 | - * password using Nextcloud Talk. |
|
| 496 | - * |
|
| 497 | - * @param bool $sendPasswordByTalk |
|
| 498 | - * @return \OCP\Share\IShare The modified object |
|
| 499 | - * @since 14.0.0 |
|
| 500 | - */ |
|
| 501 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk); |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Get if the recipient can start a conversation with the owner to get the |
|
| 505 | - * password using Nextcloud Talk. |
|
| 506 | - * The returned value does not take into account other factors, like Talk |
|
| 507 | - * being enabled for the owner of the share or not; it just cover whether |
|
| 508 | - * the option is enabled for the share itself or not. |
|
| 509 | - * |
|
| 510 | - * @return bool |
|
| 511 | - * @since 14.0.0 |
|
| 512 | - */ |
|
| 513 | - public function getSendPasswordByTalk(): bool; |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Set the public link token. |
|
| 517 | - * |
|
| 518 | - * @param string $token |
|
| 519 | - * @return \OCP\Share\IShare The modified object |
|
| 520 | - * @since 9.0.0 |
|
| 521 | - */ |
|
| 522 | - public function setToken($token); |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Get the public link token. |
|
| 526 | - * |
|
| 527 | - * @return string |
|
| 528 | - * @since 9.0.0 |
|
| 529 | - */ |
|
| 530 | - public function getToken(); |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Set the target path of this share relative to the recipients user folder. |
|
| 534 | - * |
|
| 535 | - * @param string $target |
|
| 536 | - * @return \OCP\Share\IShare The modified object |
|
| 537 | - * @since 9.0.0 |
|
| 538 | - */ |
|
| 539 | - public function setTarget($target); |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Get the target path of this share relative to the recipients user folder. |
|
| 543 | - * |
|
| 544 | - * @return string |
|
| 545 | - * @since 9.0.0 |
|
| 546 | - */ |
|
| 547 | - public function getTarget(); |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Set the time this share was created |
|
| 551 | - * |
|
| 552 | - * @param \DateTime $shareTime |
|
| 553 | - * @return \OCP\Share\IShare The modified object |
|
| 554 | - * @since 9.0.0 |
|
| 555 | - */ |
|
| 556 | - public function setShareTime(\DateTime $shareTime); |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Get the timestamp this share was created |
|
| 560 | - * |
|
| 561 | - * @return \DateTime |
|
| 562 | - * @since 9.0.0 |
|
| 563 | - */ |
|
| 564 | - public function getShareTime(); |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set if the recipient should be informed by mail about the share. |
|
| 568 | - * |
|
| 569 | - * @param bool $mailSend |
|
| 570 | - * @return \OCP\Share\IShare The modified object |
|
| 571 | - * @since 9.0.0 |
|
| 572 | - */ |
|
| 573 | - public function setMailSend($mailSend); |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Get if the recipient should be informed by mail about the share. |
|
| 577 | - * |
|
| 578 | - * @return bool |
|
| 579 | - * @since 9.0.0 |
|
| 580 | - */ |
|
| 581 | - public function getMailSend(); |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Set the cache entry for the shared node |
|
| 585 | - * |
|
| 586 | - * @param ICacheEntry $entry |
|
| 587 | - * @return void |
|
| 588 | - * @since 11.0.0 |
|
| 589 | - */ |
|
| 590 | - public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Get the cache entry for the shared node |
|
| 594 | - * |
|
| 595 | - * @return null|ICacheEntry |
|
| 596 | - * @since 11.0.0 |
|
| 597 | - */ |
|
| 598 | - public function getNodeCacheEntry(); |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Sets a shares hide download state |
|
| 602 | - * This is mainly for public shares. It will signal that the share page should |
|
| 603 | - * hide download buttons etc. |
|
| 604 | - * |
|
| 605 | - * @param bool $hide |
|
| 606 | - * @return IShare |
|
| 607 | - * @since 15.0.0 |
|
| 608 | - */ |
|
| 609 | - public function setHideDownload(bool $hide): IShare; |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Gets a shares hide download state |
|
| 613 | - * This is mainly for public shares. It will signal that the share page should |
|
| 614 | - * hide download buttons etc. |
|
| 615 | - * |
|
| 616 | - * @return bool |
|
| 617 | - * @since 15.0.0 |
|
| 618 | - */ |
|
| 619 | - public function getHideDownload(): bool; |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Sets a flag that stores whether a reminder via email has been sent |
|
| 623 | - * |
|
| 624 | - * @return self The modified object |
|
| 625 | - * @since 31.0.0 |
|
| 626 | - */ |
|
| 627 | - public function setReminderSent(bool $reminderSent): IShare; |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Gets a flag that stores whether a reminder via email has been sent |
|
| 631 | - * |
|
| 632 | - * @return bool |
|
| 633 | - * @since 31.0.0 |
|
| 634 | - */ |
|
| 635 | - public function getReminderSent(): bool; |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Check if the current user can see this share files contents. |
|
| 639 | - * This will check the download permissions as well as the global |
|
| 640 | - * admin setting to allow viewing files without downloading. |
|
| 641 | - */ |
|
| 642 | - public function canSeeContent(): bool; |
|
| 25 | + /** |
|
| 26 | + * @since 17.0.0 |
|
| 27 | + */ |
|
| 28 | + public const TYPE_USER = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @since 17.0.0 |
|
| 32 | + */ |
|
| 33 | + public const TYPE_GROUP = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @internal |
|
| 37 | + * @since 18.0.0 |
|
| 38 | + */ |
|
| 39 | + public const TYPE_USERGROUP = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @since 17.0.0 |
|
| 43 | + */ |
|
| 44 | + public const TYPE_LINK = 3; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @since 17.0.0 |
|
| 48 | + */ |
|
| 49 | + public const TYPE_EMAIL = 4; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * ToDo Check if it is still in use otherwise remove it |
|
| 53 | + * @since 17.0.0 |
|
| 54 | + */ |
|
| 55 | + // public const TYPE_CONTACT = 5; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @since 17.0.0 |
|
| 59 | + */ |
|
| 60 | + public const TYPE_REMOTE = 6; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @since 17.0.0 |
|
| 64 | + */ |
|
| 65 | + public const TYPE_CIRCLE = 7; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @since 17.0.0 |
|
| 69 | + */ |
|
| 70 | + public const TYPE_GUEST = 8; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @since 17.0.0 |
|
| 74 | + */ |
|
| 75 | + public const TYPE_REMOTE_GROUP = 9; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @since 17.0.0 |
|
| 79 | + */ |
|
| 80 | + public const TYPE_ROOM = 10; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Internal type used by RoomShareProvider |
|
| 84 | + * @since 17.0.0 |
|
| 85 | + */ |
|
| 86 | + // const TYPE_USERROOM = 11; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @since 21.0.0 |
|
| 90 | + */ |
|
| 91 | + public const TYPE_DECK = 12; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @internal |
|
| 95 | + * @since 21.0.0 |
|
| 96 | + */ |
|
| 97 | + public const TYPE_DECK_USER = 13; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @since 26.0.0 |
|
| 101 | + */ |
|
| 102 | + public const TYPE_SCIENCEMESH = 15; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @since 18.0.0 |
|
| 106 | + */ |
|
| 107 | + public const STATUS_PENDING = 0; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @since 18.0.0 |
|
| 111 | + */ |
|
| 112 | + public const STATUS_ACCEPTED = 1; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @since 18.0.0 |
|
| 116 | + */ |
|
| 117 | + public const STATUS_REJECTED = 2; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Set the internal id of the share |
|
| 121 | + * It is only allowed to set the internal id of a share once. |
|
| 122 | + * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 123 | + * |
|
| 124 | + * @param string $id |
|
| 125 | + * @return \OCP\Share\IShare |
|
| 126 | + * @throws IllegalIDChangeException |
|
| 127 | + * @throws \InvalidArgumentException |
|
| 128 | + * @since 9.1.0 |
|
| 129 | + */ |
|
| 130 | + public function setId($id); |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Get the internal id of the share. |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + * @since 9.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getId(); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get the full share id. This is the <providerid>:<internalid>. |
|
| 142 | + * The full id is unique in the system. |
|
| 143 | + * |
|
| 144 | + * @return string |
|
| 145 | + * @since 9.0.0 |
|
| 146 | + * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 147 | + */ |
|
| 148 | + public function getFullId(); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set the provider id of the share |
|
| 152 | + * It is only allowed to set the provider id of a share once. |
|
| 153 | + * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 154 | + * |
|
| 155 | + * @param string $id |
|
| 156 | + * @return \OCP\Share\IShare |
|
| 157 | + * @throws IllegalIDChangeException |
|
| 158 | + * @throws \InvalidArgumentException |
|
| 159 | + * @since 9.1.0 |
|
| 160 | + */ |
|
| 161 | + public function setProviderId($id); |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set the node of the file/folder that is shared |
|
| 165 | + * |
|
| 166 | + * @param Node $node |
|
| 167 | + * @return \OCP\Share\IShare The modified object |
|
| 168 | + * @since 9.0.0 |
|
| 169 | + */ |
|
| 170 | + public function setNode(Node $node); |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Get the node of the file/folder that is shared |
|
| 174 | + * |
|
| 175 | + * @return File|Folder |
|
| 176 | + * @since 9.0.0 |
|
| 177 | + * @throws NotFoundException |
|
| 178 | + */ |
|
| 179 | + public function getNode(); |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Set file id for lazy evaluation of the node |
|
| 183 | + * @param int $fileId |
|
| 184 | + * @return \OCP\Share\IShare The modified object |
|
| 185 | + * @since 9.0.0 |
|
| 186 | + */ |
|
| 187 | + public function setNodeId($fileId); |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the fileid of the node of this share |
|
| 191 | + * @return int |
|
| 192 | + * @since 9.0.0 |
|
| 193 | + * @throws NotFoundException |
|
| 194 | + */ |
|
| 195 | + public function getNodeId(): int; |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Set the type of node (file/folder) |
|
| 199 | + * |
|
| 200 | + * @param string $type |
|
| 201 | + * @return \OCP\Share\IShare The modified object |
|
| 202 | + * @since 9.0.0 |
|
| 203 | + */ |
|
| 204 | + public function setNodeType($type); |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Get the type of node (file/folder) |
|
| 208 | + * |
|
| 209 | + * @return string |
|
| 210 | + * @since 9.0.0 |
|
| 211 | + * @throws NotFoundException |
|
| 212 | + */ |
|
| 213 | + public function getNodeType(); |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Set the shareType |
|
| 217 | + * |
|
| 218 | + * @param int $shareType |
|
| 219 | + * @return \OCP\Share\IShare The modified object |
|
| 220 | + * @since 9.0.0 |
|
| 221 | + */ |
|
| 222 | + public function setShareType($shareType); |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Get the shareType |
|
| 226 | + * |
|
| 227 | + * @return int |
|
| 228 | + * @since 9.0.0 |
|
| 229 | + */ |
|
| 230 | + public function getShareType(); |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Set the receiver of this share. |
|
| 234 | + * |
|
| 235 | + * @param string $sharedWith |
|
| 236 | + * @return \OCP\Share\IShare The modified object |
|
| 237 | + * @since 9.0.0 |
|
| 238 | + */ |
|
| 239 | + public function setSharedWith($sharedWith); |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Get the receiver of this share. |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + * @since 9.0.0 |
|
| 246 | + */ |
|
| 247 | + public function getSharedWith(); |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Set the display name of the receiver of this share. |
|
| 251 | + * |
|
| 252 | + * @param string $displayName |
|
| 253 | + * @return \OCP\Share\IShare The modified object |
|
| 254 | + * @since 14.0.0 |
|
| 255 | + */ |
|
| 256 | + public function setSharedWithDisplayName($displayName); |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Get the display name of the receiver of this share. |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + * @since 14.0.0 |
|
| 263 | + */ |
|
| 264 | + public function getSharedWithDisplayName(); |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Set the avatar of the receiver of this share. |
|
| 268 | + * |
|
| 269 | + * @param string $src |
|
| 270 | + * @return \OCP\Share\IShare The modified object |
|
| 271 | + * @since 14.0.0 |
|
| 272 | + */ |
|
| 273 | + public function setSharedWithAvatar($src); |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Get the avatar of the receiver of this share. |
|
| 277 | + * |
|
| 278 | + * @return string |
|
| 279 | + * @since 14.0.0 |
|
| 280 | + */ |
|
| 281 | + public function getSharedWithAvatar(); |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Set the permissions. |
|
| 285 | + * See \OCP\Constants::PERMISSION_* |
|
| 286 | + * |
|
| 287 | + * @param int $permissions |
|
| 288 | + * @return IShare The modified object |
|
| 289 | + * @since 9.0.0 |
|
| 290 | + */ |
|
| 291 | + public function setPermissions($permissions); |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the share permissions |
|
| 295 | + * See \OCP\Constants::PERMISSION_* |
|
| 296 | + * |
|
| 297 | + * @return int |
|
| 298 | + * @since 9.0.0 |
|
| 299 | + */ |
|
| 300 | + public function getPermissions(); |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Create share attributes object |
|
| 304 | + * |
|
| 305 | + * @since 25.0.0 |
|
| 306 | + * @return IAttributes |
|
| 307 | + */ |
|
| 308 | + public function newAttributes(): IAttributes; |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Set share attributes |
|
| 312 | + * |
|
| 313 | + * @param ?IAttributes $attributes |
|
| 314 | + * @since 25.0.0 |
|
| 315 | + * @return IShare The modified object |
|
| 316 | + */ |
|
| 317 | + public function setAttributes(?IAttributes $attributes); |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get share attributes |
|
| 321 | + * |
|
| 322 | + * @since 25.0.0 |
|
| 323 | + * @return ?IAttributes |
|
| 324 | + */ |
|
| 325 | + public function getAttributes(): ?IAttributes; |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Set the accepted status |
|
| 329 | + * See self::STATUS_* |
|
| 330 | + * |
|
| 331 | + * @param int $status |
|
| 332 | + * @return IShare The modified object |
|
| 333 | + * @since 18.0.0 |
|
| 334 | + */ |
|
| 335 | + public function setStatus(int $status): IShare; |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Get the accepted status |
|
| 339 | + * See self::STATUS_* |
|
| 340 | + * |
|
| 341 | + * @return int |
|
| 342 | + * @since 18.0.0 |
|
| 343 | + */ |
|
| 344 | + public function getStatus(): int; |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Attach a note to a share |
|
| 348 | + * |
|
| 349 | + * @param string $note |
|
| 350 | + * @return \OCP\Share\IShare The modified object |
|
| 351 | + * @since 14.0.0 |
|
| 352 | + */ |
|
| 353 | + public function setNote($note); |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Get note attached to a share |
|
| 357 | + * |
|
| 358 | + * @return string |
|
| 359 | + * @since 14.0.0 |
|
| 360 | + */ |
|
| 361 | + public function getNote(); |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Set the expiration date |
|
| 366 | + * |
|
| 367 | + * @param \DateTime|null $expireDate |
|
| 368 | + * @return \OCP\Share\IShare The modified object |
|
| 369 | + * @since 9.0.0 |
|
| 370 | + */ |
|
| 371 | + public function setExpirationDate(?\DateTime $expireDate); |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Get the expiration date |
|
| 375 | + * |
|
| 376 | + * @return \DateTime|null |
|
| 377 | + * @since 9.0.0 |
|
| 378 | + */ |
|
| 379 | + public function getExpirationDate(); |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Set overwrite flag for falsy expiry date values |
|
| 383 | + * |
|
| 384 | + * @param bool $noExpirationDate |
|
| 385 | + * @return \OCP\Share\IShare The modified object |
|
| 386 | + * @since 30.0.0 |
|
| 387 | + */ |
|
| 388 | + public function setNoExpirationDate(bool $noExpirationDate); |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Get value of overwrite falsy expiry date flag |
|
| 393 | + * |
|
| 394 | + * @return bool |
|
| 395 | + * @since 30.0.0 |
|
| 396 | + */ |
|
| 397 | + public function getNoExpirationDate(); |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Is the share expired ? |
|
| 401 | + * |
|
| 402 | + * @return boolean |
|
| 403 | + * @since 18.0.0 |
|
| 404 | + */ |
|
| 405 | + public function isExpired(); |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * set a label for a share, some shares, e.g. public links can have a label |
|
| 409 | + * |
|
| 410 | + * @param string $label |
|
| 411 | + * @return \OCP\Share\IShare The modified object |
|
| 412 | + * @since 15.0.0 |
|
| 413 | + */ |
|
| 414 | + public function setLabel($label); |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * get label for the share, some shares, e.g. public links can have a label |
|
| 418 | + * |
|
| 419 | + * @return string |
|
| 420 | + * @since 15.0.0 |
|
| 421 | + */ |
|
| 422 | + public function getLabel(); |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Set the sharer of the path. |
|
| 426 | + * |
|
| 427 | + * @param string $sharedBy |
|
| 428 | + * @return \OCP\Share\IShare The modified object |
|
| 429 | + * @since 9.0.0 |
|
| 430 | + */ |
|
| 431 | + public function setSharedBy($sharedBy); |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Get share sharer |
|
| 435 | + * |
|
| 436 | + * @return string |
|
| 437 | + * @since 9.0.0 |
|
| 438 | + */ |
|
| 439 | + public function getSharedBy(); |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Set the original share owner (who owns the path that is shared) |
|
| 443 | + * |
|
| 444 | + * @param string $shareOwner |
|
| 445 | + * @return \OCP\Share\IShare The modified object |
|
| 446 | + * @since 9.0.0 |
|
| 447 | + */ |
|
| 448 | + public function setShareOwner($shareOwner); |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Get the original share owner (who owns the path that is shared) |
|
| 452 | + * |
|
| 453 | + * @return string |
|
| 454 | + * @since 9.0.0 |
|
| 455 | + */ |
|
| 456 | + public function getShareOwner(); |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Set the password for this share. |
|
| 460 | + * When the share is passed to the share manager to be created |
|
| 461 | + * or updated the password will be hashed. |
|
| 462 | + * |
|
| 463 | + * @param string|null $password |
|
| 464 | + * @return \OCP\Share\IShare The modified object |
|
| 465 | + * @since 9.0.0 |
|
| 466 | + */ |
|
| 467 | + public function setPassword($password); |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get the password of this share. |
|
| 471 | + * If this share is obtained via a shareprovider the password is |
|
| 472 | + * hashed. |
|
| 473 | + * |
|
| 474 | + * @return string|null |
|
| 475 | + * @since 9.0.0 |
|
| 476 | + */ |
|
| 477 | + public function getPassword(); |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Set the password's expiration time of this share. |
|
| 481 | + * |
|
| 482 | + * @return self The modified object |
|
| 483 | + * @since 24.0.0 |
|
| 484 | + */ |
|
| 485 | + public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare; |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Get the password's expiration time of this share. |
|
| 489 | + * @since 24.0.0 |
|
| 490 | + */ |
|
| 491 | + public function getPasswordExpirationTime(): ?\DateTimeInterface; |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Set if the recipient can start a conversation with the owner to get the |
|
| 495 | + * password using Nextcloud Talk. |
|
| 496 | + * |
|
| 497 | + * @param bool $sendPasswordByTalk |
|
| 498 | + * @return \OCP\Share\IShare The modified object |
|
| 499 | + * @since 14.0.0 |
|
| 500 | + */ |
|
| 501 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk); |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Get if the recipient can start a conversation with the owner to get the |
|
| 505 | + * password using Nextcloud Talk. |
|
| 506 | + * The returned value does not take into account other factors, like Talk |
|
| 507 | + * being enabled for the owner of the share or not; it just cover whether |
|
| 508 | + * the option is enabled for the share itself or not. |
|
| 509 | + * |
|
| 510 | + * @return bool |
|
| 511 | + * @since 14.0.0 |
|
| 512 | + */ |
|
| 513 | + public function getSendPasswordByTalk(): bool; |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Set the public link token. |
|
| 517 | + * |
|
| 518 | + * @param string $token |
|
| 519 | + * @return \OCP\Share\IShare The modified object |
|
| 520 | + * @since 9.0.0 |
|
| 521 | + */ |
|
| 522 | + public function setToken($token); |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Get the public link token. |
|
| 526 | + * |
|
| 527 | + * @return string |
|
| 528 | + * @since 9.0.0 |
|
| 529 | + */ |
|
| 530 | + public function getToken(); |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Set the target path of this share relative to the recipients user folder. |
|
| 534 | + * |
|
| 535 | + * @param string $target |
|
| 536 | + * @return \OCP\Share\IShare The modified object |
|
| 537 | + * @since 9.0.0 |
|
| 538 | + */ |
|
| 539 | + public function setTarget($target); |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Get the target path of this share relative to the recipients user folder. |
|
| 543 | + * |
|
| 544 | + * @return string |
|
| 545 | + * @since 9.0.0 |
|
| 546 | + */ |
|
| 547 | + public function getTarget(); |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Set the time this share was created |
|
| 551 | + * |
|
| 552 | + * @param \DateTime $shareTime |
|
| 553 | + * @return \OCP\Share\IShare The modified object |
|
| 554 | + * @since 9.0.0 |
|
| 555 | + */ |
|
| 556 | + public function setShareTime(\DateTime $shareTime); |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Get the timestamp this share was created |
|
| 560 | + * |
|
| 561 | + * @return \DateTime |
|
| 562 | + * @since 9.0.0 |
|
| 563 | + */ |
|
| 564 | + public function getShareTime(); |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set if the recipient should be informed by mail about the share. |
|
| 568 | + * |
|
| 569 | + * @param bool $mailSend |
|
| 570 | + * @return \OCP\Share\IShare The modified object |
|
| 571 | + * @since 9.0.0 |
|
| 572 | + */ |
|
| 573 | + public function setMailSend($mailSend); |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Get if the recipient should be informed by mail about the share. |
|
| 577 | + * |
|
| 578 | + * @return bool |
|
| 579 | + * @since 9.0.0 |
|
| 580 | + */ |
|
| 581 | + public function getMailSend(); |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Set the cache entry for the shared node |
|
| 585 | + * |
|
| 586 | + * @param ICacheEntry $entry |
|
| 587 | + * @return void |
|
| 588 | + * @since 11.0.0 |
|
| 589 | + */ |
|
| 590 | + public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Get the cache entry for the shared node |
|
| 594 | + * |
|
| 595 | + * @return null|ICacheEntry |
|
| 596 | + * @since 11.0.0 |
|
| 597 | + */ |
|
| 598 | + public function getNodeCacheEntry(); |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Sets a shares hide download state |
|
| 602 | + * This is mainly for public shares. It will signal that the share page should |
|
| 603 | + * hide download buttons etc. |
|
| 604 | + * |
|
| 605 | + * @param bool $hide |
|
| 606 | + * @return IShare |
|
| 607 | + * @since 15.0.0 |
|
| 608 | + */ |
|
| 609 | + public function setHideDownload(bool $hide): IShare; |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Gets a shares hide download state |
|
| 613 | + * This is mainly for public shares. It will signal that the share page should |
|
| 614 | + * hide download buttons etc. |
|
| 615 | + * |
|
| 616 | + * @return bool |
|
| 617 | + * @since 15.0.0 |
|
| 618 | + */ |
|
| 619 | + public function getHideDownload(): bool; |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Sets a flag that stores whether a reminder via email has been sent |
|
| 623 | + * |
|
| 624 | + * @return self The modified object |
|
| 625 | + * @since 31.0.0 |
|
| 626 | + */ |
|
| 627 | + public function setReminderSent(bool $reminderSent): IShare; |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Gets a flag that stores whether a reminder via email has been sent |
|
| 631 | + * |
|
| 632 | + * @return bool |
|
| 633 | + * @since 31.0.0 |
|
| 634 | + */ |
|
| 635 | + public function getReminderSent(): bool; |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Check if the current user can see this share files contents. |
|
| 639 | + * This will check the download permissions as well as the global |
|
| 640 | + * admin setting to allow viewing files without downloading. |
|
| 641 | + */ |
|
| 642 | + public function canSeeContent(): bool; |
|
| 643 | 643 | } |
@@ -21,626 +21,626 @@ |
||
| 21 | 21 | use OCP\Share\IShare; |
| 22 | 22 | |
| 23 | 23 | class Share implements IShare { |
| 24 | - /** @var string */ |
|
| 25 | - private $id; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $providerId; |
|
| 28 | - /** @var Node */ |
|
| 29 | - private $node; |
|
| 30 | - /** @var int */ |
|
| 31 | - private $fileId; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $nodeType; |
|
| 34 | - /** @var int */ |
|
| 35 | - private $shareType; |
|
| 36 | - /** @var string */ |
|
| 37 | - private $sharedWith; |
|
| 38 | - /** @var string */ |
|
| 39 | - private $sharedWithDisplayName; |
|
| 40 | - /** @var string */ |
|
| 41 | - private $sharedWithAvatar; |
|
| 42 | - /** @var string */ |
|
| 43 | - private $sharedBy; |
|
| 44 | - /** @var string */ |
|
| 45 | - private $shareOwner; |
|
| 46 | - /** @var int */ |
|
| 47 | - private $permissions; |
|
| 48 | - /** @var IAttributes */ |
|
| 49 | - private $attributes; |
|
| 50 | - /** @var int */ |
|
| 51 | - private $status; |
|
| 52 | - /** @var string */ |
|
| 53 | - private $note = ''; |
|
| 54 | - /** @var \DateTime */ |
|
| 55 | - private $expireDate; |
|
| 56 | - /** @var string */ |
|
| 57 | - private $password; |
|
| 58 | - private ?\DateTimeInterface $passwordExpirationTime = null; |
|
| 59 | - /** @var bool */ |
|
| 60 | - private $sendPasswordByTalk = false; |
|
| 61 | - /** @var string */ |
|
| 62 | - private $token; |
|
| 63 | - /** @var int */ |
|
| 64 | - private $parent; |
|
| 65 | - /** @var string */ |
|
| 66 | - private $target; |
|
| 67 | - /** @var \DateTime */ |
|
| 68 | - private $shareTime; |
|
| 69 | - /** @var bool */ |
|
| 70 | - private $mailSend; |
|
| 71 | - /** @var ICacheEntry|null */ |
|
| 72 | - private $nodeCacheEntry; |
|
| 73 | - /** @var bool */ |
|
| 74 | - private $hideDownload = false; |
|
| 75 | - private bool $reminderSent = false; |
|
| 76 | - |
|
| 77 | - private string $label = ''; |
|
| 78 | - private bool $noExpirationDate = false; |
|
| 79 | - |
|
| 80 | - public function __construct( |
|
| 81 | - private IRootFolder $rootFolder, |
|
| 82 | - private IUserManager $userManager, |
|
| 83 | - ) { |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @inheritdoc |
|
| 88 | - */ |
|
| 89 | - public function setId($id) { |
|
| 90 | - /** @var mixed $id Let's be safe until strong typing */ |
|
| 91 | - if (is_int($id)) { |
|
| 92 | - $id = (string)$id; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (!is_string($id)) { |
|
| 96 | - throw new \InvalidArgumentException('String expected.'); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ($this->id !== null) { |
|
| 100 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $this->id = trim($id); |
|
| 104 | - return $this; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @inheritdoc |
|
| 109 | - */ |
|
| 110 | - public function getId() { |
|
| 111 | - return $this->id; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @inheritdoc |
|
| 116 | - */ |
|
| 117 | - public function getFullId() { |
|
| 118 | - if ($this->providerId === null || $this->id === null) { |
|
| 119 | - throw new \UnexpectedValueException; |
|
| 120 | - } |
|
| 121 | - return $this->providerId . ':' . $this->id; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @inheritdoc |
|
| 126 | - */ |
|
| 127 | - public function setProviderId($id) { |
|
| 128 | - if (!is_string($id)) { |
|
| 129 | - throw new \InvalidArgumentException('String expected.'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($this->providerId !== null) { |
|
| 133 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $this->providerId = trim($id); |
|
| 137 | - return $this; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @inheritdoc |
|
| 142 | - */ |
|
| 143 | - public function setNode(Node $node) { |
|
| 144 | - $this->fileId = null; |
|
| 145 | - $this->nodeType = null; |
|
| 146 | - $this->node = $node; |
|
| 147 | - return $this; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @inheritdoc |
|
| 152 | - */ |
|
| 153 | - public function getNode() { |
|
| 154 | - if ($this->node === null) { |
|
| 155 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
| 156 | - throw new NotFoundException(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // for federated shares the owner can be a remote user, in this |
|
| 160 | - // case we use the initiator |
|
| 161 | - if ($this->userManager->userExists($this->shareOwner)) { |
|
| 162 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 163 | - } else { |
|
| 164 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $node = $userFolder->getFirstNodeById($this->fileId); |
|
| 168 | - if (!$node) { |
|
| 169 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $this->node = $node; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $this->node; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @inheritdoc |
|
| 180 | - */ |
|
| 181 | - public function setNodeId($fileId) { |
|
| 182 | - $this->node = null; |
|
| 183 | - $this->fileId = $fileId; |
|
| 184 | - return $this; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @inheritdoc |
|
| 189 | - */ |
|
| 190 | - public function getNodeId(): int { |
|
| 191 | - if ($this->fileId === null) { |
|
| 192 | - $this->fileId = $this->getNode()->getId(); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($this->fileId === null) { |
|
| 196 | - throw new NotFoundException('Share source not found'); |
|
| 197 | - } else { |
|
| 198 | - return $this->fileId; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @inheritdoc |
|
| 204 | - */ |
|
| 205 | - public function setNodeType($type) { |
|
| 206 | - if ($type !== 'file' && $type !== 'folder') { |
|
| 207 | - throw new \InvalidArgumentException(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $this->nodeType = $type; |
|
| 211 | - return $this; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @inheritdoc |
|
| 216 | - */ |
|
| 217 | - public function getNodeType() { |
|
| 218 | - if ($this->nodeType === null) { |
|
| 219 | - if ($this->getNodeCacheEntry()) { |
|
| 220 | - $info = $this->getNodeCacheEntry(); |
|
| 221 | - $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 222 | - } else { |
|
| 223 | - $node = $this->getNode(); |
|
| 224 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $this->nodeType; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @inheritdoc |
|
| 233 | - */ |
|
| 234 | - public function setShareType($shareType) { |
|
| 235 | - $this->shareType = $shareType; |
|
| 236 | - return $this; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @inheritdoc |
|
| 241 | - */ |
|
| 242 | - public function getShareType() { |
|
| 243 | - return $this->shareType; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @inheritdoc |
|
| 248 | - */ |
|
| 249 | - public function setSharedWith($sharedWith) { |
|
| 250 | - if (!is_string($sharedWith)) { |
|
| 251 | - throw new \InvalidArgumentException(); |
|
| 252 | - } |
|
| 253 | - $this->sharedWith = $sharedWith; |
|
| 254 | - return $this; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @inheritdoc |
|
| 259 | - */ |
|
| 260 | - public function getSharedWith() { |
|
| 261 | - return $this->sharedWith; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @inheritdoc |
|
| 266 | - */ |
|
| 267 | - public function setSharedWithDisplayName($displayName) { |
|
| 268 | - if (!is_string($displayName)) { |
|
| 269 | - throw new \InvalidArgumentException(); |
|
| 270 | - } |
|
| 271 | - $this->sharedWithDisplayName = $displayName; |
|
| 272 | - return $this; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @inheritdoc |
|
| 277 | - */ |
|
| 278 | - public function getSharedWithDisplayName() { |
|
| 279 | - return $this->sharedWithDisplayName; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @inheritdoc |
|
| 284 | - */ |
|
| 285 | - public function setSharedWithAvatar($src) { |
|
| 286 | - if (!is_string($src)) { |
|
| 287 | - throw new \InvalidArgumentException(); |
|
| 288 | - } |
|
| 289 | - $this->sharedWithAvatar = $src; |
|
| 290 | - return $this; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @inheritdoc |
|
| 295 | - */ |
|
| 296 | - public function getSharedWithAvatar() { |
|
| 297 | - return $this->sharedWithAvatar; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @inheritdoc |
|
| 302 | - */ |
|
| 303 | - public function setPermissions($permissions) { |
|
| 304 | - //TODO checks |
|
| 305 | - |
|
| 306 | - $this->permissions = $permissions; |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @inheritdoc |
|
| 312 | - */ |
|
| 313 | - public function getPermissions() { |
|
| 314 | - return $this->permissions; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @inheritdoc |
|
| 319 | - */ |
|
| 320 | - public function newAttributes(): IAttributes { |
|
| 321 | - return new ShareAttributes(); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @inheritdoc |
|
| 326 | - */ |
|
| 327 | - public function setAttributes(?IAttributes $attributes) { |
|
| 328 | - $this->attributes = $attributes; |
|
| 329 | - return $this; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @inheritdoc |
|
| 334 | - */ |
|
| 335 | - public function getAttributes(): ?IAttributes { |
|
| 336 | - return $this->attributes; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @inheritdoc |
|
| 341 | - */ |
|
| 342 | - public function setStatus(int $status): IShare { |
|
| 343 | - $this->status = $status; |
|
| 344 | - return $this; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @inheritdoc |
|
| 349 | - */ |
|
| 350 | - public function getStatus(): int { |
|
| 351 | - return $this->status; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @inheritdoc |
|
| 356 | - */ |
|
| 357 | - public function setNote($note) { |
|
| 358 | - $this->note = $note; |
|
| 359 | - return $this; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @inheritdoc |
|
| 364 | - */ |
|
| 365 | - public function getNote() { |
|
| 366 | - if (is_string($this->note)) { |
|
| 367 | - return $this->note; |
|
| 368 | - } |
|
| 369 | - return ''; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @inheritdoc |
|
| 374 | - */ |
|
| 375 | - public function setLabel($label) { |
|
| 376 | - $this->label = $label; |
|
| 377 | - return $this; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @inheritdoc |
|
| 382 | - */ |
|
| 383 | - public function getLabel() { |
|
| 384 | - return $this->label; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @inheritdoc |
|
| 389 | - */ |
|
| 390 | - public function setExpirationDate($expireDate) { |
|
| 391 | - //TODO checks |
|
| 392 | - |
|
| 393 | - $this->expireDate = $expireDate; |
|
| 394 | - return $this; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @inheritdoc |
|
| 399 | - */ |
|
| 400 | - public function getExpirationDate() { |
|
| 401 | - return $this->expireDate; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * @inheritdoc |
|
| 406 | - */ |
|
| 407 | - public function setNoExpirationDate(bool $noExpirationDate) { |
|
| 408 | - $this->noExpirationDate = $noExpirationDate; |
|
| 409 | - return $this; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * @inheritdoc |
|
| 414 | - */ |
|
| 415 | - public function getNoExpirationDate(): bool { |
|
| 416 | - return $this->noExpirationDate; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * @inheritdoc |
|
| 421 | - */ |
|
| 422 | - public function isExpired() { |
|
| 423 | - return $this->getExpirationDate() !== null && |
|
| 424 | - $this->getExpirationDate() <= new \DateTime(); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @inheritdoc |
|
| 429 | - */ |
|
| 430 | - public function setSharedBy($sharedBy) { |
|
| 431 | - if (!is_string($sharedBy)) { |
|
| 432 | - throw new \InvalidArgumentException(); |
|
| 433 | - } |
|
| 434 | - //TODO checks |
|
| 435 | - $this->sharedBy = $sharedBy; |
|
| 436 | - |
|
| 437 | - return $this; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @inheritdoc |
|
| 442 | - */ |
|
| 443 | - public function getSharedBy() { |
|
| 444 | - //TODO check if set |
|
| 445 | - return $this->sharedBy; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * @inheritdoc |
|
| 450 | - */ |
|
| 451 | - public function setShareOwner($shareOwner) { |
|
| 452 | - if (!is_string($shareOwner)) { |
|
| 453 | - throw new \InvalidArgumentException(); |
|
| 454 | - } |
|
| 455 | - //TODO checks |
|
| 456 | - |
|
| 457 | - $this->shareOwner = $shareOwner; |
|
| 458 | - return $this; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @inheritdoc |
|
| 463 | - */ |
|
| 464 | - public function getShareOwner() { |
|
| 465 | - //TODO check if set |
|
| 466 | - return $this->shareOwner; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * @inheritdoc |
|
| 471 | - */ |
|
| 472 | - public function setPassword($password) { |
|
| 473 | - $this->password = $password; |
|
| 474 | - return $this; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * @inheritdoc |
|
| 479 | - */ |
|
| 480 | - public function getPassword() { |
|
| 481 | - return $this->password; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * @inheritdoc |
|
| 486 | - */ |
|
| 487 | - public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare { |
|
| 488 | - $this->passwordExpirationTime = $passwordExpirationTime; |
|
| 489 | - return $this; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @inheritdoc |
|
| 494 | - */ |
|
| 495 | - public function getPasswordExpirationTime(): ?\DateTimeInterface { |
|
| 496 | - return $this->passwordExpirationTime; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * @inheritdoc |
|
| 501 | - */ |
|
| 502 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 503 | - $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 504 | - return $this; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @inheritdoc |
|
| 509 | - */ |
|
| 510 | - public function getSendPasswordByTalk(): bool { |
|
| 511 | - return $this->sendPasswordByTalk; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * @inheritdoc |
|
| 516 | - */ |
|
| 517 | - public function setToken($token) { |
|
| 518 | - $this->token = $token; |
|
| 519 | - return $this; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * @inheritdoc |
|
| 524 | - */ |
|
| 525 | - public function getToken() { |
|
| 526 | - return $this->token; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Set the parent of this share |
|
| 531 | - * |
|
| 532 | - * @param int $parent |
|
| 533 | - * @return IShare |
|
| 534 | - * @deprecated 12.0.0 The new shares do not have parents. This is just here for legacy reasons. |
|
| 535 | - */ |
|
| 536 | - public function setParent($parent) { |
|
| 537 | - $this->parent = $parent; |
|
| 538 | - return $this; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Get the parent of this share. |
|
| 543 | - * |
|
| 544 | - * @return int |
|
| 545 | - * @deprecated 12.0.0 The new shares do not have parents. This is just here for legacy reasons. |
|
| 546 | - */ |
|
| 547 | - public function getParent() { |
|
| 548 | - return $this->parent; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * @inheritdoc |
|
| 553 | - */ |
|
| 554 | - public function setTarget($target) { |
|
| 555 | - $this->target = $target; |
|
| 556 | - return $this; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * @inheritdoc |
|
| 561 | - */ |
|
| 562 | - public function getTarget() { |
|
| 563 | - return $this->target; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * @inheritdoc |
|
| 568 | - */ |
|
| 569 | - public function setShareTime(\DateTime $shareTime) { |
|
| 570 | - $this->shareTime = $shareTime; |
|
| 571 | - return $this; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * @inheritdoc |
|
| 576 | - */ |
|
| 577 | - public function getShareTime() { |
|
| 578 | - return $this->shareTime; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @inheritdoc |
|
| 583 | - */ |
|
| 584 | - public function setMailSend($mailSend) { |
|
| 585 | - $this->mailSend = $mailSend; |
|
| 586 | - return $this; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * @inheritdoc |
|
| 591 | - */ |
|
| 592 | - public function getMailSend() { |
|
| 593 | - return $this->mailSend; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @inheritdoc |
|
| 598 | - */ |
|
| 599 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 600 | - $this->nodeCacheEntry = $entry; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * @inheritdoc |
|
| 605 | - */ |
|
| 606 | - public function getNodeCacheEntry() { |
|
| 607 | - return $this->nodeCacheEntry; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - public function setHideDownload(bool $hide): IShare { |
|
| 611 | - $this->hideDownload = $hide; |
|
| 612 | - return $this; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - public function getHideDownload(): bool { |
|
| 616 | - return $this->hideDownload; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - public function setReminderSent(bool $reminderSent): IShare { |
|
| 620 | - $this->reminderSent = $reminderSent; |
|
| 621 | - return $this; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - public function getReminderSent(): bool { |
|
| 625 | - return $this->reminderSent; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - public function canSeeContent(): bool { |
|
| 629 | - $shareManager = Server::get(IManager::class); |
|
| 630 | - |
|
| 631 | - $allowViewWithoutDownload = $shareManager->allowViewWithoutDownload(); |
|
| 632 | - // If the share manager allows viewing without download, we can always see the content. |
|
| 633 | - if ($allowViewWithoutDownload) { |
|
| 634 | - return true; |
|
| 635 | - } |
|
| 24 | + /** @var string */ |
|
| 25 | + private $id; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $providerId; |
|
| 28 | + /** @var Node */ |
|
| 29 | + private $node; |
|
| 30 | + /** @var int */ |
|
| 31 | + private $fileId; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $nodeType; |
|
| 34 | + /** @var int */ |
|
| 35 | + private $shareType; |
|
| 36 | + /** @var string */ |
|
| 37 | + private $sharedWith; |
|
| 38 | + /** @var string */ |
|
| 39 | + private $sharedWithDisplayName; |
|
| 40 | + /** @var string */ |
|
| 41 | + private $sharedWithAvatar; |
|
| 42 | + /** @var string */ |
|
| 43 | + private $sharedBy; |
|
| 44 | + /** @var string */ |
|
| 45 | + private $shareOwner; |
|
| 46 | + /** @var int */ |
|
| 47 | + private $permissions; |
|
| 48 | + /** @var IAttributes */ |
|
| 49 | + private $attributes; |
|
| 50 | + /** @var int */ |
|
| 51 | + private $status; |
|
| 52 | + /** @var string */ |
|
| 53 | + private $note = ''; |
|
| 54 | + /** @var \DateTime */ |
|
| 55 | + private $expireDate; |
|
| 56 | + /** @var string */ |
|
| 57 | + private $password; |
|
| 58 | + private ?\DateTimeInterface $passwordExpirationTime = null; |
|
| 59 | + /** @var bool */ |
|
| 60 | + private $sendPasswordByTalk = false; |
|
| 61 | + /** @var string */ |
|
| 62 | + private $token; |
|
| 63 | + /** @var int */ |
|
| 64 | + private $parent; |
|
| 65 | + /** @var string */ |
|
| 66 | + private $target; |
|
| 67 | + /** @var \DateTime */ |
|
| 68 | + private $shareTime; |
|
| 69 | + /** @var bool */ |
|
| 70 | + private $mailSend; |
|
| 71 | + /** @var ICacheEntry|null */ |
|
| 72 | + private $nodeCacheEntry; |
|
| 73 | + /** @var bool */ |
|
| 74 | + private $hideDownload = false; |
|
| 75 | + private bool $reminderSent = false; |
|
| 76 | + |
|
| 77 | + private string $label = ''; |
|
| 78 | + private bool $noExpirationDate = false; |
|
| 79 | + |
|
| 80 | + public function __construct( |
|
| 81 | + private IRootFolder $rootFolder, |
|
| 82 | + private IUserManager $userManager, |
|
| 83 | + ) { |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @inheritdoc |
|
| 88 | + */ |
|
| 89 | + public function setId($id) { |
|
| 90 | + /** @var mixed $id Let's be safe until strong typing */ |
|
| 91 | + if (is_int($id)) { |
|
| 92 | + $id = (string)$id; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (!is_string($id)) { |
|
| 96 | + throw new \InvalidArgumentException('String expected.'); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ($this->id !== null) { |
|
| 100 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $this->id = trim($id); |
|
| 104 | + return $this; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @inheritdoc |
|
| 109 | + */ |
|
| 110 | + public function getId() { |
|
| 111 | + return $this->id; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @inheritdoc |
|
| 116 | + */ |
|
| 117 | + public function getFullId() { |
|
| 118 | + if ($this->providerId === null || $this->id === null) { |
|
| 119 | + throw new \UnexpectedValueException; |
|
| 120 | + } |
|
| 121 | + return $this->providerId . ':' . $this->id; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @inheritdoc |
|
| 126 | + */ |
|
| 127 | + public function setProviderId($id) { |
|
| 128 | + if (!is_string($id)) { |
|
| 129 | + throw new \InvalidArgumentException('String expected.'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($this->providerId !== null) { |
|
| 133 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $this->providerId = trim($id); |
|
| 137 | + return $this; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @inheritdoc |
|
| 142 | + */ |
|
| 143 | + public function setNode(Node $node) { |
|
| 144 | + $this->fileId = null; |
|
| 145 | + $this->nodeType = null; |
|
| 146 | + $this->node = $node; |
|
| 147 | + return $this; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @inheritdoc |
|
| 152 | + */ |
|
| 153 | + public function getNode() { |
|
| 154 | + if ($this->node === null) { |
|
| 155 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
| 156 | + throw new NotFoundException(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // for federated shares the owner can be a remote user, in this |
|
| 160 | + // case we use the initiator |
|
| 161 | + if ($this->userManager->userExists($this->shareOwner)) { |
|
| 162 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 163 | + } else { |
|
| 164 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $node = $userFolder->getFirstNodeById($this->fileId); |
|
| 168 | + if (!$node) { |
|
| 169 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $this->node = $node; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $this->node; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @inheritdoc |
|
| 180 | + */ |
|
| 181 | + public function setNodeId($fileId) { |
|
| 182 | + $this->node = null; |
|
| 183 | + $this->fileId = $fileId; |
|
| 184 | + return $this; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @inheritdoc |
|
| 189 | + */ |
|
| 190 | + public function getNodeId(): int { |
|
| 191 | + if ($this->fileId === null) { |
|
| 192 | + $this->fileId = $this->getNode()->getId(); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($this->fileId === null) { |
|
| 196 | + throw new NotFoundException('Share source not found'); |
|
| 197 | + } else { |
|
| 198 | + return $this->fileId; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @inheritdoc |
|
| 204 | + */ |
|
| 205 | + public function setNodeType($type) { |
|
| 206 | + if ($type !== 'file' && $type !== 'folder') { |
|
| 207 | + throw new \InvalidArgumentException(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $this->nodeType = $type; |
|
| 211 | + return $this; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @inheritdoc |
|
| 216 | + */ |
|
| 217 | + public function getNodeType() { |
|
| 218 | + if ($this->nodeType === null) { |
|
| 219 | + if ($this->getNodeCacheEntry()) { |
|
| 220 | + $info = $this->getNodeCacheEntry(); |
|
| 221 | + $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 222 | + } else { |
|
| 223 | + $node = $this->getNode(); |
|
| 224 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $this->nodeType; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @inheritdoc |
|
| 233 | + */ |
|
| 234 | + public function setShareType($shareType) { |
|
| 235 | + $this->shareType = $shareType; |
|
| 236 | + return $this; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @inheritdoc |
|
| 241 | + */ |
|
| 242 | + public function getShareType() { |
|
| 243 | + return $this->shareType; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @inheritdoc |
|
| 248 | + */ |
|
| 249 | + public function setSharedWith($sharedWith) { |
|
| 250 | + if (!is_string($sharedWith)) { |
|
| 251 | + throw new \InvalidArgumentException(); |
|
| 252 | + } |
|
| 253 | + $this->sharedWith = $sharedWith; |
|
| 254 | + return $this; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @inheritdoc |
|
| 259 | + */ |
|
| 260 | + public function getSharedWith() { |
|
| 261 | + return $this->sharedWith; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @inheritdoc |
|
| 266 | + */ |
|
| 267 | + public function setSharedWithDisplayName($displayName) { |
|
| 268 | + if (!is_string($displayName)) { |
|
| 269 | + throw new \InvalidArgumentException(); |
|
| 270 | + } |
|
| 271 | + $this->sharedWithDisplayName = $displayName; |
|
| 272 | + return $this; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @inheritdoc |
|
| 277 | + */ |
|
| 278 | + public function getSharedWithDisplayName() { |
|
| 279 | + return $this->sharedWithDisplayName; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @inheritdoc |
|
| 284 | + */ |
|
| 285 | + public function setSharedWithAvatar($src) { |
|
| 286 | + if (!is_string($src)) { |
|
| 287 | + throw new \InvalidArgumentException(); |
|
| 288 | + } |
|
| 289 | + $this->sharedWithAvatar = $src; |
|
| 290 | + return $this; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @inheritdoc |
|
| 295 | + */ |
|
| 296 | + public function getSharedWithAvatar() { |
|
| 297 | + return $this->sharedWithAvatar; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @inheritdoc |
|
| 302 | + */ |
|
| 303 | + public function setPermissions($permissions) { |
|
| 304 | + //TODO checks |
|
| 305 | + |
|
| 306 | + $this->permissions = $permissions; |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @inheritdoc |
|
| 312 | + */ |
|
| 313 | + public function getPermissions() { |
|
| 314 | + return $this->permissions; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @inheritdoc |
|
| 319 | + */ |
|
| 320 | + public function newAttributes(): IAttributes { |
|
| 321 | + return new ShareAttributes(); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @inheritdoc |
|
| 326 | + */ |
|
| 327 | + public function setAttributes(?IAttributes $attributes) { |
|
| 328 | + $this->attributes = $attributes; |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @inheritdoc |
|
| 334 | + */ |
|
| 335 | + public function getAttributes(): ?IAttributes { |
|
| 336 | + return $this->attributes; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @inheritdoc |
|
| 341 | + */ |
|
| 342 | + public function setStatus(int $status): IShare { |
|
| 343 | + $this->status = $status; |
|
| 344 | + return $this; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @inheritdoc |
|
| 349 | + */ |
|
| 350 | + public function getStatus(): int { |
|
| 351 | + return $this->status; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * @inheritdoc |
|
| 356 | + */ |
|
| 357 | + public function setNote($note) { |
|
| 358 | + $this->note = $note; |
|
| 359 | + return $this; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @inheritdoc |
|
| 364 | + */ |
|
| 365 | + public function getNote() { |
|
| 366 | + if (is_string($this->note)) { |
|
| 367 | + return $this->note; |
|
| 368 | + } |
|
| 369 | + return ''; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @inheritdoc |
|
| 374 | + */ |
|
| 375 | + public function setLabel($label) { |
|
| 376 | + $this->label = $label; |
|
| 377 | + return $this; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @inheritdoc |
|
| 382 | + */ |
|
| 383 | + public function getLabel() { |
|
| 384 | + return $this->label; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @inheritdoc |
|
| 389 | + */ |
|
| 390 | + public function setExpirationDate($expireDate) { |
|
| 391 | + //TODO checks |
|
| 392 | + |
|
| 393 | + $this->expireDate = $expireDate; |
|
| 394 | + return $this; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @inheritdoc |
|
| 399 | + */ |
|
| 400 | + public function getExpirationDate() { |
|
| 401 | + return $this->expireDate; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * @inheritdoc |
|
| 406 | + */ |
|
| 407 | + public function setNoExpirationDate(bool $noExpirationDate) { |
|
| 408 | + $this->noExpirationDate = $noExpirationDate; |
|
| 409 | + return $this; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * @inheritdoc |
|
| 414 | + */ |
|
| 415 | + public function getNoExpirationDate(): bool { |
|
| 416 | + return $this->noExpirationDate; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * @inheritdoc |
|
| 421 | + */ |
|
| 422 | + public function isExpired() { |
|
| 423 | + return $this->getExpirationDate() !== null && |
|
| 424 | + $this->getExpirationDate() <= new \DateTime(); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @inheritdoc |
|
| 429 | + */ |
|
| 430 | + public function setSharedBy($sharedBy) { |
|
| 431 | + if (!is_string($sharedBy)) { |
|
| 432 | + throw new \InvalidArgumentException(); |
|
| 433 | + } |
|
| 434 | + //TODO checks |
|
| 435 | + $this->sharedBy = $sharedBy; |
|
| 436 | + |
|
| 437 | + return $this; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @inheritdoc |
|
| 442 | + */ |
|
| 443 | + public function getSharedBy() { |
|
| 444 | + //TODO check if set |
|
| 445 | + return $this->sharedBy; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * @inheritdoc |
|
| 450 | + */ |
|
| 451 | + public function setShareOwner($shareOwner) { |
|
| 452 | + if (!is_string($shareOwner)) { |
|
| 453 | + throw new \InvalidArgumentException(); |
|
| 454 | + } |
|
| 455 | + //TODO checks |
|
| 456 | + |
|
| 457 | + $this->shareOwner = $shareOwner; |
|
| 458 | + return $this; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @inheritdoc |
|
| 463 | + */ |
|
| 464 | + public function getShareOwner() { |
|
| 465 | + //TODO check if set |
|
| 466 | + return $this->shareOwner; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * @inheritdoc |
|
| 471 | + */ |
|
| 472 | + public function setPassword($password) { |
|
| 473 | + $this->password = $password; |
|
| 474 | + return $this; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * @inheritdoc |
|
| 479 | + */ |
|
| 480 | + public function getPassword() { |
|
| 481 | + return $this->password; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * @inheritdoc |
|
| 486 | + */ |
|
| 487 | + public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare { |
|
| 488 | + $this->passwordExpirationTime = $passwordExpirationTime; |
|
| 489 | + return $this; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @inheritdoc |
|
| 494 | + */ |
|
| 495 | + public function getPasswordExpirationTime(): ?\DateTimeInterface { |
|
| 496 | + return $this->passwordExpirationTime; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * @inheritdoc |
|
| 501 | + */ |
|
| 502 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 503 | + $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 504 | + return $this; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @inheritdoc |
|
| 509 | + */ |
|
| 510 | + public function getSendPasswordByTalk(): bool { |
|
| 511 | + return $this->sendPasswordByTalk; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * @inheritdoc |
|
| 516 | + */ |
|
| 517 | + public function setToken($token) { |
|
| 518 | + $this->token = $token; |
|
| 519 | + return $this; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * @inheritdoc |
|
| 524 | + */ |
|
| 525 | + public function getToken() { |
|
| 526 | + return $this->token; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Set the parent of this share |
|
| 531 | + * |
|
| 532 | + * @param int $parent |
|
| 533 | + * @return IShare |
|
| 534 | + * @deprecated 12.0.0 The new shares do not have parents. This is just here for legacy reasons. |
|
| 535 | + */ |
|
| 536 | + public function setParent($parent) { |
|
| 537 | + $this->parent = $parent; |
|
| 538 | + return $this; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Get the parent of this share. |
|
| 543 | + * |
|
| 544 | + * @return int |
|
| 545 | + * @deprecated 12.0.0 The new shares do not have parents. This is just here for legacy reasons. |
|
| 546 | + */ |
|
| 547 | + public function getParent() { |
|
| 548 | + return $this->parent; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * @inheritdoc |
|
| 553 | + */ |
|
| 554 | + public function setTarget($target) { |
|
| 555 | + $this->target = $target; |
|
| 556 | + return $this; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * @inheritdoc |
|
| 561 | + */ |
|
| 562 | + public function getTarget() { |
|
| 563 | + return $this->target; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * @inheritdoc |
|
| 568 | + */ |
|
| 569 | + public function setShareTime(\DateTime $shareTime) { |
|
| 570 | + $this->shareTime = $shareTime; |
|
| 571 | + return $this; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * @inheritdoc |
|
| 576 | + */ |
|
| 577 | + public function getShareTime() { |
|
| 578 | + return $this->shareTime; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @inheritdoc |
|
| 583 | + */ |
|
| 584 | + public function setMailSend($mailSend) { |
|
| 585 | + $this->mailSend = $mailSend; |
|
| 586 | + return $this; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * @inheritdoc |
|
| 591 | + */ |
|
| 592 | + public function getMailSend() { |
|
| 593 | + return $this->mailSend; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @inheritdoc |
|
| 598 | + */ |
|
| 599 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 600 | + $this->nodeCacheEntry = $entry; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * @inheritdoc |
|
| 605 | + */ |
|
| 606 | + public function getNodeCacheEntry() { |
|
| 607 | + return $this->nodeCacheEntry; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + public function setHideDownload(bool $hide): IShare { |
|
| 611 | + $this->hideDownload = $hide; |
|
| 612 | + return $this; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + public function getHideDownload(): bool { |
|
| 616 | + return $this->hideDownload; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + public function setReminderSent(bool $reminderSent): IShare { |
|
| 620 | + $this->reminderSent = $reminderSent; |
|
| 621 | + return $this; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + public function getReminderSent(): bool { |
|
| 625 | + return $this->reminderSent; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + public function canSeeContent(): bool { |
|
| 629 | + $shareManager = Server::get(IManager::class); |
|
| 630 | + |
|
| 631 | + $allowViewWithoutDownload = $shareManager->allowViewWithoutDownload(); |
|
| 632 | + // If the share manager allows viewing without download, we can always see the content. |
|
| 633 | + if ($allowViewWithoutDownload) { |
|
| 634 | + return true; |
|
| 635 | + } |
|
| 636 | 636 | |
| 637 | - // No "allow preview" header set, so we must check if |
|
| 638 | - // the share has not explicitly disabled download permissions |
|
| 639 | - $attributes = $this->getAttributes(); |
|
| 640 | - if ($attributes?->getAttribute('permissions', 'download') === false) { |
|
| 641 | - return false; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - return true; |
|
| 645 | - } |
|
| 637 | + // No "allow preview" header set, so we must check if |
|
| 638 | + // the share has not explicitly disabled download permissions |
|
| 639 | + $attributes = $this->getAttributes(); |
|
| 640 | + if ($attributes?->getAttribute('permissions', 'download') === false) { |
|
| 641 | + return false; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + return true; |
|
| 645 | + } |
|
| 646 | 646 | } |
@@ -60,2008 +60,2008 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | class Manager implements IManager { |
| 62 | 62 | |
| 63 | - private ?IL10N $l; |
|
| 64 | - private LegacyHooks $legacyHooks; |
|
| 65 | - |
|
| 66 | - public function __construct( |
|
| 67 | - private LoggerInterface $logger, |
|
| 68 | - private IConfig $config, |
|
| 69 | - private ISecureRandom $secureRandom, |
|
| 70 | - private IHasher $hasher, |
|
| 71 | - private IMountManager $mountManager, |
|
| 72 | - private IGroupManager $groupManager, |
|
| 73 | - private IFactory $l10nFactory, |
|
| 74 | - private IProviderFactory $factory, |
|
| 75 | - private IUserManager $userManager, |
|
| 76 | - private IRootFolder $rootFolder, |
|
| 77 | - private IMailer $mailer, |
|
| 78 | - private IURLGenerator $urlGenerator, |
|
| 79 | - private \OC_Defaults $defaults, |
|
| 80 | - private IEventDispatcher $dispatcher, |
|
| 81 | - private IUserSession $userSession, |
|
| 82 | - private KnownUserService $knownUserService, |
|
| 83 | - private ShareDisableChecker $shareDisableChecker, |
|
| 84 | - private IDateTimeZone $dateTimeZone, |
|
| 85 | - private IAppConfig $appConfig, |
|
| 86 | - ) { |
|
| 87 | - $this->l = $this->l10nFactory->get('lib'); |
|
| 88 | - // The constructor of LegacyHooks registers the listeners of share events |
|
| 89 | - // do not remove if those are not properly migrated |
|
| 90 | - $this->legacyHooks = new LegacyHooks($this->dispatcher); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
| 95 | - * |
|
| 96 | - * @param string $id |
|
| 97 | - * @return string[] |
|
| 98 | - */ |
|
| 99 | - private function splitFullId($id) { |
|
| 100 | - return explode(':', $id, 2); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Verify if a password meets all requirements |
|
| 105 | - * |
|
| 106 | - * @param string $password |
|
| 107 | - * @throws HintException |
|
| 108 | - */ |
|
| 109 | - protected function verifyPassword($password) { |
|
| 110 | - if ($password === null) { |
|
| 111 | - // No password is set, check if this is allowed. |
|
| 112 | - if ($this->shareApiLinkEnforcePassword()) { |
|
| 113 | - throw new \InvalidArgumentException($this->l->t('Passwords are enforced for link and mail shares')); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Let others verify the password |
|
| 120 | - try { |
|
| 121 | - $event = new ValidatePasswordPolicyEvent($password, PasswordContext::SHARING); |
|
| 122 | - $this->dispatcher->dispatchTyped($event); |
|
| 123 | - } catch (HintException $e) { |
|
| 124 | - /* Wrap in a 400 bad request error */ |
|
| 125 | - throw new HintException($e->getMessage(), $e->getHint(), 400, $e); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Check for generic requirements before creating a share |
|
| 131 | - * |
|
| 132 | - * @param IShare $share |
|
| 133 | - * @throws \InvalidArgumentException |
|
| 134 | - * @throws GenericShareException |
|
| 135 | - * |
|
| 136 | - * @suppress PhanUndeclaredClassMethod |
|
| 137 | - */ |
|
| 138 | - protected function generalCreateChecks(IShare $share, bool $isUpdate = false) { |
|
| 139 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 140 | - // We expect a valid user as sharedWith for user shares |
|
| 141 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 142 | - throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid user')); |
|
| 143 | - } |
|
| 144 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 145 | - // We expect a valid group as sharedWith for group shares |
|
| 146 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 147 | - throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid group')); |
|
| 148 | - } |
|
| 149 | - } elseif ($share->getShareType() === IShare::TYPE_LINK) { |
|
| 150 | - // No check for TYPE_EMAIL here as we have a recipient for them |
|
| 151 | - if ($share->getSharedWith() !== null) { |
|
| 152 | - throw new \InvalidArgumentException($this->l->t('Share recipient should be empty')); |
|
| 153 | - } |
|
| 154 | - } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 155 | - if ($share->getSharedWith() === null) { |
|
| 156 | - throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 157 | - } |
|
| 158 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
| 159 | - if ($share->getSharedWith() === null) { |
|
| 160 | - throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 161 | - } |
|
| 162 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 163 | - if ($share->getSharedWith() === null) { |
|
| 164 | - throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 165 | - } |
|
| 166 | - } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { |
|
| 167 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
| 168 | - if ($circle === null) { |
|
| 169 | - throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid circle')); |
|
| 170 | - } |
|
| 171 | - } elseif ($share->getShareType() === IShare::TYPE_ROOM) { |
|
| 172 | - } elseif ($share->getShareType() === IShare::TYPE_DECK) { |
|
| 173 | - } elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) { |
|
| 174 | - } else { |
|
| 175 | - // We cannot handle other types yet |
|
| 176 | - throw new \InvalidArgumentException($this->l->t('Unknown share type')); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Verify the initiator of the share is set |
|
| 180 | - if ($share->getSharedBy() === null) { |
|
| 181 | - throw new \InvalidArgumentException($this->l->t('Share initiator must be set')); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // Cannot share with yourself |
|
| 185 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
| 186 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
| 187 | - throw new \InvalidArgumentException($this->l->t('Cannot share with yourself')); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // The path should be set |
|
| 191 | - if ($share->getNode() === null) { |
|
| 192 | - throw new \InvalidArgumentException($this->l->t('Shared path must be set')); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // And it should be a file or a folder |
|
| 196 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 197 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 198 | - throw new \InvalidArgumentException($this->l->t('Shared path must be either a file or a folder')); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // And you cannot share your rootfolder |
|
| 202 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 203 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 204 | - } else { |
|
| 205 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 206 | - } |
|
| 207 | - if ($userFolder->getId() === $share->getNode()->getId()) { |
|
| 208 | - throw new \InvalidArgumentException($this->l->t('You cannot share your root folder')); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // Check if we actually have share permissions |
|
| 212 | - if (!$share->getNode()->isShareable()) { |
|
| 213 | - throw new GenericShareException($this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]), code: 404); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // Permissions should be set |
|
| 217 | - if ($share->getPermissions() === null) { |
|
| 218 | - throw new \InvalidArgumentException($this->l->t('Valid permissions are required for sharing')); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // Permissions must be valid |
|
| 222 | - if ($share->getPermissions() < 0 || $share->getPermissions() > \OCP\Constants::PERMISSION_ALL) { |
|
| 223 | - throw new \InvalidArgumentException($this->l->t('Valid permissions are required for sharing')); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Single file shares should never have delete or create permissions |
|
| 227 | - if (($share->getNode() instanceof File) |
|
| 228 | - && (($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE)) !== 0)) { |
|
| 229 | - throw new \InvalidArgumentException($this->l->t('File shares cannot have create or delete permissions')); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $permissions = 0; |
|
| 233 | - $nodesForUser = $userFolder->getById($share->getNodeId()); |
|
| 234 | - foreach ($nodesForUser as $node) { |
|
| 235 | - if ($node->getInternalPath() === '' && !$node->getMountPoint() instanceof MoveableMount) { |
|
| 236 | - // for the root of non-movable mount, the permissions we see if limited by the mount itself, |
|
| 237 | - // so we instead use the "raw" permissions from the storage |
|
| 238 | - $permissions |= $node->getStorage()->getPermissions(''); |
|
| 239 | - } else { |
|
| 240 | - $permissions |= $node->getPermissions(); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Check that we do not share with more permissions than we have |
|
| 245 | - if ($share->getPermissions() & ~$permissions) { |
|
| 246 | - $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 247 | - throw new GenericShareException($this->l->t('Cannot increase permissions of %s', [$path]), code: 404); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // Check that read permissions are always set |
|
| 251 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 252 | - $noReadPermissionRequired = $share->getShareType() === IShare::TYPE_LINK |
|
| 253 | - || $share->getShareType() === IShare::TYPE_EMAIL; |
|
| 254 | - if (!$noReadPermissionRequired && |
|
| 255 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 256 | - throw new \InvalidArgumentException($this->l->t('Shares need at least read permissions')); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 260 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 261 | - throw new GenericShareException($this->l->t('Files cannot be shared with delete permissions')); |
|
| 262 | - } |
|
| 263 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 264 | - throw new GenericShareException($this->l->t('Files cannot be shared with create permissions')); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Validate if the expiration date fits the system settings |
|
| 271 | - * |
|
| 272 | - * @param IShare $share The share to validate the expiration date of |
|
| 273 | - * @return IShare The modified share object |
|
| 274 | - * @throws GenericShareException |
|
| 275 | - * @throws \InvalidArgumentException |
|
| 276 | - * @throws \Exception |
|
| 277 | - */ |
|
| 278 | - protected function validateExpirationDateInternal(IShare $share) { |
|
| 279 | - $isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP; |
|
| 280 | - |
|
| 281 | - $expirationDate = $share->getExpirationDate(); |
|
| 282 | - |
|
| 283 | - if ($isRemote) { |
|
| 284 | - $defaultExpireDate = $this->shareApiRemoteDefaultExpireDate(); |
|
| 285 | - $defaultExpireDays = $this->shareApiRemoteDefaultExpireDays(); |
|
| 286 | - $configProp = 'remote_defaultExpDays'; |
|
| 287 | - $isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced(); |
|
| 288 | - } else { |
|
| 289 | - $defaultExpireDate = $this->shareApiInternalDefaultExpireDate(); |
|
| 290 | - $defaultExpireDays = $this->shareApiInternalDefaultExpireDays(); |
|
| 291 | - $configProp = 'internal_defaultExpDays'; |
|
| 292 | - $isEnforced = $this->shareApiInternalDefaultExpireDateEnforced(); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced |
|
| 296 | - // Then skip expiration date validation as null is accepted |
|
| 297 | - if (!$share->getNoExpirationDate() || $isEnforced) { |
|
| 298 | - if ($expirationDate !== null) { |
|
| 299 | - $expirationDate->setTimezone($this->dateTimeZone->getTimeZone()); |
|
| 300 | - $expirationDate->setTime(0, 0, 0); |
|
| 301 | - |
|
| 302 | - $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 303 | - $date->setTime(0, 0, 0); |
|
| 304 | - if ($date >= $expirationDate) { |
|
| 305 | - throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // If expiredate is empty set a default one if there is a default |
|
| 310 | - $fullId = null; |
|
| 311 | - try { |
|
| 312 | - $fullId = $share->getFullId(); |
|
| 313 | - } catch (\UnexpectedValueException $e) { |
|
| 314 | - // This is a new share |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if ($fullId === null && $expirationDate === null && $defaultExpireDate) { |
|
| 318 | - $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 319 | - $expirationDate->setTime(0, 0, 0); |
|
| 320 | - $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays); |
|
| 321 | - if ($days > $defaultExpireDays) { |
|
| 322 | - $days = $defaultExpireDays; |
|
| 323 | - } |
|
| 324 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // If we enforce the expiration date check that is does not exceed |
|
| 328 | - if ($isEnforced) { |
|
| 329 | - if (empty($expirationDate)) { |
|
| 330 | - throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 334 | - $date->setTime(0, 0, 0); |
|
| 335 | - $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); |
|
| 336 | - if ($date < $expirationDate) { |
|
| 337 | - throw new GenericShareException($this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays), code: 404); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $accepted = true; |
|
| 343 | - $message = ''; |
|
| 344 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 345 | - 'expirationDate' => &$expirationDate, |
|
| 346 | - 'accepted' => &$accepted, |
|
| 347 | - 'message' => &$message, |
|
| 348 | - 'passwordSet' => $share->getPassword() !== null, |
|
| 349 | - ]); |
|
| 350 | - |
|
| 351 | - if (!$accepted) { |
|
| 352 | - throw new \Exception($message); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - $share->setExpirationDate($expirationDate); |
|
| 356 | - |
|
| 357 | - return $share; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Validate if the expiration date fits the system settings |
|
| 362 | - * |
|
| 363 | - * @param IShare $share The share to validate the expiration date of |
|
| 364 | - * @return IShare The modified share object |
|
| 365 | - * @throws GenericShareException |
|
| 366 | - * @throws \InvalidArgumentException |
|
| 367 | - * @throws \Exception |
|
| 368 | - */ |
|
| 369 | - protected function validateExpirationDateLink(IShare $share) { |
|
| 370 | - $expirationDate = $share->getExpirationDate(); |
|
| 371 | - $isEnforced = $this->shareApiLinkDefaultExpireDateEnforced(); |
|
| 372 | - |
|
| 373 | - // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced |
|
| 374 | - // Then skip expiration date validation as null is accepted |
|
| 375 | - if (!($share->getNoExpirationDate() && !$isEnforced)) { |
|
| 376 | - if ($expirationDate !== null) { |
|
| 377 | - $expirationDate->setTimezone($this->dateTimeZone->getTimeZone()); |
|
| 378 | - $expirationDate->setTime(0, 0, 0); |
|
| 379 | - |
|
| 380 | - $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 381 | - $date->setTime(0, 0, 0); |
|
| 382 | - if ($date >= $expirationDate) { |
|
| 383 | - throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // If expiredate is empty set a default one if there is a default |
|
| 388 | - $fullId = null; |
|
| 389 | - try { |
|
| 390 | - $fullId = $share->getFullId(); |
|
| 391 | - } catch (\UnexpectedValueException $e) { |
|
| 392 | - // This is a new share |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 396 | - $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 397 | - $expirationDate->setTime(0, 0, 0); |
|
| 398 | - |
|
| 399 | - $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays()); |
|
| 400 | - if ($days > $this->shareApiLinkDefaultExpireDays()) { |
|
| 401 | - $days = $this->shareApiLinkDefaultExpireDays(); |
|
| 402 | - } |
|
| 403 | - $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // If we enforce the expiration date check that is does not exceed |
|
| 407 | - if ($isEnforced) { |
|
| 408 | - if (empty($expirationDate)) { |
|
| 409 | - throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 413 | - $date->setTime(0, 0, 0); |
|
| 414 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 415 | - if ($date < $expirationDate) { |
|
| 416 | - throw new GenericShareException( |
|
| 417 | - $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()), |
|
| 418 | - code: 404, |
|
| 419 | - ); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - $accepted = true; |
|
| 426 | - $message = ''; |
|
| 427 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 428 | - 'expirationDate' => &$expirationDate, |
|
| 429 | - 'accepted' => &$accepted, |
|
| 430 | - 'message' => &$message, |
|
| 431 | - 'passwordSet' => $share->getPassword() !== null, |
|
| 432 | - ]); |
|
| 433 | - |
|
| 434 | - if (!$accepted) { |
|
| 435 | - throw new \Exception($message); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $share->setExpirationDate($expirationDate); |
|
| 439 | - |
|
| 440 | - return $share; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Check for pre share requirements for user shares |
|
| 445 | - * |
|
| 446 | - * @param IShare $share |
|
| 447 | - * @throws \Exception |
|
| 448 | - */ |
|
| 449 | - protected function userCreateChecks(IShare $share) { |
|
| 450 | - // Check if we can share with group members only |
|
| 451 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 452 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 453 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 454 | - // Verify we can share with this user |
|
| 455 | - $groups = array_intersect( |
|
| 456 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
| 457 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
| 458 | - ); |
|
| 459 | - |
|
| 460 | - // optional excluded groups |
|
| 461 | - $excludedGroups = $this->shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 462 | - $groups = array_diff($groups, $excludedGroups); |
|
| 463 | - |
|
| 464 | - if (empty($groups)) { |
|
| 465 | - throw new \Exception($this->l->t('Sharing is only allowed with group members')); |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /* |
|
| 63 | + private ?IL10N $l; |
|
| 64 | + private LegacyHooks $legacyHooks; |
|
| 65 | + |
|
| 66 | + public function __construct( |
|
| 67 | + private LoggerInterface $logger, |
|
| 68 | + private IConfig $config, |
|
| 69 | + private ISecureRandom $secureRandom, |
|
| 70 | + private IHasher $hasher, |
|
| 71 | + private IMountManager $mountManager, |
|
| 72 | + private IGroupManager $groupManager, |
|
| 73 | + private IFactory $l10nFactory, |
|
| 74 | + private IProviderFactory $factory, |
|
| 75 | + private IUserManager $userManager, |
|
| 76 | + private IRootFolder $rootFolder, |
|
| 77 | + private IMailer $mailer, |
|
| 78 | + private IURLGenerator $urlGenerator, |
|
| 79 | + private \OC_Defaults $defaults, |
|
| 80 | + private IEventDispatcher $dispatcher, |
|
| 81 | + private IUserSession $userSession, |
|
| 82 | + private KnownUserService $knownUserService, |
|
| 83 | + private ShareDisableChecker $shareDisableChecker, |
|
| 84 | + private IDateTimeZone $dateTimeZone, |
|
| 85 | + private IAppConfig $appConfig, |
|
| 86 | + ) { |
|
| 87 | + $this->l = $this->l10nFactory->get('lib'); |
|
| 88 | + // The constructor of LegacyHooks registers the listeners of share events |
|
| 89 | + // do not remove if those are not properly migrated |
|
| 90 | + $this->legacyHooks = new LegacyHooks($this->dispatcher); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
| 95 | + * |
|
| 96 | + * @param string $id |
|
| 97 | + * @return string[] |
|
| 98 | + */ |
|
| 99 | + private function splitFullId($id) { |
|
| 100 | + return explode(':', $id, 2); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Verify if a password meets all requirements |
|
| 105 | + * |
|
| 106 | + * @param string $password |
|
| 107 | + * @throws HintException |
|
| 108 | + */ |
|
| 109 | + protected function verifyPassword($password) { |
|
| 110 | + if ($password === null) { |
|
| 111 | + // No password is set, check if this is allowed. |
|
| 112 | + if ($this->shareApiLinkEnforcePassword()) { |
|
| 113 | + throw new \InvalidArgumentException($this->l->t('Passwords are enforced for link and mail shares')); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Let others verify the password |
|
| 120 | + try { |
|
| 121 | + $event = new ValidatePasswordPolicyEvent($password, PasswordContext::SHARING); |
|
| 122 | + $this->dispatcher->dispatchTyped($event); |
|
| 123 | + } catch (HintException $e) { |
|
| 124 | + /* Wrap in a 400 bad request error */ |
|
| 125 | + throw new HintException($e->getMessage(), $e->getHint(), 400, $e); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Check for generic requirements before creating a share |
|
| 131 | + * |
|
| 132 | + * @param IShare $share |
|
| 133 | + * @throws \InvalidArgumentException |
|
| 134 | + * @throws GenericShareException |
|
| 135 | + * |
|
| 136 | + * @suppress PhanUndeclaredClassMethod |
|
| 137 | + */ |
|
| 138 | + protected function generalCreateChecks(IShare $share, bool $isUpdate = false) { |
|
| 139 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 140 | + // We expect a valid user as sharedWith for user shares |
|
| 141 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
| 142 | + throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid user')); |
|
| 143 | + } |
|
| 144 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 145 | + // We expect a valid group as sharedWith for group shares |
|
| 146 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
| 147 | + throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid group')); |
|
| 148 | + } |
|
| 149 | + } elseif ($share->getShareType() === IShare::TYPE_LINK) { |
|
| 150 | + // No check for TYPE_EMAIL here as we have a recipient for them |
|
| 151 | + if ($share->getSharedWith() !== null) { |
|
| 152 | + throw new \InvalidArgumentException($this->l->t('Share recipient should be empty')); |
|
| 153 | + } |
|
| 154 | + } elseif ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 155 | + if ($share->getSharedWith() === null) { |
|
| 156 | + throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 157 | + } |
|
| 158 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE) { |
|
| 159 | + if ($share->getSharedWith() === null) { |
|
| 160 | + throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 161 | + } |
|
| 162 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 163 | + if ($share->getSharedWith() === null) { |
|
| 164 | + throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty')); |
|
| 165 | + } |
|
| 166 | + } elseif ($share->getShareType() === IShare::TYPE_CIRCLE) { |
|
| 167 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
| 168 | + if ($circle === null) { |
|
| 169 | + throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid circle')); |
|
| 170 | + } |
|
| 171 | + } elseif ($share->getShareType() === IShare::TYPE_ROOM) { |
|
| 172 | + } elseif ($share->getShareType() === IShare::TYPE_DECK) { |
|
| 173 | + } elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) { |
|
| 174 | + } else { |
|
| 175 | + // We cannot handle other types yet |
|
| 176 | + throw new \InvalidArgumentException($this->l->t('Unknown share type')); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Verify the initiator of the share is set |
|
| 180 | + if ($share->getSharedBy() === null) { |
|
| 181 | + throw new \InvalidArgumentException($this->l->t('Share initiator must be set')); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // Cannot share with yourself |
|
| 185 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
| 186 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
| 187 | + throw new \InvalidArgumentException($this->l->t('Cannot share with yourself')); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // The path should be set |
|
| 191 | + if ($share->getNode() === null) { |
|
| 192 | + throw new \InvalidArgumentException($this->l->t('Shared path must be set')); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // And it should be a file or a folder |
|
| 196 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
| 197 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 198 | + throw new \InvalidArgumentException($this->l->t('Shared path must be either a file or a folder')); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // And you cannot share your rootfolder |
|
| 202 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
| 203 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 204 | + } else { |
|
| 205 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 206 | + } |
|
| 207 | + if ($userFolder->getId() === $share->getNode()->getId()) { |
|
| 208 | + throw new \InvalidArgumentException($this->l->t('You cannot share your root folder')); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // Check if we actually have share permissions |
|
| 212 | + if (!$share->getNode()->isShareable()) { |
|
| 213 | + throw new GenericShareException($this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]), code: 404); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // Permissions should be set |
|
| 217 | + if ($share->getPermissions() === null) { |
|
| 218 | + throw new \InvalidArgumentException($this->l->t('Valid permissions are required for sharing')); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // Permissions must be valid |
|
| 222 | + if ($share->getPermissions() < 0 || $share->getPermissions() > \OCP\Constants::PERMISSION_ALL) { |
|
| 223 | + throw new \InvalidArgumentException($this->l->t('Valid permissions are required for sharing')); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Single file shares should never have delete or create permissions |
|
| 227 | + if (($share->getNode() instanceof File) |
|
| 228 | + && (($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE)) !== 0)) { |
|
| 229 | + throw new \InvalidArgumentException($this->l->t('File shares cannot have create or delete permissions')); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $permissions = 0; |
|
| 233 | + $nodesForUser = $userFolder->getById($share->getNodeId()); |
|
| 234 | + foreach ($nodesForUser as $node) { |
|
| 235 | + if ($node->getInternalPath() === '' && !$node->getMountPoint() instanceof MoveableMount) { |
|
| 236 | + // for the root of non-movable mount, the permissions we see if limited by the mount itself, |
|
| 237 | + // so we instead use the "raw" permissions from the storage |
|
| 238 | + $permissions |= $node->getStorage()->getPermissions(''); |
|
| 239 | + } else { |
|
| 240 | + $permissions |= $node->getPermissions(); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Check that we do not share with more permissions than we have |
|
| 245 | + if ($share->getPermissions() & ~$permissions) { |
|
| 246 | + $path = $userFolder->getRelativePath($share->getNode()->getPath()); |
|
| 247 | + throw new GenericShareException($this->l->t('Cannot increase permissions of %s', [$path]), code: 404); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // Check that read permissions are always set |
|
| 251 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
| 252 | + $noReadPermissionRequired = $share->getShareType() === IShare::TYPE_LINK |
|
| 253 | + || $share->getShareType() === IShare::TYPE_EMAIL; |
|
| 254 | + if (!$noReadPermissionRequired && |
|
| 255 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
| 256 | + throw new \InvalidArgumentException($this->l->t('Shares need at least read permissions')); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
| 260 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 261 | + throw new GenericShareException($this->l->t('Files cannot be shared with delete permissions')); |
|
| 262 | + } |
|
| 263 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 264 | + throw new GenericShareException($this->l->t('Files cannot be shared with create permissions')); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Validate if the expiration date fits the system settings |
|
| 271 | + * |
|
| 272 | + * @param IShare $share The share to validate the expiration date of |
|
| 273 | + * @return IShare The modified share object |
|
| 274 | + * @throws GenericShareException |
|
| 275 | + * @throws \InvalidArgumentException |
|
| 276 | + * @throws \Exception |
|
| 277 | + */ |
|
| 278 | + protected function validateExpirationDateInternal(IShare $share) { |
|
| 279 | + $isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP; |
|
| 280 | + |
|
| 281 | + $expirationDate = $share->getExpirationDate(); |
|
| 282 | + |
|
| 283 | + if ($isRemote) { |
|
| 284 | + $defaultExpireDate = $this->shareApiRemoteDefaultExpireDate(); |
|
| 285 | + $defaultExpireDays = $this->shareApiRemoteDefaultExpireDays(); |
|
| 286 | + $configProp = 'remote_defaultExpDays'; |
|
| 287 | + $isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced(); |
|
| 288 | + } else { |
|
| 289 | + $defaultExpireDate = $this->shareApiInternalDefaultExpireDate(); |
|
| 290 | + $defaultExpireDays = $this->shareApiInternalDefaultExpireDays(); |
|
| 291 | + $configProp = 'internal_defaultExpDays'; |
|
| 292 | + $isEnforced = $this->shareApiInternalDefaultExpireDateEnforced(); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced |
|
| 296 | + // Then skip expiration date validation as null is accepted |
|
| 297 | + if (!$share->getNoExpirationDate() || $isEnforced) { |
|
| 298 | + if ($expirationDate !== null) { |
|
| 299 | + $expirationDate->setTimezone($this->dateTimeZone->getTimeZone()); |
|
| 300 | + $expirationDate->setTime(0, 0, 0); |
|
| 301 | + |
|
| 302 | + $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 303 | + $date->setTime(0, 0, 0); |
|
| 304 | + if ($date >= $expirationDate) { |
|
| 305 | + throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // If expiredate is empty set a default one if there is a default |
|
| 310 | + $fullId = null; |
|
| 311 | + try { |
|
| 312 | + $fullId = $share->getFullId(); |
|
| 313 | + } catch (\UnexpectedValueException $e) { |
|
| 314 | + // This is a new share |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if ($fullId === null && $expirationDate === null && $defaultExpireDate) { |
|
| 318 | + $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 319 | + $expirationDate->setTime(0, 0, 0); |
|
| 320 | + $days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays); |
|
| 321 | + if ($days > $defaultExpireDays) { |
|
| 322 | + $days = $defaultExpireDays; |
|
| 323 | + } |
|
| 324 | + $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // If we enforce the expiration date check that is does not exceed |
|
| 328 | + if ($isEnforced) { |
|
| 329 | + if (empty($expirationDate)) { |
|
| 330 | + throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 334 | + $date->setTime(0, 0, 0); |
|
| 335 | + $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); |
|
| 336 | + if ($date < $expirationDate) { |
|
| 337 | + throw new GenericShareException($this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays), code: 404); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $accepted = true; |
|
| 343 | + $message = ''; |
|
| 344 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 345 | + 'expirationDate' => &$expirationDate, |
|
| 346 | + 'accepted' => &$accepted, |
|
| 347 | + 'message' => &$message, |
|
| 348 | + 'passwordSet' => $share->getPassword() !== null, |
|
| 349 | + ]); |
|
| 350 | + |
|
| 351 | + if (!$accepted) { |
|
| 352 | + throw new \Exception($message); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + $share->setExpirationDate($expirationDate); |
|
| 356 | + |
|
| 357 | + return $share; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Validate if the expiration date fits the system settings |
|
| 362 | + * |
|
| 363 | + * @param IShare $share The share to validate the expiration date of |
|
| 364 | + * @return IShare The modified share object |
|
| 365 | + * @throws GenericShareException |
|
| 366 | + * @throws \InvalidArgumentException |
|
| 367 | + * @throws \Exception |
|
| 368 | + */ |
|
| 369 | + protected function validateExpirationDateLink(IShare $share) { |
|
| 370 | + $expirationDate = $share->getExpirationDate(); |
|
| 371 | + $isEnforced = $this->shareApiLinkDefaultExpireDateEnforced(); |
|
| 372 | + |
|
| 373 | + // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced |
|
| 374 | + // Then skip expiration date validation as null is accepted |
|
| 375 | + if (!($share->getNoExpirationDate() && !$isEnforced)) { |
|
| 376 | + if ($expirationDate !== null) { |
|
| 377 | + $expirationDate->setTimezone($this->dateTimeZone->getTimeZone()); |
|
| 378 | + $expirationDate->setTime(0, 0, 0); |
|
| 379 | + |
|
| 380 | + $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 381 | + $date->setTime(0, 0, 0); |
|
| 382 | + if ($date >= $expirationDate) { |
|
| 383 | + throw new GenericShareException($this->l->t('Expiration date is in the past'), code: 404); |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // If expiredate is empty set a default one if there is a default |
|
| 388 | + $fullId = null; |
|
| 389 | + try { |
|
| 390 | + $fullId = $share->getFullId(); |
|
| 391 | + } catch (\UnexpectedValueException $e) { |
|
| 392 | + // This is a new share |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
| 396 | + $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 397 | + $expirationDate->setTime(0, 0, 0); |
|
| 398 | + |
|
| 399 | + $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays()); |
|
| 400 | + if ($days > $this->shareApiLinkDefaultExpireDays()) { |
|
| 401 | + $days = $this->shareApiLinkDefaultExpireDays(); |
|
| 402 | + } |
|
| 403 | + $expirationDate->add(new \DateInterval('P' . $days . 'D')); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // If we enforce the expiration date check that is does not exceed |
|
| 407 | + if ($isEnforced) { |
|
| 408 | + if (empty($expirationDate)) { |
|
| 409 | + throw new \InvalidArgumentException($this->l->t('Expiration date is enforced')); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $date = new \DateTime('now', $this->dateTimeZone->getTimeZone()); |
|
| 413 | + $date->setTime(0, 0, 0); |
|
| 414 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
| 415 | + if ($date < $expirationDate) { |
|
| 416 | + throw new GenericShareException( |
|
| 417 | + $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()), |
|
| 418 | + code: 404, |
|
| 419 | + ); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + $accepted = true; |
|
| 426 | + $message = ''; |
|
| 427 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
| 428 | + 'expirationDate' => &$expirationDate, |
|
| 429 | + 'accepted' => &$accepted, |
|
| 430 | + 'message' => &$message, |
|
| 431 | + 'passwordSet' => $share->getPassword() !== null, |
|
| 432 | + ]); |
|
| 433 | + |
|
| 434 | + if (!$accepted) { |
|
| 435 | + throw new \Exception($message); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $share->setExpirationDate($expirationDate); |
|
| 439 | + |
|
| 440 | + return $share; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Check for pre share requirements for user shares |
|
| 445 | + * |
|
| 446 | + * @param IShare $share |
|
| 447 | + * @throws \Exception |
|
| 448 | + */ |
|
| 449 | + protected function userCreateChecks(IShare $share) { |
|
| 450 | + // Check if we can share with group members only |
|
| 451 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 452 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 453 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 454 | + // Verify we can share with this user |
|
| 455 | + $groups = array_intersect( |
|
| 456 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
| 457 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
| 458 | + ); |
|
| 459 | + |
|
| 460 | + // optional excluded groups |
|
| 461 | + $excludedGroups = $this->shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 462 | + $groups = array_diff($groups, $excludedGroups); |
|
| 463 | + |
|
| 464 | + if (empty($groups)) { |
|
| 465 | + throw new \Exception($this->l->t('Sharing is only allowed with group members')); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /* |
|
| 470 | 470 | * TODO: Could be costly, fix |
| 471 | 471 | * |
| 472 | 472 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 473 | 473 | */ |
| 474 | - $provider = $this->factory->getProviderForType(IShare::TYPE_USER); |
|
| 475 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 476 | - foreach ($existingShares as $existingShare) { |
|
| 477 | - // Ignore if it is the same share |
|
| 478 | - try { |
|
| 479 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 480 | - continue; |
|
| 481 | - } |
|
| 482 | - } catch (\UnexpectedValueException $e) { |
|
| 483 | - //Shares are not identical |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // Identical share already exists |
|
| 487 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 488 | - throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - // The share is already shared with this user via a group share |
|
| 492 | - if ($existingShare->getShareType() === IShare::TYPE_GROUP) { |
|
| 493 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 494 | - if (!is_null($group)) { |
|
| 495 | - $user = $this->userManager->get($share->getSharedWith()); |
|
| 496 | - |
|
| 497 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 498 | - throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Check for pre share requirements for group shares |
|
| 507 | - * |
|
| 508 | - * @param IShare $share |
|
| 509 | - * @throws \Exception |
|
| 510 | - */ |
|
| 511 | - protected function groupCreateChecks(IShare $share) { |
|
| 512 | - // Verify group shares are allowed |
|
| 513 | - if (!$this->allowGroupSharing()) { |
|
| 514 | - throw new \Exception($this->l->t('Group sharing is now allowed')); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - // Verify if the user can share with this group |
|
| 518 | - if ($this->shareWithGroupMembersOnly()) { |
|
| 519 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 520 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 521 | - |
|
| 522 | - // optional excluded groups |
|
| 523 | - $excludedGroups = $this->shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 524 | - if (is_null($sharedWith) || in_array($share->getSharedWith(), $excludedGroups) || !$sharedWith->inGroup($sharedBy)) { |
|
| 525 | - throw new \Exception($this->l->t('Sharing is only allowed within your own groups')); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /* |
|
| 474 | + $provider = $this->factory->getProviderForType(IShare::TYPE_USER); |
|
| 475 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 476 | + foreach ($existingShares as $existingShare) { |
|
| 477 | + // Ignore if it is the same share |
|
| 478 | + try { |
|
| 479 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 480 | + continue; |
|
| 481 | + } |
|
| 482 | + } catch (\UnexpectedValueException $e) { |
|
| 483 | + //Shares are not identical |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // Identical share already exists |
|
| 487 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 488 | + throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + // The share is already shared with this user via a group share |
|
| 492 | + if ($existingShare->getShareType() === IShare::TYPE_GROUP) { |
|
| 493 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
| 494 | + if (!is_null($group)) { |
|
| 495 | + $user = $this->userManager->get($share->getSharedWith()); |
|
| 496 | + |
|
| 497 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
| 498 | + throw new AlreadySharedException($this->l->t('Sharing %s failed, because this item is already shared with the account %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]), $existingShare); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Check for pre share requirements for group shares |
|
| 507 | + * |
|
| 508 | + * @param IShare $share |
|
| 509 | + * @throws \Exception |
|
| 510 | + */ |
|
| 511 | + protected function groupCreateChecks(IShare $share) { |
|
| 512 | + // Verify group shares are allowed |
|
| 513 | + if (!$this->allowGroupSharing()) { |
|
| 514 | + throw new \Exception($this->l->t('Group sharing is now allowed')); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + // Verify if the user can share with this group |
|
| 518 | + if ($this->shareWithGroupMembersOnly()) { |
|
| 519 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 520 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 521 | + |
|
| 522 | + // optional excluded groups |
|
| 523 | + $excludedGroups = $this->shareWithGroupMembersOnlyExcludeGroupsList(); |
|
| 524 | + if (is_null($sharedWith) || in_array($share->getSharedWith(), $excludedGroups) || !$sharedWith->inGroup($sharedBy)) { |
|
| 525 | + throw new \Exception($this->l->t('Sharing is only allowed within your own groups')); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /* |
|
| 530 | 530 | * TODO: Could be costly, fix |
| 531 | 531 | * |
| 532 | 532 | * Also this is not what we want in the future.. then we want to squash identical shares. |
| 533 | 533 | */ |
| 534 | - $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
| 535 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 536 | - foreach ($existingShares as $existingShare) { |
|
| 537 | - try { |
|
| 538 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 539 | - continue; |
|
| 540 | - } |
|
| 541 | - } catch (\UnexpectedValueException $e) { |
|
| 542 | - //It is a new share so just continue |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 546 | - throw new AlreadySharedException($this->l->t('Path is already shared with this group'), $existingShare); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Check for pre share requirements for link shares |
|
| 553 | - * |
|
| 554 | - * @param IShare $share |
|
| 555 | - * @throws \Exception |
|
| 556 | - */ |
|
| 557 | - protected function linkCreateChecks(IShare $share) { |
|
| 558 | - // Are link shares allowed? |
|
| 559 | - if (!$this->shareApiAllowLinks()) { |
|
| 560 | - throw new \Exception($this->l->t('Link sharing is not allowed')); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - // Check if public upload is allowed |
|
| 564 | - if ($share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload() && |
|
| 565 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 566 | - throw new \InvalidArgumentException($this->l->t('Public upload is not allowed')); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * To make sure we don't get invisible link shares we set the parent |
|
| 572 | - * of a link if it is a reshare. This is a quick word around |
|
| 573 | - * until we can properly display multiple link shares in the UI |
|
| 574 | - * |
|
| 575 | - * See: https://github.com/owncloud/core/issues/22295 |
|
| 576 | - * |
|
| 577 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
| 578 | - * |
|
| 579 | - * @param IShare $share |
|
| 580 | - */ |
|
| 581 | - protected function setLinkParent(IShare $share) { |
|
| 582 | - // No sense in checking if the method is not there. |
|
| 583 | - if (method_exists($share, 'setParent')) { |
|
| 584 | - $storage = $share->getNode()->getStorage(); |
|
| 585 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 586 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 587 | - $share->setParent($storage->getShareId()); |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * @param File|Folder $path |
|
| 594 | - */ |
|
| 595 | - protected function pathCreateChecks($path) { |
|
| 596 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
| 597 | - if ($path instanceof \OCP\Files\Folder) { |
|
| 598 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 599 | - foreach ($mounts as $mount) { |
|
| 600 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 601 | - // Using a flat sharing model ensures the file owner can always see who has access. |
|
| 602 | - // Allowing parent folder sharing would require tracking inherited access, which adds complexity |
|
| 603 | - // and hurts performance/scalability. |
|
| 604 | - // So we forbid sharing a parent folder of a share you received. |
|
| 605 | - throw new \InvalidArgumentException($this->l->t('You cannot share a folder that contains other shares')); |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Check if the user that is sharing can actually share |
|
| 613 | - * |
|
| 614 | - * @param IShare $share |
|
| 615 | - * @throws \Exception |
|
| 616 | - */ |
|
| 617 | - protected function canShare(IShare $share) { |
|
| 618 | - if (!$this->shareApiEnabled()) { |
|
| 619 | - throw new \Exception($this->l->t('Sharing is disabled')); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 623 | - throw new \Exception($this->l->t('Sharing is disabled for you')); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Share a path |
|
| 629 | - * |
|
| 630 | - * @param IShare $share |
|
| 631 | - * @return IShare The share object |
|
| 632 | - * @throws \Exception |
|
| 633 | - * |
|
| 634 | - * TODO: handle link share permissions or check them |
|
| 635 | - */ |
|
| 636 | - public function createShare(IShare $share) { |
|
| 637 | - $this->canShare($share); |
|
| 638 | - |
|
| 639 | - $this->generalCreateChecks($share); |
|
| 640 | - |
|
| 641 | - // Verify if there are any issues with the path |
|
| 642 | - $this->pathCreateChecks($share->getNode()); |
|
| 643 | - |
|
| 644 | - /* |
|
| 534 | + $provider = $this->factory->getProviderForType(IShare::TYPE_GROUP); |
|
| 535 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
| 536 | + foreach ($existingShares as $existingShare) { |
|
| 537 | + try { |
|
| 538 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
| 539 | + continue; |
|
| 540 | + } |
|
| 541 | + } catch (\UnexpectedValueException $e) { |
|
| 542 | + //It is a new share so just continue |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) { |
|
| 546 | + throw new AlreadySharedException($this->l->t('Path is already shared with this group'), $existingShare); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Check for pre share requirements for link shares |
|
| 553 | + * |
|
| 554 | + * @param IShare $share |
|
| 555 | + * @throws \Exception |
|
| 556 | + */ |
|
| 557 | + protected function linkCreateChecks(IShare $share) { |
|
| 558 | + // Are link shares allowed? |
|
| 559 | + if (!$this->shareApiAllowLinks()) { |
|
| 560 | + throw new \Exception($this->l->t('Link sharing is not allowed')); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + // Check if public upload is allowed |
|
| 564 | + if ($share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload() && |
|
| 565 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
| 566 | + throw new \InvalidArgumentException($this->l->t('Public upload is not allowed')); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * To make sure we don't get invisible link shares we set the parent |
|
| 572 | + * of a link if it is a reshare. This is a quick word around |
|
| 573 | + * until we can properly display multiple link shares in the UI |
|
| 574 | + * |
|
| 575 | + * See: https://github.com/owncloud/core/issues/22295 |
|
| 576 | + * |
|
| 577 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
| 578 | + * |
|
| 579 | + * @param IShare $share |
|
| 580 | + */ |
|
| 581 | + protected function setLinkParent(IShare $share) { |
|
| 582 | + // No sense in checking if the method is not there. |
|
| 583 | + if (method_exists($share, 'setParent')) { |
|
| 584 | + $storage = $share->getNode()->getStorage(); |
|
| 585 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 586 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 587 | + $share->setParent($storage->getShareId()); |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * @param File|Folder $path |
|
| 594 | + */ |
|
| 595 | + protected function pathCreateChecks($path) { |
|
| 596 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
| 597 | + if ($path instanceof \OCP\Files\Folder) { |
|
| 598 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
| 599 | + foreach ($mounts as $mount) { |
|
| 600 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
| 601 | + // Using a flat sharing model ensures the file owner can always see who has access. |
|
| 602 | + // Allowing parent folder sharing would require tracking inherited access, which adds complexity |
|
| 603 | + // and hurts performance/scalability. |
|
| 604 | + // So we forbid sharing a parent folder of a share you received. |
|
| 605 | + throw new \InvalidArgumentException($this->l->t('You cannot share a folder that contains other shares')); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Check if the user that is sharing can actually share |
|
| 613 | + * |
|
| 614 | + * @param IShare $share |
|
| 615 | + * @throws \Exception |
|
| 616 | + */ |
|
| 617 | + protected function canShare(IShare $share) { |
|
| 618 | + if (!$this->shareApiEnabled()) { |
|
| 619 | + throw new \Exception($this->l->t('Sharing is disabled')); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
| 623 | + throw new \Exception($this->l->t('Sharing is disabled for you')); |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Share a path |
|
| 629 | + * |
|
| 630 | + * @param IShare $share |
|
| 631 | + * @return IShare The share object |
|
| 632 | + * @throws \Exception |
|
| 633 | + * |
|
| 634 | + * TODO: handle link share permissions or check them |
|
| 635 | + */ |
|
| 636 | + public function createShare(IShare $share) { |
|
| 637 | + $this->canShare($share); |
|
| 638 | + |
|
| 639 | + $this->generalCreateChecks($share); |
|
| 640 | + |
|
| 641 | + // Verify if there are any issues with the path |
|
| 642 | + $this->pathCreateChecks($share->getNode()); |
|
| 643 | + |
|
| 644 | + /* |
|
| 645 | 645 | * On creation of a share the owner is always the owner of the path |
| 646 | 646 | * Except for mounted federated shares. |
| 647 | 647 | */ |
| 648 | - $storage = $share->getNode()->getStorage(); |
|
| 649 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 650 | - $parent = $share->getNode()->getParent(); |
|
| 651 | - while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 652 | - $parent = $parent->getParent(); |
|
| 653 | - } |
|
| 654 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 655 | - } else { |
|
| 656 | - if ($share->getNode()->getOwner()) { |
|
| 657 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 658 | - } else { |
|
| 659 | - $share->setShareOwner($share->getSharedBy()); |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - try { |
|
| 664 | - // Verify share type |
|
| 665 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 666 | - $this->userCreateChecks($share); |
|
| 667 | - |
|
| 668 | - // Verify the expiration date |
|
| 669 | - $share = $this->validateExpirationDateInternal($share); |
|
| 670 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 671 | - $this->groupCreateChecks($share); |
|
| 672 | - |
|
| 673 | - // Verify the expiration date |
|
| 674 | - $share = $this->validateExpirationDateInternal($share); |
|
| 675 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 676 | - // Verify the expiration date |
|
| 677 | - $share = $this->validateExpirationDateInternal($share); |
|
| 678 | - } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
| 679 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 680 | - $this->linkCreateChecks($share); |
|
| 681 | - $this->setLinkParent($share); |
|
| 682 | - |
|
| 683 | - $token = $this->generateToken(); |
|
| 684 | - // Set the unique token |
|
| 685 | - $share->setToken($token); |
|
| 686 | - |
|
| 687 | - // Verify the expiration date |
|
| 688 | - $share = $this->validateExpirationDateLink($share); |
|
| 689 | - |
|
| 690 | - // Verify the password |
|
| 691 | - $this->verifyPassword($share->getPassword()); |
|
| 692 | - |
|
| 693 | - // If a password is set. Hash it! |
|
| 694 | - if ($share->getShareType() === IShare::TYPE_LINK |
|
| 695 | - && $share->getPassword() !== null) { |
|
| 696 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - // Cannot share with the owner |
|
| 701 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
| 702 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 703 | - throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - // Generate the target |
|
| 707 | - $defaultShareFolder = $this->config->getSystemValue('share_folder', '/'); |
|
| 708 | - $allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true); |
|
| 709 | - if ($allowCustomShareFolder) { |
|
| 710 | - $shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $defaultShareFolder); |
|
| 711 | - } else { |
|
| 712 | - $shareFolder = $defaultShareFolder; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - $target = $shareFolder . '/' . $share->getNode()->getName(); |
|
| 716 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 717 | - $share->setTarget($target); |
|
| 718 | - |
|
| 719 | - // Pre share event |
|
| 720 | - $event = new Share\Events\BeforeShareCreatedEvent($share); |
|
| 721 | - $this->dispatcher->dispatchTyped($event); |
|
| 722 | - if ($event->isPropagationStopped() && $event->getError()) { |
|
| 723 | - throw new \Exception($event->getError()); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - $oldShare = $share; |
|
| 727 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 728 | - $share = $provider->create($share); |
|
| 729 | - |
|
| 730 | - // Reuse the node we already have |
|
| 731 | - $share->setNode($oldShare->getNode()); |
|
| 732 | - |
|
| 733 | - // Reset the target if it is null for the new share |
|
| 734 | - if ($share->getTarget() === '') { |
|
| 735 | - $share->setTarget($target); |
|
| 736 | - } |
|
| 737 | - } catch (AlreadySharedException $e) { |
|
| 738 | - // If a share for the same target already exists, dont create a new one, |
|
| 739 | - // but do trigger the hooks and notifications again |
|
| 740 | - $oldShare = $share; |
|
| 741 | - |
|
| 742 | - // Reuse the node we already have |
|
| 743 | - $share = $e->getExistingShare(); |
|
| 744 | - $share->setNode($oldShare->getNode()); |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - // Post share event |
|
| 748 | - $this->dispatcher->dispatchTyped(new ShareCreatedEvent($share)); |
|
| 749 | - |
|
| 750 | - // Send email if needed |
|
| 751 | - if ($this->config->getSystemValueBool('sharing.enable_share_mail', true)) { |
|
| 752 | - if ($share->getMailSend()) { |
|
| 753 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 754 | - if ($provider instanceof IShareProviderWithNotification) { |
|
| 755 | - $provider->sendMailNotification($share); |
|
| 756 | - } else { |
|
| 757 | - $this->logger->debug('Share notification not sent because the provider does not support it.', ['app' => 'share']); |
|
| 758 | - } |
|
| 759 | - } else { |
|
| 760 | - $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
| 761 | - } |
|
| 762 | - } else { |
|
| 763 | - $this->logger->debug('Share notification not sent because sharing notification emails is disabled.', ['app' => 'share']); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - return $share; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Update a share |
|
| 771 | - * |
|
| 772 | - * @param IShare $share |
|
| 773 | - * @return IShare The share object |
|
| 774 | - * @throws \InvalidArgumentException |
|
| 775 | - * @throws HintException |
|
| 776 | - */ |
|
| 777 | - public function updateShare(IShare $share, bool $onlyValid = true) { |
|
| 778 | - $expirationDateUpdated = false; |
|
| 779 | - |
|
| 780 | - $this->canShare($share); |
|
| 781 | - |
|
| 782 | - try { |
|
| 783 | - $originalShare = $this->getShareById($share->getFullId(), onlyValid: $onlyValid); |
|
| 784 | - } catch (\UnexpectedValueException $e) { |
|
| 785 | - throw new \InvalidArgumentException($this->l->t('Share does not have a full ID')); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - // We cannot change the share type! |
|
| 789 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 790 | - throw new \InvalidArgumentException($this->l->t('Cannot change share type')); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - // We can only change the recipient on user shares |
|
| 794 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 795 | - $share->getShareType() !== IShare::TYPE_USER) { |
|
| 796 | - throw new \InvalidArgumentException($this->l->t('Can only update recipient on user shares')); |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // Cannot share with the owner |
|
| 800 | - if ($share->getShareType() === IShare::TYPE_USER && |
|
| 801 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
| 802 | - throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - $this->generalCreateChecks($share, true); |
|
| 806 | - |
|
| 807 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 808 | - $this->userCreateChecks($share); |
|
| 809 | - |
|
| 810 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 811 | - // Verify the expiration date |
|
| 812 | - $this->validateExpirationDateInternal($share); |
|
| 813 | - $expirationDateUpdated = true; |
|
| 814 | - } |
|
| 815 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 816 | - $this->groupCreateChecks($share); |
|
| 817 | - |
|
| 818 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 819 | - // Verify the expiration date |
|
| 820 | - $this->validateExpirationDateInternal($share); |
|
| 821 | - $expirationDateUpdated = true; |
|
| 822 | - } |
|
| 823 | - } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
| 824 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 825 | - $this->linkCreateChecks($share); |
|
| 826 | - |
|
| 827 | - // The new password is not set again if it is the same as the old |
|
| 828 | - // one, unless when switching from sending by Talk to sending by |
|
| 829 | - // mail. |
|
| 830 | - $plainTextPassword = $share->getPassword(); |
|
| 831 | - $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Cannot enable the getSendPasswordByTalk if there is no password set |
|
| 835 | - */ |
|
| 836 | - if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { |
|
| 837 | - throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk with an empty password')); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * If we're in a mail share, we need to force a password change |
|
| 842 | - * as either the user is not aware of the password or is already (received by mail) |
|
| 843 | - * Thus the SendPasswordByTalk feature would not make sense |
|
| 844 | - */ |
|
| 845 | - if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 846 | - if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
| 847 | - throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk without setting a new password')); |
|
| 848 | - } |
|
| 849 | - if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { |
|
| 850 | - throw new \InvalidArgumentException($this->l->t('Cannot disable sending the password by Talk without setting a new password')); |
|
| 851 | - } |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 855 | - // Verify the expiration date |
|
| 856 | - $this->validateExpirationDateLink($share); |
|
| 857 | - $expirationDateUpdated = true; |
|
| 858 | - } |
|
| 859 | - } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 860 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 861 | - // Verify the expiration date |
|
| 862 | - $this->validateExpirationDateInternal($share); |
|
| 863 | - $expirationDateUpdated = true; |
|
| 864 | - } |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $this->pathCreateChecks($share->getNode()); |
|
| 868 | - |
|
| 869 | - // Now update the share! |
|
| 870 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 871 | - if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 872 | - $share = $provider->update($share, $plainTextPassword); |
|
| 873 | - } else { |
|
| 874 | - $share = $provider->update($share); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - if ($expirationDateUpdated === true) { |
|
| 878 | - \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
| 879 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 880 | - 'itemSource' => $share->getNode()->getId(), |
|
| 881 | - 'date' => $share->getExpirationDate(), |
|
| 882 | - 'uidOwner' => $share->getSharedBy(), |
|
| 883 | - ]); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 887 | - \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
| 888 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 889 | - 'itemSource' => $share->getNode()->getId(), |
|
| 890 | - 'uidOwner' => $share->getSharedBy(), |
|
| 891 | - 'token' => $share->getToken(), |
|
| 892 | - 'disabled' => is_null($share->getPassword()), |
|
| 893 | - ]); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 897 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 898 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 899 | - } else { |
|
| 900 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 901 | - } |
|
| 902 | - \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
| 903 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 904 | - 'itemSource' => $share->getNode()->getId(), |
|
| 905 | - 'shareType' => $share->getShareType(), |
|
| 906 | - 'shareWith' => $share->getSharedWith(), |
|
| 907 | - 'uidOwner' => $share->getSharedBy(), |
|
| 908 | - 'permissions' => $share->getPermissions(), |
|
| 909 | - 'attributes' => $share->getAttributes() !== null ? $share->getAttributes()->toArray() : null, |
|
| 910 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 911 | - ]); |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - return $share; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Accept a share. |
|
| 919 | - * |
|
| 920 | - * @param IShare $share |
|
| 921 | - * @param string $recipientId |
|
| 922 | - * @return IShare The share object |
|
| 923 | - * @throws \InvalidArgumentException Thrown if the provider does not implement `IShareProviderSupportsAccept` |
|
| 924 | - * @since 9.0.0 |
|
| 925 | - */ |
|
| 926 | - public function acceptShare(IShare $share, string $recipientId): IShare { |
|
| 927 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 928 | - $provider = $this->factory->getProvider($providerId); |
|
| 929 | - |
|
| 930 | - if (!($provider instanceof IShareProviderSupportsAccept)) { |
|
| 931 | - throw new \InvalidArgumentException($this->l->t('Share provider does not support accepting')); |
|
| 932 | - } |
|
| 933 | - /** @var IShareProvider&IShareProviderSupportsAccept $provider */ |
|
| 934 | - $provider->acceptShare($share, $recipientId); |
|
| 935 | - |
|
| 936 | - $event = new ShareAcceptedEvent($share); |
|
| 937 | - $this->dispatcher->dispatchTyped($event); |
|
| 938 | - |
|
| 939 | - return $share; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * Updates the password of the given share if it is not the same as the |
|
| 944 | - * password of the original share. |
|
| 945 | - * |
|
| 946 | - * @param IShare $share the share to update its password. |
|
| 947 | - * @param IShare $originalShare the original share to compare its |
|
| 948 | - * password with. |
|
| 949 | - * @return boolean whether the password was updated or not. |
|
| 950 | - */ |
|
| 951 | - private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShare) { |
|
| 952 | - $passwordsAreDifferent = ($share->getPassword() !== $originalShare->getPassword()) && |
|
| 953 | - (($share->getPassword() !== null && $originalShare->getPassword() === null) || |
|
| 954 | - ($share->getPassword() === null && $originalShare->getPassword() !== null) || |
|
| 955 | - ($share->getPassword() !== null && $originalShare->getPassword() !== null && |
|
| 956 | - !$this->hasher->verify($share->getPassword(), $originalShare->getPassword()))); |
|
| 957 | - |
|
| 958 | - // Password updated. |
|
| 959 | - if ($passwordsAreDifferent) { |
|
| 960 | - // Verify the password |
|
| 961 | - $this->verifyPassword($share->getPassword()); |
|
| 962 | - |
|
| 963 | - // If a password is set. Hash it! |
|
| 964 | - if (!empty($share->getPassword())) { |
|
| 965 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 966 | - if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 967 | - // Shares shared by email have temporary passwords |
|
| 968 | - $this->setSharePasswordExpirationTime($share); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - return true; |
|
| 972 | - } else { |
|
| 973 | - // Empty string and null are seen as NOT password protected |
|
| 974 | - $share->setPassword(null); |
|
| 975 | - if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 976 | - $share->setPasswordExpirationTime(null); |
|
| 977 | - } |
|
| 978 | - return true; |
|
| 979 | - } |
|
| 980 | - } else { |
|
| 981 | - // Reset the password to the original one, as it is either the same |
|
| 982 | - // as the "new" password or a hashed version of it. |
|
| 983 | - $share->setPassword($originalShare->getPassword()); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - return false; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Set the share's password expiration time |
|
| 991 | - */ |
|
| 992 | - private function setSharePasswordExpirationTime(IShare $share): void { |
|
| 993 | - if (!$this->config->getSystemValueBool('sharing.enable_mail_link_password_expiration', false)) { |
|
| 994 | - // Sets password expiration date to NULL |
|
| 995 | - $share->setPasswordExpirationTime(); |
|
| 996 | - return; |
|
| 997 | - } |
|
| 998 | - // Sets password expiration date |
|
| 999 | - $expirationTime = null; |
|
| 1000 | - $now = new \DateTime(); |
|
| 1001 | - $expirationInterval = $this->config->getSystemValue('sharing.mail_link_password_expiration_interval', 3600); |
|
| 1002 | - $expirationTime = $now->add(new \DateInterval('PT' . $expirationInterval . 'S')); |
|
| 1003 | - $share->setPasswordExpirationTime($expirationTime); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * Delete all the children of this share |
|
| 1009 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 1010 | - * |
|
| 1011 | - * @param IShare $share |
|
| 1012 | - * @return IShare[] List of deleted shares |
|
| 1013 | - */ |
|
| 1014 | - protected function deleteChildren(IShare $share) { |
|
| 1015 | - $deletedShares = []; |
|
| 1016 | - |
|
| 1017 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1018 | - |
|
| 1019 | - foreach ($provider->getChildren($share) as $child) { |
|
| 1020 | - $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($child)); |
|
| 1021 | - |
|
| 1022 | - $deletedChildren = $this->deleteChildren($child); |
|
| 1023 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 1024 | - |
|
| 1025 | - $provider->delete($child); |
|
| 1026 | - $this->dispatcher->dispatchTyped(new ShareDeletedEvent($child)); |
|
| 1027 | - $deletedShares[] = $child; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - return $deletedShares; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** Promote re-shares into direct shares so that target user keeps access */ |
|
| 1034 | - protected function promoteReshares(IShare $share): void { |
|
| 1035 | - try { |
|
| 1036 | - $node = $share->getNode(); |
|
| 1037 | - } catch (NotFoundException) { |
|
| 1038 | - /* Skip if node not found */ |
|
| 1039 | - return; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - $userIds = []; |
|
| 1043 | - |
|
| 1044 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 1045 | - $userIds[] = $share->getSharedWith(); |
|
| 1046 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 1047 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
| 1048 | - $users = $group?->getUsers() ?? []; |
|
| 1049 | - |
|
| 1050 | - foreach ($users as $user) { |
|
| 1051 | - /* Skip share owner */ |
|
| 1052 | - if ($user->getUID() === $share->getShareOwner() || $user->getUID() === $share->getSharedBy()) { |
|
| 1053 | - continue; |
|
| 1054 | - } |
|
| 1055 | - $userIds[] = $user->getUID(); |
|
| 1056 | - } |
|
| 1057 | - } else { |
|
| 1058 | - /* We only support user and group shares */ |
|
| 1059 | - return; |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - $reshareRecords = []; |
|
| 1063 | - $shareTypes = [ |
|
| 1064 | - IShare::TYPE_GROUP, |
|
| 1065 | - IShare::TYPE_USER, |
|
| 1066 | - IShare::TYPE_LINK, |
|
| 1067 | - IShare::TYPE_REMOTE, |
|
| 1068 | - IShare::TYPE_EMAIL, |
|
| 1069 | - ]; |
|
| 1070 | - |
|
| 1071 | - foreach ($userIds as $userId) { |
|
| 1072 | - foreach ($shareTypes as $shareType) { |
|
| 1073 | - try { |
|
| 1074 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 1075 | - } catch (ProviderException $e) { |
|
| 1076 | - continue; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - if ($node instanceof Folder) { |
|
| 1080 | - /* We need to get all shares by this user to get subshares */ |
|
| 1081 | - $shares = $provider->getSharesBy($userId, $shareType, null, false, -1, 0); |
|
| 1082 | - |
|
| 1083 | - foreach ($shares as $share) { |
|
| 1084 | - try { |
|
| 1085 | - $path = $share->getNode()->getPath(); |
|
| 1086 | - } catch (NotFoundException) { |
|
| 1087 | - /* Ignore share of non-existing node */ |
|
| 1088 | - continue; |
|
| 1089 | - } |
|
| 1090 | - if ($node->getRelativePath($path) !== null) { |
|
| 1091 | - /* If relative path is not null it means the shared node is the same or in a subfolder */ |
|
| 1092 | - $reshareRecords[] = $share; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } else { |
|
| 1096 | - $shares = $provider->getSharesBy($userId, $shareType, $node, false, -1, 0); |
|
| 1097 | - foreach ($shares as $child) { |
|
| 1098 | - $reshareRecords[] = $child; |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - foreach ($reshareRecords as $child) { |
|
| 1105 | - try { |
|
| 1106 | - /* Check if the share is still valid (means the resharer still has access to the file through another mean) */ |
|
| 1107 | - $this->generalCreateChecks($child); |
|
| 1108 | - } catch (GenericShareException $e) { |
|
| 1109 | - /* The check is invalid, promote it to a direct share from the sharer of parent share */ |
|
| 1110 | - $this->logger->debug('Promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); |
|
| 1111 | - try { |
|
| 1112 | - $child->setSharedBy($share->getSharedBy()); |
|
| 1113 | - $this->updateShare($child); |
|
| 1114 | - } catch (GenericShareException|\InvalidArgumentException $e) { |
|
| 1115 | - $this->logger->warning('Failed to promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); |
|
| 1116 | - } |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * Delete a share |
|
| 1123 | - * |
|
| 1124 | - * @param IShare $share |
|
| 1125 | - * @throws ShareNotFound |
|
| 1126 | - * @throws \InvalidArgumentException |
|
| 1127 | - */ |
|
| 1128 | - public function deleteShare(IShare $share) { |
|
| 1129 | - try { |
|
| 1130 | - $share->getFullId(); |
|
| 1131 | - } catch (\UnexpectedValueException $e) { |
|
| 1132 | - throw new \InvalidArgumentException($this->l->t('Share does not have a full ID')); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($share)); |
|
| 1136 | - |
|
| 1137 | - // Get all children and delete them as well |
|
| 1138 | - $this->deleteChildren($share); |
|
| 1139 | - |
|
| 1140 | - // Do the actual delete |
|
| 1141 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1142 | - $provider->delete($share); |
|
| 1143 | - |
|
| 1144 | - $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); |
|
| 1145 | - |
|
| 1146 | - // Promote reshares of the deleted share |
|
| 1147 | - $this->promoteReshares($share); |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Unshare a file as the recipient. |
|
| 1153 | - * This can be different from a regular delete for example when one of |
|
| 1154 | - * the users in a groups deletes that share. But the provider should |
|
| 1155 | - * handle this. |
|
| 1156 | - * |
|
| 1157 | - * @param IShare $share |
|
| 1158 | - * @param string $recipientId |
|
| 1159 | - */ |
|
| 1160 | - public function deleteFromSelf(IShare $share, $recipientId) { |
|
| 1161 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1162 | - $provider = $this->factory->getProvider($providerId); |
|
| 1163 | - |
|
| 1164 | - $provider->deleteFromSelf($share, $recipientId); |
|
| 1165 | - $event = new ShareDeletedFromSelfEvent($share); |
|
| 1166 | - $this->dispatcher->dispatchTyped($event); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - public function restoreShare(IShare $share, string $recipientId): IShare { |
|
| 1170 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1171 | - $provider = $this->factory->getProvider($providerId); |
|
| 1172 | - |
|
| 1173 | - return $provider->restore($share, $recipientId); |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * @inheritdoc |
|
| 1178 | - */ |
|
| 1179 | - public function moveShare(IShare $share, $recipientId) { |
|
| 1180 | - if ($share->getShareType() === IShare::TYPE_LINK |
|
| 1181 | - || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 1182 | - throw new \InvalidArgumentException($this->l->t('Cannot change target of link share')); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 1186 | - throw new \InvalidArgumentException($this->l->t('Invalid share recipient')); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - if ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 1190 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 1191 | - if (is_null($sharedWith)) { |
|
| 1192 | - throw new \InvalidArgumentException($this->l->t('Group "%s" does not exist', [$share->getSharedWith()])); |
|
| 1193 | - } |
|
| 1194 | - $recipient = $this->userManager->get($recipientId); |
|
| 1195 | - if (!$sharedWith->inGroup($recipient)) { |
|
| 1196 | - throw new \InvalidArgumentException($this->l->t('Invalid share recipient')); |
|
| 1197 | - } |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1201 | - $provider = $this->factory->getProvider($providerId); |
|
| 1202 | - |
|
| 1203 | - return $provider->move($share, $recipientId); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) { |
|
| 1207 | - $providers = $this->factory->getAllProviders(); |
|
| 1208 | - if (!$shallow) { |
|
| 1209 | - throw new \Exception('non-shallow getSharesInFolder is no longer supported'); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - $isOwnerless = $node->getMountPoint() instanceof IShareOwnerlessMount; |
|
| 1213 | - |
|
| 1214 | - $shares = []; |
|
| 1215 | - foreach ($providers as $provider) { |
|
| 1216 | - if ($isOwnerless) { |
|
| 1217 | - // If the provider does not implement the additional interface, |
|
| 1218 | - // we lack a performant way of querying all shares and therefore ignore the provider. |
|
| 1219 | - if ($provider instanceof IShareProviderSupportsAllSharesInFolder) { |
|
| 1220 | - foreach ($provider->getAllSharesInFolder($node) as $fid => $data) { |
|
| 1221 | - $shares[$fid] ??= []; |
|
| 1222 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - } else { |
|
| 1226 | - foreach ($provider->getSharesInFolder($userId, $node, $reshares) as $fid => $data) { |
|
| 1227 | - $shares[$fid] ??= []; |
|
| 1228 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - return $shares; |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * @inheritdoc |
|
| 1238 | - */ |
|
| 1239 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true) { |
|
| 1240 | - if ($path !== null && |
|
| 1241 | - !($path instanceof \OCP\Files\File) && |
|
| 1242 | - !($path instanceof \OCP\Files\Folder)) { |
|
| 1243 | - throw new \InvalidArgumentException($this->l->t('Invalid path')); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - try { |
|
| 1247 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 1248 | - } catch (ProviderException $e) { |
|
| 1249 | - return []; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - if ($path?->getMountPoint() instanceof IShareOwnerlessMount) { |
|
| 1253 | - $shares = array_filter($provider->getSharesByPath($path), static fn (IShare $share) => $share->getShareType() === $shareType); |
|
| 1254 | - } else { |
|
| 1255 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /* |
|
| 648 | + $storage = $share->getNode()->getStorage(); |
|
| 649 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 650 | + $parent = $share->getNode()->getParent(); |
|
| 651 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 652 | + $parent = $parent->getParent(); |
|
| 653 | + } |
|
| 654 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
| 655 | + } else { |
|
| 656 | + if ($share->getNode()->getOwner()) { |
|
| 657 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
| 658 | + } else { |
|
| 659 | + $share->setShareOwner($share->getSharedBy()); |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + try { |
|
| 664 | + // Verify share type |
|
| 665 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 666 | + $this->userCreateChecks($share); |
|
| 667 | + |
|
| 668 | + // Verify the expiration date |
|
| 669 | + $share = $this->validateExpirationDateInternal($share); |
|
| 670 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 671 | + $this->groupCreateChecks($share); |
|
| 672 | + |
|
| 673 | + // Verify the expiration date |
|
| 674 | + $share = $this->validateExpirationDateInternal($share); |
|
| 675 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 676 | + // Verify the expiration date |
|
| 677 | + $share = $this->validateExpirationDateInternal($share); |
|
| 678 | + } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
| 679 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 680 | + $this->linkCreateChecks($share); |
|
| 681 | + $this->setLinkParent($share); |
|
| 682 | + |
|
| 683 | + $token = $this->generateToken(); |
|
| 684 | + // Set the unique token |
|
| 685 | + $share->setToken($token); |
|
| 686 | + |
|
| 687 | + // Verify the expiration date |
|
| 688 | + $share = $this->validateExpirationDateLink($share); |
|
| 689 | + |
|
| 690 | + // Verify the password |
|
| 691 | + $this->verifyPassword($share->getPassword()); |
|
| 692 | + |
|
| 693 | + // If a password is set. Hash it! |
|
| 694 | + if ($share->getShareType() === IShare::TYPE_LINK |
|
| 695 | + && $share->getPassword() !== null) { |
|
| 696 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + // Cannot share with the owner |
|
| 701 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
| 702 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 703 | + throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + // Generate the target |
|
| 707 | + $defaultShareFolder = $this->config->getSystemValue('share_folder', '/'); |
|
| 708 | + $allowCustomShareFolder = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true); |
|
| 709 | + if ($allowCustomShareFolder) { |
|
| 710 | + $shareFolder = $this->config->getUserValue($share->getSharedWith(), Application::APP_ID, 'share_folder', $defaultShareFolder); |
|
| 711 | + } else { |
|
| 712 | + $shareFolder = $defaultShareFolder; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + $target = $shareFolder . '/' . $share->getNode()->getName(); |
|
| 716 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
| 717 | + $share->setTarget($target); |
|
| 718 | + |
|
| 719 | + // Pre share event |
|
| 720 | + $event = new Share\Events\BeforeShareCreatedEvent($share); |
|
| 721 | + $this->dispatcher->dispatchTyped($event); |
|
| 722 | + if ($event->isPropagationStopped() && $event->getError()) { |
|
| 723 | + throw new \Exception($event->getError()); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + $oldShare = $share; |
|
| 727 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 728 | + $share = $provider->create($share); |
|
| 729 | + |
|
| 730 | + // Reuse the node we already have |
|
| 731 | + $share->setNode($oldShare->getNode()); |
|
| 732 | + |
|
| 733 | + // Reset the target if it is null for the new share |
|
| 734 | + if ($share->getTarget() === '') { |
|
| 735 | + $share->setTarget($target); |
|
| 736 | + } |
|
| 737 | + } catch (AlreadySharedException $e) { |
|
| 738 | + // If a share for the same target already exists, dont create a new one, |
|
| 739 | + // but do trigger the hooks and notifications again |
|
| 740 | + $oldShare = $share; |
|
| 741 | + |
|
| 742 | + // Reuse the node we already have |
|
| 743 | + $share = $e->getExistingShare(); |
|
| 744 | + $share->setNode($oldShare->getNode()); |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + // Post share event |
|
| 748 | + $this->dispatcher->dispatchTyped(new ShareCreatedEvent($share)); |
|
| 749 | + |
|
| 750 | + // Send email if needed |
|
| 751 | + if ($this->config->getSystemValueBool('sharing.enable_share_mail', true)) { |
|
| 752 | + if ($share->getMailSend()) { |
|
| 753 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 754 | + if ($provider instanceof IShareProviderWithNotification) { |
|
| 755 | + $provider->sendMailNotification($share); |
|
| 756 | + } else { |
|
| 757 | + $this->logger->debug('Share notification not sent because the provider does not support it.', ['app' => 'share']); |
|
| 758 | + } |
|
| 759 | + } else { |
|
| 760 | + $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
| 761 | + } |
|
| 762 | + } else { |
|
| 763 | + $this->logger->debug('Share notification not sent because sharing notification emails is disabled.', ['app' => 'share']); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + return $share; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Update a share |
|
| 771 | + * |
|
| 772 | + * @param IShare $share |
|
| 773 | + * @return IShare The share object |
|
| 774 | + * @throws \InvalidArgumentException |
|
| 775 | + * @throws HintException |
|
| 776 | + */ |
|
| 777 | + public function updateShare(IShare $share, bool $onlyValid = true) { |
|
| 778 | + $expirationDateUpdated = false; |
|
| 779 | + |
|
| 780 | + $this->canShare($share); |
|
| 781 | + |
|
| 782 | + try { |
|
| 783 | + $originalShare = $this->getShareById($share->getFullId(), onlyValid: $onlyValid); |
|
| 784 | + } catch (\UnexpectedValueException $e) { |
|
| 785 | + throw new \InvalidArgumentException($this->l->t('Share does not have a full ID')); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + // We cannot change the share type! |
|
| 789 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
| 790 | + throw new \InvalidArgumentException($this->l->t('Cannot change share type')); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + // We can only change the recipient on user shares |
|
| 794 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
| 795 | + $share->getShareType() !== IShare::TYPE_USER) { |
|
| 796 | + throw new \InvalidArgumentException($this->l->t('Can only update recipient on user shares')); |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // Cannot share with the owner |
|
| 800 | + if ($share->getShareType() === IShare::TYPE_USER && |
|
| 801 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
| 802 | + throw new \InvalidArgumentException($this->l->t('Cannot share with the share owner')); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + $this->generalCreateChecks($share, true); |
|
| 806 | + |
|
| 807 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 808 | + $this->userCreateChecks($share); |
|
| 809 | + |
|
| 810 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 811 | + // Verify the expiration date |
|
| 812 | + $this->validateExpirationDateInternal($share); |
|
| 813 | + $expirationDateUpdated = true; |
|
| 814 | + } |
|
| 815 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 816 | + $this->groupCreateChecks($share); |
|
| 817 | + |
|
| 818 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 819 | + // Verify the expiration date |
|
| 820 | + $this->validateExpirationDateInternal($share); |
|
| 821 | + $expirationDateUpdated = true; |
|
| 822 | + } |
|
| 823 | + } elseif ($share->getShareType() === IShare::TYPE_LINK |
|
| 824 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 825 | + $this->linkCreateChecks($share); |
|
| 826 | + |
|
| 827 | + // The new password is not set again if it is the same as the old |
|
| 828 | + // one, unless when switching from sending by Talk to sending by |
|
| 829 | + // mail. |
|
| 830 | + $plainTextPassword = $share->getPassword(); |
|
| 831 | + $updatedPassword = $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Cannot enable the getSendPasswordByTalk if there is no password set |
|
| 835 | + */ |
|
| 836 | + if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) { |
|
| 837 | + throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk with an empty password')); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * If we're in a mail share, we need to force a password change |
|
| 842 | + * as either the user is not aware of the password or is already (received by mail) |
|
| 843 | + * Thus the SendPasswordByTalk feature would not make sense |
|
| 844 | + */ |
|
| 845 | + if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 846 | + if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
| 847 | + throw new \InvalidArgumentException($this->l->t('Cannot enable sending the password by Talk without setting a new password')); |
|
| 848 | + } |
|
| 849 | + if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) { |
|
| 850 | + throw new \InvalidArgumentException($this->l->t('Cannot disable sending the password by Talk without setting a new password')); |
|
| 851 | + } |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 855 | + // Verify the expiration date |
|
| 856 | + $this->validateExpirationDateLink($share); |
|
| 857 | + $expirationDateUpdated = true; |
|
| 858 | + } |
|
| 859 | + } elseif ($share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP) { |
|
| 860 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
| 861 | + // Verify the expiration date |
|
| 862 | + $this->validateExpirationDateInternal($share); |
|
| 863 | + $expirationDateUpdated = true; |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $this->pathCreateChecks($share->getNode()); |
|
| 868 | + |
|
| 869 | + // Now update the share! |
|
| 870 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 871 | + if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 872 | + $share = $provider->update($share, $plainTextPassword); |
|
| 873 | + } else { |
|
| 874 | + $share = $provider->update($share); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + if ($expirationDateUpdated === true) { |
|
| 878 | + \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
| 879 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 880 | + 'itemSource' => $share->getNode()->getId(), |
|
| 881 | + 'date' => $share->getExpirationDate(), |
|
| 882 | + 'uidOwner' => $share->getSharedBy(), |
|
| 883 | + ]); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
| 887 | + \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
| 888 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 889 | + 'itemSource' => $share->getNode()->getId(), |
|
| 890 | + 'uidOwner' => $share->getSharedBy(), |
|
| 891 | + 'token' => $share->getToken(), |
|
| 892 | + 'disabled' => is_null($share->getPassword()), |
|
| 893 | + ]); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
| 897 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
| 898 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
| 899 | + } else { |
|
| 900 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
| 901 | + } |
|
| 902 | + \OC_Hook::emit(Share::class, 'post_update_permissions', [ |
|
| 903 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
| 904 | + 'itemSource' => $share->getNode()->getId(), |
|
| 905 | + 'shareType' => $share->getShareType(), |
|
| 906 | + 'shareWith' => $share->getSharedWith(), |
|
| 907 | + 'uidOwner' => $share->getSharedBy(), |
|
| 908 | + 'permissions' => $share->getPermissions(), |
|
| 909 | + 'attributes' => $share->getAttributes() !== null ? $share->getAttributes()->toArray() : null, |
|
| 910 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
| 911 | + ]); |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + return $share; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Accept a share. |
|
| 919 | + * |
|
| 920 | + * @param IShare $share |
|
| 921 | + * @param string $recipientId |
|
| 922 | + * @return IShare The share object |
|
| 923 | + * @throws \InvalidArgumentException Thrown if the provider does not implement `IShareProviderSupportsAccept` |
|
| 924 | + * @since 9.0.0 |
|
| 925 | + */ |
|
| 926 | + public function acceptShare(IShare $share, string $recipientId): IShare { |
|
| 927 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 928 | + $provider = $this->factory->getProvider($providerId); |
|
| 929 | + |
|
| 930 | + if (!($provider instanceof IShareProviderSupportsAccept)) { |
|
| 931 | + throw new \InvalidArgumentException($this->l->t('Share provider does not support accepting')); |
|
| 932 | + } |
|
| 933 | + /** @var IShareProvider&IShareProviderSupportsAccept $provider */ |
|
| 934 | + $provider->acceptShare($share, $recipientId); |
|
| 935 | + |
|
| 936 | + $event = new ShareAcceptedEvent($share); |
|
| 937 | + $this->dispatcher->dispatchTyped($event); |
|
| 938 | + |
|
| 939 | + return $share; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * Updates the password of the given share if it is not the same as the |
|
| 944 | + * password of the original share. |
|
| 945 | + * |
|
| 946 | + * @param IShare $share the share to update its password. |
|
| 947 | + * @param IShare $originalShare the original share to compare its |
|
| 948 | + * password with. |
|
| 949 | + * @return boolean whether the password was updated or not. |
|
| 950 | + */ |
|
| 951 | + private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShare) { |
|
| 952 | + $passwordsAreDifferent = ($share->getPassword() !== $originalShare->getPassword()) && |
|
| 953 | + (($share->getPassword() !== null && $originalShare->getPassword() === null) || |
|
| 954 | + ($share->getPassword() === null && $originalShare->getPassword() !== null) || |
|
| 955 | + ($share->getPassword() !== null && $originalShare->getPassword() !== null && |
|
| 956 | + !$this->hasher->verify($share->getPassword(), $originalShare->getPassword()))); |
|
| 957 | + |
|
| 958 | + // Password updated. |
|
| 959 | + if ($passwordsAreDifferent) { |
|
| 960 | + // Verify the password |
|
| 961 | + $this->verifyPassword($share->getPassword()); |
|
| 962 | + |
|
| 963 | + // If a password is set. Hash it! |
|
| 964 | + if (!empty($share->getPassword())) { |
|
| 965 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
| 966 | + if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 967 | + // Shares shared by email have temporary passwords |
|
| 968 | + $this->setSharePasswordExpirationTime($share); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + return true; |
|
| 972 | + } else { |
|
| 973 | + // Empty string and null are seen as NOT password protected |
|
| 974 | + $share->setPassword(null); |
|
| 975 | + if ($share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 976 | + $share->setPasswordExpirationTime(null); |
|
| 977 | + } |
|
| 978 | + return true; |
|
| 979 | + } |
|
| 980 | + } else { |
|
| 981 | + // Reset the password to the original one, as it is either the same |
|
| 982 | + // as the "new" password or a hashed version of it. |
|
| 983 | + $share->setPassword($originalShare->getPassword()); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + return false; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Set the share's password expiration time |
|
| 991 | + */ |
|
| 992 | + private function setSharePasswordExpirationTime(IShare $share): void { |
|
| 993 | + if (!$this->config->getSystemValueBool('sharing.enable_mail_link_password_expiration', false)) { |
|
| 994 | + // Sets password expiration date to NULL |
|
| 995 | + $share->setPasswordExpirationTime(); |
|
| 996 | + return; |
|
| 997 | + } |
|
| 998 | + // Sets password expiration date |
|
| 999 | + $expirationTime = null; |
|
| 1000 | + $now = new \DateTime(); |
|
| 1001 | + $expirationInterval = $this->config->getSystemValue('sharing.mail_link_password_expiration_interval', 3600); |
|
| 1002 | + $expirationTime = $now->add(new \DateInterval('PT' . $expirationInterval . 'S')); |
|
| 1003 | + $share->setPasswordExpirationTime($expirationTime); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Delete all the children of this share |
|
| 1009 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
| 1010 | + * |
|
| 1011 | + * @param IShare $share |
|
| 1012 | + * @return IShare[] List of deleted shares |
|
| 1013 | + */ |
|
| 1014 | + protected function deleteChildren(IShare $share) { |
|
| 1015 | + $deletedShares = []; |
|
| 1016 | + |
|
| 1017 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1018 | + |
|
| 1019 | + foreach ($provider->getChildren($share) as $child) { |
|
| 1020 | + $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($child)); |
|
| 1021 | + |
|
| 1022 | + $deletedChildren = $this->deleteChildren($child); |
|
| 1023 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
| 1024 | + |
|
| 1025 | + $provider->delete($child); |
|
| 1026 | + $this->dispatcher->dispatchTyped(new ShareDeletedEvent($child)); |
|
| 1027 | + $deletedShares[] = $child; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + return $deletedShares; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** Promote re-shares into direct shares so that target user keeps access */ |
|
| 1034 | + protected function promoteReshares(IShare $share): void { |
|
| 1035 | + try { |
|
| 1036 | + $node = $share->getNode(); |
|
| 1037 | + } catch (NotFoundException) { |
|
| 1038 | + /* Skip if node not found */ |
|
| 1039 | + return; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + $userIds = []; |
|
| 1043 | + |
|
| 1044 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
| 1045 | + $userIds[] = $share->getSharedWith(); |
|
| 1046 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 1047 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
| 1048 | + $users = $group?->getUsers() ?? []; |
|
| 1049 | + |
|
| 1050 | + foreach ($users as $user) { |
|
| 1051 | + /* Skip share owner */ |
|
| 1052 | + if ($user->getUID() === $share->getShareOwner() || $user->getUID() === $share->getSharedBy()) { |
|
| 1053 | + continue; |
|
| 1054 | + } |
|
| 1055 | + $userIds[] = $user->getUID(); |
|
| 1056 | + } |
|
| 1057 | + } else { |
|
| 1058 | + /* We only support user and group shares */ |
|
| 1059 | + return; |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + $reshareRecords = []; |
|
| 1063 | + $shareTypes = [ |
|
| 1064 | + IShare::TYPE_GROUP, |
|
| 1065 | + IShare::TYPE_USER, |
|
| 1066 | + IShare::TYPE_LINK, |
|
| 1067 | + IShare::TYPE_REMOTE, |
|
| 1068 | + IShare::TYPE_EMAIL, |
|
| 1069 | + ]; |
|
| 1070 | + |
|
| 1071 | + foreach ($userIds as $userId) { |
|
| 1072 | + foreach ($shareTypes as $shareType) { |
|
| 1073 | + try { |
|
| 1074 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 1075 | + } catch (ProviderException $e) { |
|
| 1076 | + continue; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + if ($node instanceof Folder) { |
|
| 1080 | + /* We need to get all shares by this user to get subshares */ |
|
| 1081 | + $shares = $provider->getSharesBy($userId, $shareType, null, false, -1, 0); |
|
| 1082 | + |
|
| 1083 | + foreach ($shares as $share) { |
|
| 1084 | + try { |
|
| 1085 | + $path = $share->getNode()->getPath(); |
|
| 1086 | + } catch (NotFoundException) { |
|
| 1087 | + /* Ignore share of non-existing node */ |
|
| 1088 | + continue; |
|
| 1089 | + } |
|
| 1090 | + if ($node->getRelativePath($path) !== null) { |
|
| 1091 | + /* If relative path is not null it means the shared node is the same or in a subfolder */ |
|
| 1092 | + $reshareRecords[] = $share; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } else { |
|
| 1096 | + $shares = $provider->getSharesBy($userId, $shareType, $node, false, -1, 0); |
|
| 1097 | + foreach ($shares as $child) { |
|
| 1098 | + $reshareRecords[] = $child; |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + foreach ($reshareRecords as $child) { |
|
| 1105 | + try { |
|
| 1106 | + /* Check if the share is still valid (means the resharer still has access to the file through another mean) */ |
|
| 1107 | + $this->generalCreateChecks($child); |
|
| 1108 | + } catch (GenericShareException $e) { |
|
| 1109 | + /* The check is invalid, promote it to a direct share from the sharer of parent share */ |
|
| 1110 | + $this->logger->debug('Promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); |
|
| 1111 | + try { |
|
| 1112 | + $child->setSharedBy($share->getSharedBy()); |
|
| 1113 | + $this->updateShare($child); |
|
| 1114 | + } catch (GenericShareException|\InvalidArgumentException $e) { |
|
| 1115 | + $this->logger->warning('Failed to promote reshare because of exception ' . $e->getMessage(), ['exception' => $e, 'fullId' => $child->getFullId()]); |
|
| 1116 | + } |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + /** |
|
| 1122 | + * Delete a share |
|
| 1123 | + * |
|
| 1124 | + * @param IShare $share |
|
| 1125 | + * @throws ShareNotFound |
|
| 1126 | + * @throws \InvalidArgumentException |
|
| 1127 | + */ |
|
| 1128 | + public function deleteShare(IShare $share) { |
|
| 1129 | + try { |
|
| 1130 | + $share->getFullId(); |
|
| 1131 | + } catch (\UnexpectedValueException $e) { |
|
| 1132 | + throw new \InvalidArgumentException($this->l->t('Share does not have a full ID')); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + $this->dispatcher->dispatchTyped(new BeforeShareDeletedEvent($share)); |
|
| 1136 | + |
|
| 1137 | + // Get all children and delete them as well |
|
| 1138 | + $this->deleteChildren($share); |
|
| 1139 | + |
|
| 1140 | + // Do the actual delete |
|
| 1141 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1142 | + $provider->delete($share); |
|
| 1143 | + |
|
| 1144 | + $this->dispatcher->dispatchTyped(new ShareDeletedEvent($share)); |
|
| 1145 | + |
|
| 1146 | + // Promote reshares of the deleted share |
|
| 1147 | + $this->promoteReshares($share); |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Unshare a file as the recipient. |
|
| 1153 | + * This can be different from a regular delete for example when one of |
|
| 1154 | + * the users in a groups deletes that share. But the provider should |
|
| 1155 | + * handle this. |
|
| 1156 | + * |
|
| 1157 | + * @param IShare $share |
|
| 1158 | + * @param string $recipientId |
|
| 1159 | + */ |
|
| 1160 | + public function deleteFromSelf(IShare $share, $recipientId) { |
|
| 1161 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1162 | + $provider = $this->factory->getProvider($providerId); |
|
| 1163 | + |
|
| 1164 | + $provider->deleteFromSelf($share, $recipientId); |
|
| 1165 | + $event = new ShareDeletedFromSelfEvent($share); |
|
| 1166 | + $this->dispatcher->dispatchTyped($event); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + public function restoreShare(IShare $share, string $recipientId): IShare { |
|
| 1170 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1171 | + $provider = $this->factory->getProvider($providerId); |
|
| 1172 | + |
|
| 1173 | + return $provider->restore($share, $recipientId); |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * @inheritdoc |
|
| 1178 | + */ |
|
| 1179 | + public function moveShare(IShare $share, $recipientId) { |
|
| 1180 | + if ($share->getShareType() === IShare::TYPE_LINK |
|
| 1181 | + || $share->getShareType() === IShare::TYPE_EMAIL) { |
|
| 1182 | + throw new \InvalidArgumentException($this->l->t('Cannot change target of link share')); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
| 1186 | + throw new \InvalidArgumentException($this->l->t('Invalid share recipient')); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + if ($share->getShareType() === IShare::TYPE_GROUP) { |
|
| 1190 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 1191 | + if (is_null($sharedWith)) { |
|
| 1192 | + throw new \InvalidArgumentException($this->l->t('Group "%s" does not exist', [$share->getSharedWith()])); |
|
| 1193 | + } |
|
| 1194 | + $recipient = $this->userManager->get($recipientId); |
|
| 1195 | + if (!$sharedWith->inGroup($recipient)) { |
|
| 1196 | + throw new \InvalidArgumentException($this->l->t('Invalid share recipient')); |
|
| 1197 | + } |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + [$providerId,] = $this->splitFullId($share->getFullId()); |
|
| 1201 | + $provider = $this->factory->getProvider($providerId); |
|
| 1202 | + |
|
| 1203 | + return $provider->move($share, $recipientId); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) { |
|
| 1207 | + $providers = $this->factory->getAllProviders(); |
|
| 1208 | + if (!$shallow) { |
|
| 1209 | + throw new \Exception('non-shallow getSharesInFolder is no longer supported'); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + $isOwnerless = $node->getMountPoint() instanceof IShareOwnerlessMount; |
|
| 1213 | + |
|
| 1214 | + $shares = []; |
|
| 1215 | + foreach ($providers as $provider) { |
|
| 1216 | + if ($isOwnerless) { |
|
| 1217 | + // If the provider does not implement the additional interface, |
|
| 1218 | + // we lack a performant way of querying all shares and therefore ignore the provider. |
|
| 1219 | + if ($provider instanceof IShareProviderSupportsAllSharesInFolder) { |
|
| 1220 | + foreach ($provider->getAllSharesInFolder($node) as $fid => $data) { |
|
| 1221 | + $shares[$fid] ??= []; |
|
| 1222 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + } else { |
|
| 1226 | + foreach ($provider->getSharesInFolder($userId, $node, $reshares) as $fid => $data) { |
|
| 1227 | + $shares[$fid] ??= []; |
|
| 1228 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + return $shares; |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + /** |
|
| 1237 | + * @inheritdoc |
|
| 1238 | + */ |
|
| 1239 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true) { |
|
| 1240 | + if ($path !== null && |
|
| 1241 | + !($path instanceof \OCP\Files\File) && |
|
| 1242 | + !($path instanceof \OCP\Files\Folder)) { |
|
| 1243 | + throw new \InvalidArgumentException($this->l->t('Invalid path')); |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + try { |
|
| 1247 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 1248 | + } catch (ProviderException $e) { |
|
| 1249 | + return []; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + if ($path?->getMountPoint() instanceof IShareOwnerlessMount) { |
|
| 1253 | + $shares = array_filter($provider->getSharesByPath($path), static fn (IShare $share) => $share->getShareType() === $shareType); |
|
| 1254 | + } else { |
|
| 1255 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /* |
|
| 1259 | 1259 | * Work around so we don't return expired shares but still follow |
| 1260 | 1260 | * proper pagination. |
| 1261 | 1261 | */ |
| 1262 | 1262 | |
| 1263 | - $shares2 = []; |
|
| 1264 | - |
|
| 1265 | - while (true) { |
|
| 1266 | - $added = 0; |
|
| 1267 | - foreach ($shares as $share) { |
|
| 1268 | - if ($onlyValid) { |
|
| 1269 | - try { |
|
| 1270 | - $this->checkShare($share); |
|
| 1271 | - } catch (ShareNotFound $e) { |
|
| 1272 | - // Ignore since this basically means the share is deleted |
|
| 1273 | - continue; |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - $added++; |
|
| 1278 | - $shares2[] = $share; |
|
| 1279 | - |
|
| 1280 | - if (count($shares2) === $limit) { |
|
| 1281 | - break; |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - // If we did not fetch more shares than the limit then there are no more shares |
|
| 1286 | - if (count($shares) < $limit) { |
|
| 1287 | - break; |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - if (count($shares2) === $limit) { |
|
| 1291 | - break; |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - // If there was no limit on the select we are done |
|
| 1295 | - if ($limit === -1) { |
|
| 1296 | - break; |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - $offset += $added; |
|
| 1300 | - |
|
| 1301 | - // Fetch again $limit shares |
|
| 1302 | - if ($path?->getMountPoint() instanceof IShareOwnerlessMount) { |
|
| 1303 | - // We already fetched all shares, so end here |
|
| 1304 | - $shares = []; |
|
| 1305 | - } else { |
|
| 1306 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - // No more shares means we are done |
|
| 1310 | - if (empty($shares)) { |
|
| 1311 | - break; |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - $shares = $shares2; |
|
| 1316 | - |
|
| 1317 | - return $shares; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - /** |
|
| 1321 | - * @inheritdoc |
|
| 1322 | - */ |
|
| 1323 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1324 | - try { |
|
| 1325 | - $provider = $this->factory->getProviderForType($shareType); |
|
| 1326 | - } catch (ProviderException $e) { |
|
| 1327 | - return []; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1331 | - |
|
| 1332 | - // remove all shares which are already expired |
|
| 1333 | - foreach ($shares as $key => $share) { |
|
| 1334 | - try { |
|
| 1335 | - $this->checkShare($share); |
|
| 1336 | - } catch (ShareNotFound $e) { |
|
| 1337 | - unset($shares[$key]); |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - return $shares; |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - /** |
|
| 1345 | - * @inheritdoc |
|
| 1346 | - */ |
|
| 1347 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1348 | - $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1349 | - |
|
| 1350 | - // Only get deleted shares |
|
| 1351 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1352 | - return $share->getPermissions() === 0; |
|
| 1353 | - }); |
|
| 1354 | - |
|
| 1355 | - // Only get shares where the owner still exists |
|
| 1356 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 1357 | - return $this->userManager->userExists($share->getShareOwner()); |
|
| 1358 | - }); |
|
| 1359 | - |
|
| 1360 | - return $shares; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * @inheritdoc |
|
| 1365 | - */ |
|
| 1366 | - public function getShareById($id, $recipient = null, bool $onlyValid = true) { |
|
| 1367 | - if ($id === null) { |
|
| 1368 | - throw new ShareNotFound(); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - [$providerId, $id] = $this->splitFullId($id); |
|
| 1372 | - |
|
| 1373 | - try { |
|
| 1374 | - $provider = $this->factory->getProvider($providerId); |
|
| 1375 | - } catch (ProviderException $e) { |
|
| 1376 | - throw new ShareNotFound(); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - $share = $provider->getShareById($id, $recipient); |
|
| 1380 | - |
|
| 1381 | - if ($onlyValid) { |
|
| 1382 | - $this->checkShare($share); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - return $share; |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Get all the shares for a given path |
|
| 1390 | - * |
|
| 1391 | - * @param \OCP\Files\Node $path |
|
| 1392 | - * @param int $page |
|
| 1393 | - * @param int $perPage |
|
| 1394 | - * |
|
| 1395 | - * @return Share[] |
|
| 1396 | - */ |
|
| 1397 | - public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
| 1398 | - return []; |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * Get the share by token possible with password |
|
| 1403 | - * |
|
| 1404 | - * @param string $token |
|
| 1405 | - * @return IShare |
|
| 1406 | - * |
|
| 1407 | - * @throws ShareNotFound |
|
| 1408 | - */ |
|
| 1409 | - public function getShareByToken($token) { |
|
| 1410 | - // tokens cannot be valid local user names |
|
| 1411 | - if ($this->userManager->userExists($token)) { |
|
| 1412 | - throw new ShareNotFound(); |
|
| 1413 | - } |
|
| 1414 | - $share = null; |
|
| 1415 | - try { |
|
| 1416 | - if ($this->shareApiAllowLinks()) { |
|
| 1417 | - $provider = $this->factory->getProviderForType(IShare::TYPE_LINK); |
|
| 1418 | - $share = $provider->getShareByToken($token); |
|
| 1419 | - } |
|
| 1420 | - } catch (ProviderException $e) { |
|
| 1421 | - } catch (ShareNotFound $e) { |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - // If it is not a link share try to fetch a federated share by token |
|
| 1426 | - if ($share === null) { |
|
| 1427 | - try { |
|
| 1428 | - $provider = $this->factory->getProviderForType(IShare::TYPE_REMOTE); |
|
| 1429 | - $share = $provider->getShareByToken($token); |
|
| 1430 | - } catch (ProviderException $e) { |
|
| 1431 | - } catch (ShareNotFound $e) { |
|
| 1432 | - } |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - // If it is not a link share try to fetch a mail share by token |
|
| 1436 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
| 1437 | - try { |
|
| 1438 | - $provider = $this->factory->getProviderForType(IShare::TYPE_EMAIL); |
|
| 1439 | - $share = $provider->getShareByToken($token); |
|
| 1440 | - } catch (ProviderException $e) { |
|
| 1441 | - } catch (ShareNotFound $e) { |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_CIRCLE)) { |
|
| 1446 | - try { |
|
| 1447 | - $provider = $this->factory->getProviderForType(IShare::TYPE_CIRCLE); |
|
| 1448 | - $share = $provider->getShareByToken($token); |
|
| 1449 | - } catch (ProviderException $e) { |
|
| 1450 | - } catch (ShareNotFound $e) { |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - if ($share === null && $this->shareProviderExists(IShare::TYPE_ROOM)) { |
|
| 1455 | - try { |
|
| 1456 | - $provider = $this->factory->getProviderForType(IShare::TYPE_ROOM); |
|
| 1457 | - $share = $provider->getShareByToken($token); |
|
| 1458 | - } catch (ProviderException $e) { |
|
| 1459 | - } catch (ShareNotFound $e) { |
|
| 1460 | - } |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - if ($share === null) { |
|
| 1464 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - $this->checkShare($share); |
|
| 1468 | - |
|
| 1469 | - /* |
|
| 1263 | + $shares2 = []; |
|
| 1264 | + |
|
| 1265 | + while (true) { |
|
| 1266 | + $added = 0; |
|
| 1267 | + foreach ($shares as $share) { |
|
| 1268 | + if ($onlyValid) { |
|
| 1269 | + try { |
|
| 1270 | + $this->checkShare($share); |
|
| 1271 | + } catch (ShareNotFound $e) { |
|
| 1272 | + // Ignore since this basically means the share is deleted |
|
| 1273 | + continue; |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + $added++; |
|
| 1278 | + $shares2[] = $share; |
|
| 1279 | + |
|
| 1280 | + if (count($shares2) === $limit) { |
|
| 1281 | + break; |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + // If we did not fetch more shares than the limit then there are no more shares |
|
| 1286 | + if (count($shares) < $limit) { |
|
| 1287 | + break; |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + if (count($shares2) === $limit) { |
|
| 1291 | + break; |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + // If there was no limit on the select we are done |
|
| 1295 | + if ($limit === -1) { |
|
| 1296 | + break; |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + $offset += $added; |
|
| 1300 | + |
|
| 1301 | + // Fetch again $limit shares |
|
| 1302 | + if ($path?->getMountPoint() instanceof IShareOwnerlessMount) { |
|
| 1303 | + // We already fetched all shares, so end here |
|
| 1304 | + $shares = []; |
|
| 1305 | + } else { |
|
| 1306 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + // No more shares means we are done |
|
| 1310 | + if (empty($shares)) { |
|
| 1311 | + break; |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + $shares = $shares2; |
|
| 1316 | + |
|
| 1317 | + return $shares; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + /** |
|
| 1321 | + * @inheritdoc |
|
| 1322 | + */ |
|
| 1323 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1324 | + try { |
|
| 1325 | + $provider = $this->factory->getProviderForType($shareType); |
|
| 1326 | + } catch (ProviderException $e) { |
|
| 1327 | + return []; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1331 | + |
|
| 1332 | + // remove all shares which are already expired |
|
| 1333 | + foreach ($shares as $key => $share) { |
|
| 1334 | + try { |
|
| 1335 | + $this->checkShare($share); |
|
| 1336 | + } catch (ShareNotFound $e) { |
|
| 1337 | + unset($shares[$key]); |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + return $shares; |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + /** |
|
| 1345 | + * @inheritdoc |
|
| 1346 | + */ |
|
| 1347 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
| 1348 | + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 1349 | + |
|
| 1350 | + // Only get deleted shares |
|
| 1351 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 1352 | + return $share->getPermissions() === 0; |
|
| 1353 | + }); |
|
| 1354 | + |
|
| 1355 | + // Only get shares where the owner still exists |
|
| 1356 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 1357 | + return $this->userManager->userExists($share->getShareOwner()); |
|
| 1358 | + }); |
|
| 1359 | + |
|
| 1360 | + return $shares; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * @inheritdoc |
|
| 1365 | + */ |
|
| 1366 | + public function getShareById($id, $recipient = null, bool $onlyValid = true) { |
|
| 1367 | + if ($id === null) { |
|
| 1368 | + throw new ShareNotFound(); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + [$providerId, $id] = $this->splitFullId($id); |
|
| 1372 | + |
|
| 1373 | + try { |
|
| 1374 | + $provider = $this->factory->getProvider($providerId); |
|
| 1375 | + } catch (ProviderException $e) { |
|
| 1376 | + throw new ShareNotFound(); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + $share = $provider->getShareById($id, $recipient); |
|
| 1380 | + |
|
| 1381 | + if ($onlyValid) { |
|
| 1382 | + $this->checkShare($share); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + return $share; |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Get all the shares for a given path |
|
| 1390 | + * |
|
| 1391 | + * @param \OCP\Files\Node $path |
|
| 1392 | + * @param int $page |
|
| 1393 | + * @param int $perPage |
|
| 1394 | + * |
|
| 1395 | + * @return Share[] |
|
| 1396 | + */ |
|
| 1397 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
| 1398 | + return []; |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * Get the share by token possible with password |
|
| 1403 | + * |
|
| 1404 | + * @param string $token |
|
| 1405 | + * @return IShare |
|
| 1406 | + * |
|
| 1407 | + * @throws ShareNotFound |
|
| 1408 | + */ |
|
| 1409 | + public function getShareByToken($token) { |
|
| 1410 | + // tokens cannot be valid local user names |
|
| 1411 | + if ($this->userManager->userExists($token)) { |
|
| 1412 | + throw new ShareNotFound(); |
|
| 1413 | + } |
|
| 1414 | + $share = null; |
|
| 1415 | + try { |
|
| 1416 | + if ($this->shareApiAllowLinks()) { |
|
| 1417 | + $provider = $this->factory->getProviderForType(IShare::TYPE_LINK); |
|
| 1418 | + $share = $provider->getShareByToken($token); |
|
| 1419 | + } |
|
| 1420 | + } catch (ProviderException $e) { |
|
| 1421 | + } catch (ShareNotFound $e) { |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + // If it is not a link share try to fetch a federated share by token |
|
| 1426 | + if ($share === null) { |
|
| 1427 | + try { |
|
| 1428 | + $provider = $this->factory->getProviderForType(IShare::TYPE_REMOTE); |
|
| 1429 | + $share = $provider->getShareByToken($token); |
|
| 1430 | + } catch (ProviderException $e) { |
|
| 1431 | + } catch (ShareNotFound $e) { |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + // If it is not a link share try to fetch a mail share by token |
|
| 1436 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
| 1437 | + try { |
|
| 1438 | + $provider = $this->factory->getProviderForType(IShare::TYPE_EMAIL); |
|
| 1439 | + $share = $provider->getShareByToken($token); |
|
| 1440 | + } catch (ProviderException $e) { |
|
| 1441 | + } catch (ShareNotFound $e) { |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_CIRCLE)) { |
|
| 1446 | + try { |
|
| 1447 | + $provider = $this->factory->getProviderForType(IShare::TYPE_CIRCLE); |
|
| 1448 | + $share = $provider->getShareByToken($token); |
|
| 1449 | + } catch (ProviderException $e) { |
|
| 1450 | + } catch (ShareNotFound $e) { |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + if ($share === null && $this->shareProviderExists(IShare::TYPE_ROOM)) { |
|
| 1455 | + try { |
|
| 1456 | + $provider = $this->factory->getProviderForType(IShare::TYPE_ROOM); |
|
| 1457 | + $share = $provider->getShareByToken($token); |
|
| 1458 | + } catch (ProviderException $e) { |
|
| 1459 | + } catch (ShareNotFound $e) { |
|
| 1460 | + } |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + if ($share === null) { |
|
| 1464 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + $this->checkShare($share); |
|
| 1468 | + |
|
| 1469 | + /* |
|
| 1470 | 1470 | * Reduce the permissions for link or email shares if public upload is not enabled |
| 1471 | 1471 | */ |
| 1472 | - if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) |
|
| 1473 | - && $share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1474 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1475 | - } |
|
| 1476 | - |
|
| 1477 | - return $share; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * Check expire date and disabled owner |
|
| 1482 | - * |
|
| 1483 | - * @throws ShareNotFound |
|
| 1484 | - */ |
|
| 1485 | - protected function checkShare(IShare $share): void { |
|
| 1486 | - if ($share->isExpired()) { |
|
| 1487 | - $this->deleteShare($share); |
|
| 1488 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1489 | - } |
|
| 1490 | - if ($this->config->getAppValue('files_sharing', 'hide_disabled_user_shares', 'no') === 'yes') { |
|
| 1491 | - $uids = array_unique([$share->getShareOwner(),$share->getSharedBy()]); |
|
| 1492 | - foreach ($uids as $uid) { |
|
| 1493 | - $user = $this->userManager->get($uid); |
|
| 1494 | - if ($user?->isEnabled() === false) { |
|
| 1495 | - throw new ShareNotFound($this->l->t('The requested share comes from a disabled user')); |
|
| 1496 | - } |
|
| 1497 | - } |
|
| 1498 | - } |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - /** |
|
| 1502 | - * Verify the password of a public share |
|
| 1503 | - * |
|
| 1504 | - * @param IShare $share |
|
| 1505 | - * @param ?string $password |
|
| 1506 | - * @return bool |
|
| 1507 | - */ |
|
| 1508 | - public function checkPassword(IShare $share, $password) { |
|
| 1509 | - |
|
| 1510 | - // if there is no password on the share object / passsword is null, there is nothing to check |
|
| 1511 | - if ($password === null || $share->getPassword() === null) { |
|
| 1512 | - return false; |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - // Makes sure password hasn't expired |
|
| 1516 | - $expirationTime = $share->getPasswordExpirationTime(); |
|
| 1517 | - if ($expirationTime !== null && $expirationTime < new \DateTime()) { |
|
| 1518 | - return false; |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - $newHash = ''; |
|
| 1522 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1523 | - return false; |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - if (!empty($newHash)) { |
|
| 1527 | - $share->setPassword($newHash); |
|
| 1528 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1529 | - $provider->update($share); |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - return true; |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - /** |
|
| 1536 | - * @inheritdoc |
|
| 1537 | - */ |
|
| 1538 | - public function userDeleted($uid) { |
|
| 1539 | - $types = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_EMAIL]; |
|
| 1540 | - |
|
| 1541 | - foreach ($types as $type) { |
|
| 1542 | - try { |
|
| 1543 | - $provider = $this->factory->getProviderForType($type); |
|
| 1544 | - } catch (ProviderException $e) { |
|
| 1545 | - continue; |
|
| 1546 | - } |
|
| 1547 | - $provider->userDeleted($uid, $type); |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - /** |
|
| 1552 | - * @inheritdoc |
|
| 1553 | - */ |
|
| 1554 | - public function groupDeleted($gid) { |
|
| 1555 | - foreach ([IShare::TYPE_GROUP, IShare::TYPE_REMOTE_GROUP] as $type) { |
|
| 1556 | - try { |
|
| 1557 | - $provider = $this->factory->getProviderForType($type); |
|
| 1558 | - } catch (ProviderException $e) { |
|
| 1559 | - continue; |
|
| 1560 | - } |
|
| 1561 | - $provider->groupDeleted($gid); |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1565 | - if ($excludedGroups === '') { |
|
| 1566 | - return; |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - $excludedGroups = json_decode($excludedGroups, true); |
|
| 1570 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 1571 | - return; |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - $excludedGroups = array_diff($excludedGroups, [$gid]); |
|
| 1575 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups)); |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - /** |
|
| 1579 | - * @inheritdoc |
|
| 1580 | - */ |
|
| 1581 | - public function userDeletedFromGroup($uid, $gid) { |
|
| 1582 | - foreach ([IShare::TYPE_GROUP, IShare::TYPE_REMOTE_GROUP] as $type) { |
|
| 1583 | - try { |
|
| 1584 | - $provider = $this->factory->getProviderForType($type); |
|
| 1585 | - } catch (ProviderException $e) { |
|
| 1586 | - continue; |
|
| 1587 | - } |
|
| 1588 | - $provider->userDeletedFromGroup($uid, $gid); |
|
| 1589 | - } |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * Get access list to a path. This means |
|
| 1594 | - * all the users that can access a given path. |
|
| 1595 | - * |
|
| 1596 | - * Consider: |
|
| 1597 | - * -root |
|
| 1598 | - * |-folder1 (23) |
|
| 1599 | - * |-folder2 (32) |
|
| 1600 | - * |-fileA (42) |
|
| 1601 | - * |
|
| 1602 | - * fileA is shared with user1 and user1@server1 and email1@maildomain1 |
|
| 1603 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1604 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 1605 | - * and email2@maildomain2 |
|
| 1606 | - * |
|
| 1607 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 1608 | - * [ |
|
| 1609 | - * users => [ |
|
| 1610 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 1611 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 1612 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 1613 | - * ], |
|
| 1614 | - * remote => [ |
|
| 1615 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 1616 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 1617 | - * ], |
|
| 1618 | - * public => bool |
|
| 1619 | - * mail => [ |
|
| 1620 | - * 'email1@maildomain1' => ['node_id' => 42, 'token' => 'aBcDeFg'], |
|
| 1621 | - * 'email2@maildomain2' => ['node_id' => 23, 'token' => 'hIjKlMn'], |
|
| 1622 | - * ] |
|
| 1623 | - * ] |
|
| 1624 | - * |
|
| 1625 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 1626 | - * [ |
|
| 1627 | - * users => ['user1', 'user2', 'user4'], |
|
| 1628 | - * remote => bool, |
|
| 1629 | - * public => bool |
|
| 1630 | - * mail => ['email1@maildomain1', 'email2@maildomain2'] |
|
| 1631 | - * ] |
|
| 1632 | - * |
|
| 1633 | - * This is required for encryption/activity |
|
| 1634 | - * |
|
| 1635 | - * @param \OCP\Files\Node $path |
|
| 1636 | - * @param bool $recursive Should we check all parent folders as well |
|
| 1637 | - * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
| 1638 | - * @return array |
|
| 1639 | - */ |
|
| 1640 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1641 | - $owner = $path->getOwner(); |
|
| 1642 | - |
|
| 1643 | - if ($owner === null) { |
|
| 1644 | - return []; |
|
| 1645 | - } |
|
| 1646 | - |
|
| 1647 | - $owner = $owner->getUID(); |
|
| 1648 | - |
|
| 1649 | - if ($currentAccess) { |
|
| 1650 | - $al = ['users' => [], 'remote' => [], 'public' => false, 'mail' => []]; |
|
| 1651 | - } else { |
|
| 1652 | - $al = ['users' => [], 'remote' => false, 'public' => false, 'mail' => []]; |
|
| 1653 | - } |
|
| 1654 | - if (!$this->userManager->userExists($owner)) { |
|
| 1655 | - return $al; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - //Get node for the owner and correct the owner in case of external storage |
|
| 1659 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1660 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
| 1661 | - $path = $userFolder->getFirstNodeById($path->getId()); |
|
| 1662 | - if ($path === null || $path->getOwner() === null) { |
|
| 1663 | - return []; |
|
| 1664 | - } |
|
| 1665 | - $owner = $path->getOwner()->getUID(); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - $providers = $this->factory->getAllProviders(); |
|
| 1669 | - |
|
| 1670 | - /** @var Node[] $nodes */ |
|
| 1671 | - $nodes = []; |
|
| 1672 | - |
|
| 1673 | - |
|
| 1674 | - if ($currentAccess) { |
|
| 1675 | - $ownerPath = $path->getPath(); |
|
| 1676 | - $ownerPath = explode('/', $ownerPath, 4); |
|
| 1677 | - if (count($ownerPath) < 4) { |
|
| 1678 | - $ownerPath = ''; |
|
| 1679 | - } else { |
|
| 1680 | - $ownerPath = $ownerPath[3]; |
|
| 1681 | - } |
|
| 1682 | - $al['users'][$owner] = [ |
|
| 1683 | - 'node_id' => $path->getId(), |
|
| 1684 | - 'node_path' => '/' . $ownerPath, |
|
| 1685 | - ]; |
|
| 1686 | - } else { |
|
| 1687 | - $al['users'][] = $owner; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - // Collect all the shares |
|
| 1691 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1692 | - $nodes[] = $path; |
|
| 1693 | - if (!$recursive) { |
|
| 1694 | - break; |
|
| 1695 | - } |
|
| 1696 | - $path = $path->getParent(); |
|
| 1697 | - } |
|
| 1698 | - |
|
| 1699 | - foreach ($providers as $provider) { |
|
| 1700 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1701 | - |
|
| 1702 | - foreach ($tmp as $k => $v) { |
|
| 1703 | - if (isset($al[$k])) { |
|
| 1704 | - if (is_array($al[$k])) { |
|
| 1705 | - if ($currentAccess) { |
|
| 1706 | - $al[$k] += $v; |
|
| 1707 | - } else { |
|
| 1708 | - $al[$k] = array_merge($al[$k], $v); |
|
| 1709 | - $al[$k] = array_unique($al[$k]); |
|
| 1710 | - $al[$k] = array_values($al[$k]); |
|
| 1711 | - } |
|
| 1712 | - } else { |
|
| 1713 | - $al[$k] = $al[$k] || $v; |
|
| 1714 | - } |
|
| 1715 | - } else { |
|
| 1716 | - $al[$k] = $v; |
|
| 1717 | - } |
|
| 1718 | - } |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - return $al; |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * Create a new share |
|
| 1726 | - * |
|
| 1727 | - * @return IShare |
|
| 1728 | - */ |
|
| 1729 | - public function newShare() { |
|
| 1730 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - /** |
|
| 1734 | - * Is the share API enabled |
|
| 1735 | - * |
|
| 1736 | - * @return bool |
|
| 1737 | - */ |
|
| 1738 | - public function shareApiEnabled() { |
|
| 1739 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - /** |
|
| 1743 | - * Is public link sharing enabled |
|
| 1744 | - * |
|
| 1745 | - * @return bool |
|
| 1746 | - */ |
|
| 1747 | - public function shareApiAllowLinks() { |
|
| 1748 | - if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 1749 | - return false; |
|
| 1750 | - } |
|
| 1751 | - |
|
| 1752 | - $user = $this->userSession->getUser(); |
|
| 1753 | - if ($user) { |
|
| 1754 | - $excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]')); |
|
| 1755 | - if ($excludedGroups) { |
|
| 1756 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1757 | - return !(bool)array_intersect($excludedGroups, $userGroups); |
|
| 1758 | - } |
|
| 1759 | - } |
|
| 1760 | - |
|
| 1761 | - return true; |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - /** |
|
| 1765 | - * Is password on public link requires |
|
| 1766 | - * |
|
| 1767 | - * @param bool Check group membership exclusion |
|
| 1768 | - * @return bool |
|
| 1769 | - */ |
|
| 1770 | - public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true) { |
|
| 1771 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', ''); |
|
| 1772 | - if ($excludedGroups !== '' && $checkGroupMembership) { |
|
| 1773 | - $excludedGroups = json_decode($excludedGroups); |
|
| 1774 | - $user = $this->userSession->getUser(); |
|
| 1775 | - if ($user) { |
|
| 1776 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1777 | - if ((bool)array_intersect($excludedGroups, $userGroups)) { |
|
| 1778 | - return false; |
|
| 1779 | - } |
|
| 1780 | - } |
|
| 1781 | - } |
|
| 1782 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - /** |
|
| 1786 | - * Is default link expire date enabled |
|
| 1787 | - * |
|
| 1788 | - * @return bool |
|
| 1789 | - */ |
|
| 1790 | - public function shareApiLinkDefaultExpireDate() { |
|
| 1791 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - /** |
|
| 1795 | - * Is default link expire date enforced |
|
| 1796 | - *` |
|
| 1797 | - * |
|
| 1798 | - * @return bool |
|
| 1799 | - */ |
|
| 1800 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1801 | - return $this->shareApiLinkDefaultExpireDate() && |
|
| 1802 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - |
|
| 1806 | - /** |
|
| 1807 | - * Number of default link expire days |
|
| 1808 | - * |
|
| 1809 | - * @return int |
|
| 1810 | - */ |
|
| 1811 | - public function shareApiLinkDefaultExpireDays() { |
|
| 1812 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1813 | - } |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Is default internal expire date enabled |
|
| 1817 | - * |
|
| 1818 | - * @return bool |
|
| 1819 | - */ |
|
| 1820 | - public function shareApiInternalDefaultExpireDate(): bool { |
|
| 1821 | - return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
| 1822 | - } |
|
| 1823 | - |
|
| 1824 | - /** |
|
| 1825 | - * Is default remote expire date enabled |
|
| 1826 | - * |
|
| 1827 | - * @return bool |
|
| 1828 | - */ |
|
| 1829 | - public function shareApiRemoteDefaultExpireDate(): bool { |
|
| 1830 | - return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes'; |
|
| 1831 | - } |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * Is default expire date enforced |
|
| 1835 | - * |
|
| 1836 | - * @return bool |
|
| 1837 | - */ |
|
| 1838 | - public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
| 1839 | - return $this->shareApiInternalDefaultExpireDate() && |
|
| 1840 | - $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - /** |
|
| 1844 | - * Is default expire date enforced for remote shares |
|
| 1845 | - * |
|
| 1846 | - * @return bool |
|
| 1847 | - */ |
|
| 1848 | - public function shareApiRemoteDefaultExpireDateEnforced(): bool { |
|
| 1849 | - return $this->shareApiRemoteDefaultExpireDate() && |
|
| 1850 | - $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes'; |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - /** |
|
| 1854 | - * Number of default expire days |
|
| 1855 | - * |
|
| 1856 | - * @return int |
|
| 1857 | - */ |
|
| 1858 | - public function shareApiInternalDefaultExpireDays(): int { |
|
| 1859 | - return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * Number of default expire days for remote shares |
|
| 1864 | - * |
|
| 1865 | - * @return int |
|
| 1866 | - */ |
|
| 1867 | - public function shareApiRemoteDefaultExpireDays(): int { |
|
| 1868 | - return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
| 1869 | - } |
|
| 1870 | - |
|
| 1871 | - /** |
|
| 1872 | - * Allow public upload on link shares |
|
| 1873 | - * |
|
| 1874 | - * @return bool |
|
| 1875 | - */ |
|
| 1876 | - public function shareApiLinkAllowPublicUpload() { |
|
| 1877 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1878 | - } |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * check if user can only share with group members |
|
| 1882 | - * |
|
| 1883 | - * @return bool |
|
| 1884 | - */ |
|
| 1885 | - public function shareWithGroupMembersOnly() { |
|
| 1886 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - /** |
|
| 1890 | - * If shareWithGroupMembersOnly is enabled, return an optional |
|
| 1891 | - * list of groups that must be excluded from the principle of |
|
| 1892 | - * belonging to the same group. |
|
| 1893 | - * |
|
| 1894 | - * @return array |
|
| 1895 | - */ |
|
| 1896 | - public function shareWithGroupMembersOnlyExcludeGroupsList() { |
|
| 1897 | - if (!$this->shareWithGroupMembersOnly()) { |
|
| 1898 | - return []; |
|
| 1899 | - } |
|
| 1900 | - $excludeGroups = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''); |
|
| 1901 | - return json_decode($excludeGroups, true) ?? []; |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - /** |
|
| 1905 | - * Check if users can share with groups |
|
| 1906 | - * |
|
| 1907 | - * @return bool |
|
| 1908 | - */ |
|
| 1909 | - public function allowGroupSharing() { |
|
| 1910 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1911 | - } |
|
| 1912 | - |
|
| 1913 | - public function allowEnumeration(): bool { |
|
| 1914 | - return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - public function limitEnumerationToGroups(): bool { |
|
| 1918 | - return $this->allowEnumeration() && |
|
| 1919 | - $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - public function limitEnumerationToPhone(): bool { |
|
| 1923 | - return $this->allowEnumeration() && |
|
| 1924 | - $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - public function allowEnumerationFullMatch(): bool { |
|
| 1928 | - return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - public function matchEmail(): bool { |
|
| 1932 | - return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
| 1933 | - } |
|
| 1934 | - |
|
| 1935 | - public function ignoreSecondDisplayName(): bool { |
|
| 1936 | - return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes'; |
|
| 1937 | - } |
|
| 1938 | - |
|
| 1939 | - public function allowCustomTokens(): bool { |
|
| 1940 | - return $this->appConfig->getValueBool('core', 'shareapi_allow_custom_tokens', false); |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - public function allowViewWithoutDownload(): bool { |
|
| 1944 | - return $this->appConfig->getValueBool('core', 'shareapi_allow_view_without_download', true); |
|
| 1945 | - } |
|
| 1946 | - |
|
| 1947 | - public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool { |
|
| 1948 | - if ($this->allowEnumerationFullMatch()) { |
|
| 1949 | - return true; |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - if (!$this->allowEnumeration()) { |
|
| 1953 | - return false; |
|
| 1954 | - } |
|
| 1955 | - |
|
| 1956 | - if (!$this->limitEnumerationToPhone() && !$this->limitEnumerationToGroups()) { |
|
| 1957 | - // Enumeration is enabled and not restricted: OK |
|
| 1958 | - return true; |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - if (!$currentUser instanceof IUser) { |
|
| 1962 | - // Enumeration restrictions require an account |
|
| 1963 | - return false; |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - // Enumeration is limited to phone match |
|
| 1967 | - if ($this->limitEnumerationToPhone() && $this->knownUserService->isKnownToUser($currentUser->getUID(), $targetUser->getUID())) { |
|
| 1968 | - return true; |
|
| 1969 | - } |
|
| 1970 | - |
|
| 1971 | - // Enumeration is limited to groups |
|
| 1972 | - if ($this->limitEnumerationToGroups()) { |
|
| 1973 | - $currentUserGroupIds = $this->groupManager->getUserGroupIds($currentUser); |
|
| 1974 | - $targetUserGroupIds = $this->groupManager->getUserGroupIds($targetUser); |
|
| 1975 | - if (!empty(array_intersect($currentUserGroupIds, $targetUserGroupIds))) { |
|
| 1976 | - return true; |
|
| 1977 | - } |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - return false; |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * Check if sharing is disabled for the current user |
|
| 1985 | - */ |
|
| 1986 | - public function sharingDisabledForUser(?string $userId): bool { |
|
| 1987 | - return $this->shareDisableChecker->sharingDisabledForUser($userId); |
|
| 1988 | - } |
|
| 1989 | - |
|
| 1990 | - /** |
|
| 1991 | - * @inheritdoc |
|
| 1992 | - */ |
|
| 1993 | - public function outgoingServer2ServerSharesAllowed() { |
|
| 1994 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * @inheritdoc |
|
| 1999 | - */ |
|
| 2000 | - public function outgoingServer2ServerGroupSharesAllowed() { |
|
| 2001 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
| 2002 | - } |
|
| 2003 | - |
|
| 2004 | - /** |
|
| 2005 | - * @inheritdoc |
|
| 2006 | - */ |
|
| 2007 | - public function shareProviderExists($shareType) { |
|
| 2008 | - try { |
|
| 2009 | - $this->factory->getProviderForType($shareType); |
|
| 2010 | - } catch (ProviderException $e) { |
|
| 2011 | - return false; |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - return true; |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - public function registerShareProvider(string $shareProviderClass): void { |
|
| 2018 | - $this->factory->registerProvider($shareProviderClass); |
|
| 2019 | - } |
|
| 2020 | - |
|
| 2021 | - public function getAllShares(): iterable { |
|
| 2022 | - $providers = $this->factory->getAllProviders(); |
|
| 2023 | - |
|
| 2024 | - foreach ($providers as $provider) { |
|
| 2025 | - yield from $provider->getAllShares(); |
|
| 2026 | - } |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - public function generateToken(): string { |
|
| 2030 | - // Initial token length |
|
| 2031 | - $tokenLength = \OC\Share\Helper::getTokenLength(); |
|
| 2032 | - |
|
| 2033 | - do { |
|
| 2034 | - $tokenExists = false; |
|
| 2035 | - |
|
| 2036 | - for ($i = 0; $i <= 2; $i++) { |
|
| 2037 | - // Generate a new token |
|
| 2038 | - $token = $this->secureRandom->generate( |
|
| 2039 | - $tokenLength, |
|
| 2040 | - ISecureRandom::CHAR_HUMAN_READABLE, |
|
| 2041 | - ); |
|
| 2042 | - |
|
| 2043 | - try { |
|
| 2044 | - // Try to fetch a share with the generated token |
|
| 2045 | - $this->getShareByToken($token); |
|
| 2046 | - $tokenExists = true; // Token exists, we need to try again |
|
| 2047 | - } catch (ShareNotFound $e) { |
|
| 2048 | - // Token is unique, exit the loop |
|
| 2049 | - $tokenExists = false; |
|
| 2050 | - break; |
|
| 2051 | - } |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - // If we've reached the maximum attempts and the token still exists, increase the token length |
|
| 2055 | - if ($tokenExists) { |
|
| 2056 | - $tokenLength++; |
|
| 2057 | - |
|
| 2058 | - // Check if the token length exceeds the maximum allowed length |
|
| 2059 | - if ($tokenLength > \OC\Share\Constants::MAX_TOKEN_LENGTH) { |
|
| 2060 | - throw new ShareTokenException('Unable to generate a unique share token. Maximum token length exceeded.'); |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - } while ($tokenExists); |
|
| 2064 | - |
|
| 2065 | - return $token; |
|
| 2066 | - } |
|
| 1472 | + if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) |
|
| 1473 | + && $share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload()) { |
|
| 1474 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + return $share; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * Check expire date and disabled owner |
|
| 1482 | + * |
|
| 1483 | + * @throws ShareNotFound |
|
| 1484 | + */ |
|
| 1485 | + protected function checkShare(IShare $share): void { |
|
| 1486 | + if ($share->isExpired()) { |
|
| 1487 | + $this->deleteShare($share); |
|
| 1488 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
| 1489 | + } |
|
| 1490 | + if ($this->config->getAppValue('files_sharing', 'hide_disabled_user_shares', 'no') === 'yes') { |
|
| 1491 | + $uids = array_unique([$share->getShareOwner(),$share->getSharedBy()]); |
|
| 1492 | + foreach ($uids as $uid) { |
|
| 1493 | + $user = $this->userManager->get($uid); |
|
| 1494 | + if ($user?->isEnabled() === false) { |
|
| 1495 | + throw new ShareNotFound($this->l->t('The requested share comes from a disabled user')); |
|
| 1496 | + } |
|
| 1497 | + } |
|
| 1498 | + } |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + /** |
|
| 1502 | + * Verify the password of a public share |
|
| 1503 | + * |
|
| 1504 | + * @param IShare $share |
|
| 1505 | + * @param ?string $password |
|
| 1506 | + * @return bool |
|
| 1507 | + */ |
|
| 1508 | + public function checkPassword(IShare $share, $password) { |
|
| 1509 | + |
|
| 1510 | + // if there is no password on the share object / passsword is null, there is nothing to check |
|
| 1511 | + if ($password === null || $share->getPassword() === null) { |
|
| 1512 | + return false; |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + // Makes sure password hasn't expired |
|
| 1516 | + $expirationTime = $share->getPasswordExpirationTime(); |
|
| 1517 | + if ($expirationTime !== null && $expirationTime < new \DateTime()) { |
|
| 1518 | + return false; |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + $newHash = ''; |
|
| 1522 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
| 1523 | + return false; |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + if (!empty($newHash)) { |
|
| 1527 | + $share->setPassword($newHash); |
|
| 1528 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
| 1529 | + $provider->update($share); |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + return true; |
|
| 1533 | + } |
|
| 1534 | + |
|
| 1535 | + /** |
|
| 1536 | + * @inheritdoc |
|
| 1537 | + */ |
|
| 1538 | + public function userDeleted($uid) { |
|
| 1539 | + $types = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_EMAIL]; |
|
| 1540 | + |
|
| 1541 | + foreach ($types as $type) { |
|
| 1542 | + try { |
|
| 1543 | + $provider = $this->factory->getProviderForType($type); |
|
| 1544 | + } catch (ProviderException $e) { |
|
| 1545 | + continue; |
|
| 1546 | + } |
|
| 1547 | + $provider->userDeleted($uid, $type); |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + /** |
|
| 1552 | + * @inheritdoc |
|
| 1553 | + */ |
|
| 1554 | + public function groupDeleted($gid) { |
|
| 1555 | + foreach ([IShare::TYPE_GROUP, IShare::TYPE_REMOTE_GROUP] as $type) { |
|
| 1556 | + try { |
|
| 1557 | + $provider = $this->factory->getProviderForType($type); |
|
| 1558 | + } catch (ProviderException $e) { |
|
| 1559 | + continue; |
|
| 1560 | + } |
|
| 1561 | + $provider->groupDeleted($gid); |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 1565 | + if ($excludedGroups === '') { |
|
| 1566 | + return; |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + $excludedGroups = json_decode($excludedGroups, true); |
|
| 1570 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 1571 | + return; |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + $excludedGroups = array_diff($excludedGroups, [$gid]); |
|
| 1575 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups)); |
|
| 1576 | + } |
|
| 1577 | + |
|
| 1578 | + /** |
|
| 1579 | + * @inheritdoc |
|
| 1580 | + */ |
|
| 1581 | + public function userDeletedFromGroup($uid, $gid) { |
|
| 1582 | + foreach ([IShare::TYPE_GROUP, IShare::TYPE_REMOTE_GROUP] as $type) { |
|
| 1583 | + try { |
|
| 1584 | + $provider = $this->factory->getProviderForType($type); |
|
| 1585 | + } catch (ProviderException $e) { |
|
| 1586 | + continue; |
|
| 1587 | + } |
|
| 1588 | + $provider->userDeletedFromGroup($uid, $gid); |
|
| 1589 | + } |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * Get access list to a path. This means |
|
| 1594 | + * all the users that can access a given path. |
|
| 1595 | + * |
|
| 1596 | + * Consider: |
|
| 1597 | + * -root |
|
| 1598 | + * |-folder1 (23) |
|
| 1599 | + * |-folder2 (32) |
|
| 1600 | + * |-fileA (42) |
|
| 1601 | + * |
|
| 1602 | + * fileA is shared with user1 and user1@server1 and email1@maildomain1 |
|
| 1603 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
| 1604 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
| 1605 | + * and email2@maildomain2 |
|
| 1606 | + * |
|
| 1607 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
| 1608 | + * [ |
|
| 1609 | + * users => [ |
|
| 1610 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
| 1611 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
| 1612 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
| 1613 | + * ], |
|
| 1614 | + * remote => [ |
|
| 1615 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
| 1616 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
| 1617 | + * ], |
|
| 1618 | + * public => bool |
|
| 1619 | + * mail => [ |
|
| 1620 | + * 'email1@maildomain1' => ['node_id' => 42, 'token' => 'aBcDeFg'], |
|
| 1621 | + * 'email2@maildomain2' => ['node_id' => 23, 'token' => 'hIjKlMn'], |
|
| 1622 | + * ] |
|
| 1623 | + * ] |
|
| 1624 | + * |
|
| 1625 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
| 1626 | + * [ |
|
| 1627 | + * users => ['user1', 'user2', 'user4'], |
|
| 1628 | + * remote => bool, |
|
| 1629 | + * public => bool |
|
| 1630 | + * mail => ['email1@maildomain1', 'email2@maildomain2'] |
|
| 1631 | + * ] |
|
| 1632 | + * |
|
| 1633 | + * This is required for encryption/activity |
|
| 1634 | + * |
|
| 1635 | + * @param \OCP\Files\Node $path |
|
| 1636 | + * @param bool $recursive Should we check all parent folders as well |
|
| 1637 | + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
| 1638 | + * @return array |
|
| 1639 | + */ |
|
| 1640 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
| 1641 | + $owner = $path->getOwner(); |
|
| 1642 | + |
|
| 1643 | + if ($owner === null) { |
|
| 1644 | + return []; |
|
| 1645 | + } |
|
| 1646 | + |
|
| 1647 | + $owner = $owner->getUID(); |
|
| 1648 | + |
|
| 1649 | + if ($currentAccess) { |
|
| 1650 | + $al = ['users' => [], 'remote' => [], 'public' => false, 'mail' => []]; |
|
| 1651 | + } else { |
|
| 1652 | + $al = ['users' => [], 'remote' => false, 'public' => false, 'mail' => []]; |
|
| 1653 | + } |
|
| 1654 | + if (!$this->userManager->userExists($owner)) { |
|
| 1655 | + return $al; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + //Get node for the owner and correct the owner in case of external storage |
|
| 1659 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
| 1660 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
| 1661 | + $path = $userFolder->getFirstNodeById($path->getId()); |
|
| 1662 | + if ($path === null || $path->getOwner() === null) { |
|
| 1663 | + return []; |
|
| 1664 | + } |
|
| 1665 | + $owner = $path->getOwner()->getUID(); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + $providers = $this->factory->getAllProviders(); |
|
| 1669 | + |
|
| 1670 | + /** @var Node[] $nodes */ |
|
| 1671 | + $nodes = []; |
|
| 1672 | + |
|
| 1673 | + |
|
| 1674 | + if ($currentAccess) { |
|
| 1675 | + $ownerPath = $path->getPath(); |
|
| 1676 | + $ownerPath = explode('/', $ownerPath, 4); |
|
| 1677 | + if (count($ownerPath) < 4) { |
|
| 1678 | + $ownerPath = ''; |
|
| 1679 | + } else { |
|
| 1680 | + $ownerPath = $ownerPath[3]; |
|
| 1681 | + } |
|
| 1682 | + $al['users'][$owner] = [ |
|
| 1683 | + 'node_id' => $path->getId(), |
|
| 1684 | + 'node_path' => '/' . $ownerPath, |
|
| 1685 | + ]; |
|
| 1686 | + } else { |
|
| 1687 | + $al['users'][] = $owner; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + // Collect all the shares |
|
| 1691 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
| 1692 | + $nodes[] = $path; |
|
| 1693 | + if (!$recursive) { |
|
| 1694 | + break; |
|
| 1695 | + } |
|
| 1696 | + $path = $path->getParent(); |
|
| 1697 | + } |
|
| 1698 | + |
|
| 1699 | + foreach ($providers as $provider) { |
|
| 1700 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
| 1701 | + |
|
| 1702 | + foreach ($tmp as $k => $v) { |
|
| 1703 | + if (isset($al[$k])) { |
|
| 1704 | + if (is_array($al[$k])) { |
|
| 1705 | + if ($currentAccess) { |
|
| 1706 | + $al[$k] += $v; |
|
| 1707 | + } else { |
|
| 1708 | + $al[$k] = array_merge($al[$k], $v); |
|
| 1709 | + $al[$k] = array_unique($al[$k]); |
|
| 1710 | + $al[$k] = array_values($al[$k]); |
|
| 1711 | + } |
|
| 1712 | + } else { |
|
| 1713 | + $al[$k] = $al[$k] || $v; |
|
| 1714 | + } |
|
| 1715 | + } else { |
|
| 1716 | + $al[$k] = $v; |
|
| 1717 | + } |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + return $al; |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + /** |
|
| 1725 | + * Create a new share |
|
| 1726 | + * |
|
| 1727 | + * @return IShare |
|
| 1728 | + */ |
|
| 1729 | + public function newShare() { |
|
| 1730 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + /** |
|
| 1734 | + * Is the share API enabled |
|
| 1735 | + * |
|
| 1736 | + * @return bool |
|
| 1737 | + */ |
|
| 1738 | + public function shareApiEnabled() { |
|
| 1739 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + /** |
|
| 1743 | + * Is public link sharing enabled |
|
| 1744 | + * |
|
| 1745 | + * @return bool |
|
| 1746 | + */ |
|
| 1747 | + public function shareApiAllowLinks() { |
|
| 1748 | + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 1749 | + return false; |
|
| 1750 | + } |
|
| 1751 | + |
|
| 1752 | + $user = $this->userSession->getUser(); |
|
| 1753 | + if ($user) { |
|
| 1754 | + $excludedGroups = json_decode($this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', '[]')); |
|
| 1755 | + if ($excludedGroups) { |
|
| 1756 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1757 | + return !(bool)array_intersect($excludedGroups, $userGroups); |
|
| 1758 | + } |
|
| 1759 | + } |
|
| 1760 | + |
|
| 1761 | + return true; |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + /** |
|
| 1765 | + * Is password on public link requires |
|
| 1766 | + * |
|
| 1767 | + * @param bool Check group membership exclusion |
|
| 1768 | + * @return bool |
|
| 1769 | + */ |
|
| 1770 | + public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true) { |
|
| 1771 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', ''); |
|
| 1772 | + if ($excludedGroups !== '' && $checkGroupMembership) { |
|
| 1773 | + $excludedGroups = json_decode($excludedGroups); |
|
| 1774 | + $user = $this->userSession->getUser(); |
|
| 1775 | + if ($user) { |
|
| 1776 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
| 1777 | + if ((bool)array_intersect($excludedGroups, $userGroups)) { |
|
| 1778 | + return false; |
|
| 1779 | + } |
|
| 1780 | + } |
|
| 1781 | + } |
|
| 1782 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + /** |
|
| 1786 | + * Is default link expire date enabled |
|
| 1787 | + * |
|
| 1788 | + * @return bool |
|
| 1789 | + */ |
|
| 1790 | + public function shareApiLinkDefaultExpireDate() { |
|
| 1791 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + /** |
|
| 1795 | + * Is default link expire date enforced |
|
| 1796 | + *` |
|
| 1797 | + * |
|
| 1798 | + * @return bool |
|
| 1799 | + */ |
|
| 1800 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
| 1801 | + return $this->shareApiLinkDefaultExpireDate() && |
|
| 1802 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + |
|
| 1806 | + /** |
|
| 1807 | + * Number of default link expire days |
|
| 1808 | + * |
|
| 1809 | + * @return int |
|
| 1810 | + */ |
|
| 1811 | + public function shareApiLinkDefaultExpireDays() { |
|
| 1812 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 1813 | + } |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Is default internal expire date enabled |
|
| 1817 | + * |
|
| 1818 | + * @return bool |
|
| 1819 | + */ |
|
| 1820 | + public function shareApiInternalDefaultExpireDate(): bool { |
|
| 1821 | + return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
| 1822 | + } |
|
| 1823 | + |
|
| 1824 | + /** |
|
| 1825 | + * Is default remote expire date enabled |
|
| 1826 | + * |
|
| 1827 | + * @return bool |
|
| 1828 | + */ |
|
| 1829 | + public function shareApiRemoteDefaultExpireDate(): bool { |
|
| 1830 | + return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes'; |
|
| 1831 | + } |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * Is default expire date enforced |
|
| 1835 | + * |
|
| 1836 | + * @return bool |
|
| 1837 | + */ |
|
| 1838 | + public function shareApiInternalDefaultExpireDateEnforced(): bool { |
|
| 1839 | + return $this->shareApiInternalDefaultExpireDate() && |
|
| 1840 | + $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + /** |
|
| 1844 | + * Is default expire date enforced for remote shares |
|
| 1845 | + * |
|
| 1846 | + * @return bool |
|
| 1847 | + */ |
|
| 1848 | + public function shareApiRemoteDefaultExpireDateEnforced(): bool { |
|
| 1849 | + return $this->shareApiRemoteDefaultExpireDate() && |
|
| 1850 | + $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes'; |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + /** |
|
| 1854 | + * Number of default expire days |
|
| 1855 | + * |
|
| 1856 | + * @return int |
|
| 1857 | + */ |
|
| 1858 | + public function shareApiInternalDefaultExpireDays(): int { |
|
| 1859 | + return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * Number of default expire days for remote shares |
|
| 1864 | + * |
|
| 1865 | + * @return int |
|
| 1866 | + */ |
|
| 1867 | + public function shareApiRemoteDefaultExpireDays(): int { |
|
| 1868 | + return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'); |
|
| 1869 | + } |
|
| 1870 | + |
|
| 1871 | + /** |
|
| 1872 | + * Allow public upload on link shares |
|
| 1873 | + * |
|
| 1874 | + * @return bool |
|
| 1875 | + */ |
|
| 1876 | + public function shareApiLinkAllowPublicUpload() { |
|
| 1877 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 1878 | + } |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * check if user can only share with group members |
|
| 1882 | + * |
|
| 1883 | + * @return bool |
|
| 1884 | + */ |
|
| 1885 | + public function shareWithGroupMembersOnly() { |
|
| 1886 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + /** |
|
| 1890 | + * If shareWithGroupMembersOnly is enabled, return an optional |
|
| 1891 | + * list of groups that must be excluded from the principle of |
|
| 1892 | + * belonging to the same group. |
|
| 1893 | + * |
|
| 1894 | + * @return array |
|
| 1895 | + */ |
|
| 1896 | + public function shareWithGroupMembersOnlyExcludeGroupsList() { |
|
| 1897 | + if (!$this->shareWithGroupMembersOnly()) { |
|
| 1898 | + return []; |
|
| 1899 | + } |
|
| 1900 | + $excludeGroups = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''); |
|
| 1901 | + return json_decode($excludeGroups, true) ?? []; |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + /** |
|
| 1905 | + * Check if users can share with groups |
|
| 1906 | + * |
|
| 1907 | + * @return bool |
|
| 1908 | + */ |
|
| 1909 | + public function allowGroupSharing() { |
|
| 1910 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 1911 | + } |
|
| 1912 | + |
|
| 1913 | + public function allowEnumeration(): bool { |
|
| 1914 | + return $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + public function limitEnumerationToGroups(): bool { |
|
| 1918 | + return $this->allowEnumeration() && |
|
| 1919 | + $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + public function limitEnumerationToPhone(): bool { |
|
| 1923 | + return $this->allowEnumeration() && |
|
| 1924 | + $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + public function allowEnumerationFullMatch(): bool { |
|
| 1928 | + return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + public function matchEmail(): bool { |
|
| 1932 | + return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
| 1933 | + } |
|
| 1934 | + |
|
| 1935 | + public function ignoreSecondDisplayName(): bool { |
|
| 1936 | + return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no') === 'yes'; |
|
| 1937 | + } |
|
| 1938 | + |
|
| 1939 | + public function allowCustomTokens(): bool { |
|
| 1940 | + return $this->appConfig->getValueBool('core', 'shareapi_allow_custom_tokens', false); |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + public function allowViewWithoutDownload(): bool { |
|
| 1944 | + return $this->appConfig->getValueBool('core', 'shareapi_allow_view_without_download', true); |
|
| 1945 | + } |
|
| 1946 | + |
|
| 1947 | + public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool { |
|
| 1948 | + if ($this->allowEnumerationFullMatch()) { |
|
| 1949 | + return true; |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + if (!$this->allowEnumeration()) { |
|
| 1953 | + return false; |
|
| 1954 | + } |
|
| 1955 | + |
|
| 1956 | + if (!$this->limitEnumerationToPhone() && !$this->limitEnumerationToGroups()) { |
|
| 1957 | + // Enumeration is enabled and not restricted: OK |
|
| 1958 | + return true; |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + if (!$currentUser instanceof IUser) { |
|
| 1962 | + // Enumeration restrictions require an account |
|
| 1963 | + return false; |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + // Enumeration is limited to phone match |
|
| 1967 | + if ($this->limitEnumerationToPhone() && $this->knownUserService->isKnownToUser($currentUser->getUID(), $targetUser->getUID())) { |
|
| 1968 | + return true; |
|
| 1969 | + } |
|
| 1970 | + |
|
| 1971 | + // Enumeration is limited to groups |
|
| 1972 | + if ($this->limitEnumerationToGroups()) { |
|
| 1973 | + $currentUserGroupIds = $this->groupManager->getUserGroupIds($currentUser); |
|
| 1974 | + $targetUserGroupIds = $this->groupManager->getUserGroupIds($targetUser); |
|
| 1975 | + if (!empty(array_intersect($currentUserGroupIds, $targetUserGroupIds))) { |
|
| 1976 | + return true; |
|
| 1977 | + } |
|
| 1978 | + } |
|
| 1979 | + |
|
| 1980 | + return false; |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * Check if sharing is disabled for the current user |
|
| 1985 | + */ |
|
| 1986 | + public function sharingDisabledForUser(?string $userId): bool { |
|
| 1987 | + return $this->shareDisableChecker->sharingDisabledForUser($userId); |
|
| 1988 | + } |
|
| 1989 | + |
|
| 1990 | + /** |
|
| 1991 | + * @inheritdoc |
|
| 1992 | + */ |
|
| 1993 | + public function outgoingServer2ServerSharesAllowed() { |
|
| 1994 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * @inheritdoc |
|
| 1999 | + */ |
|
| 2000 | + public function outgoingServer2ServerGroupSharesAllowed() { |
|
| 2001 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
| 2002 | + } |
|
| 2003 | + |
|
| 2004 | + /** |
|
| 2005 | + * @inheritdoc |
|
| 2006 | + */ |
|
| 2007 | + public function shareProviderExists($shareType) { |
|
| 2008 | + try { |
|
| 2009 | + $this->factory->getProviderForType($shareType); |
|
| 2010 | + } catch (ProviderException $e) { |
|
| 2011 | + return false; |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + return true; |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + public function registerShareProvider(string $shareProviderClass): void { |
|
| 2018 | + $this->factory->registerProvider($shareProviderClass); |
|
| 2019 | + } |
|
| 2020 | + |
|
| 2021 | + public function getAllShares(): iterable { |
|
| 2022 | + $providers = $this->factory->getAllProviders(); |
|
| 2023 | + |
|
| 2024 | + foreach ($providers as $provider) { |
|
| 2025 | + yield from $provider->getAllShares(); |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + public function generateToken(): string { |
|
| 2030 | + // Initial token length |
|
| 2031 | + $tokenLength = \OC\Share\Helper::getTokenLength(); |
|
| 2032 | + |
|
| 2033 | + do { |
|
| 2034 | + $tokenExists = false; |
|
| 2035 | + |
|
| 2036 | + for ($i = 0; $i <= 2; $i++) { |
|
| 2037 | + // Generate a new token |
|
| 2038 | + $token = $this->secureRandom->generate( |
|
| 2039 | + $tokenLength, |
|
| 2040 | + ISecureRandom::CHAR_HUMAN_READABLE, |
|
| 2041 | + ); |
|
| 2042 | + |
|
| 2043 | + try { |
|
| 2044 | + // Try to fetch a share with the generated token |
|
| 2045 | + $this->getShareByToken($token); |
|
| 2046 | + $tokenExists = true; // Token exists, we need to try again |
|
| 2047 | + } catch (ShareNotFound $e) { |
|
| 2048 | + // Token is unique, exit the loop |
|
| 2049 | + $tokenExists = false; |
|
| 2050 | + break; |
|
| 2051 | + } |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + // If we've reached the maximum attempts and the token still exists, increase the token length |
|
| 2055 | + if ($tokenExists) { |
|
| 2056 | + $tokenLength++; |
|
| 2057 | + |
|
| 2058 | + // Check if the token length exceeds the maximum allowed length |
|
| 2059 | + if ($tokenLength > \OC\Share\Constants::MAX_TOKEN_LENGTH) { |
|
| 2060 | + throw new ShareTokenException('Unable to generate a unique share token. Maximum token length exceeded.'); |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + } while ($tokenExists); |
|
| 2064 | + |
|
| 2065 | + return $token; |
|
| 2066 | + } |
|
| 2067 | 2067 | } |
@@ -17,104 +17,104 @@ |
||
| 17 | 17 | use OCP\Util; |
| 18 | 18 | |
| 19 | 19 | class Sharing implements IDelegatedSettings { |
| 20 | - public function __construct( |
|
| 21 | - private IConfig $config, |
|
| 22 | - private IL10N $l, |
|
| 23 | - private IManager $shareManager, |
|
| 24 | - private IAppManager $appManager, |
|
| 25 | - private IURLGenerator $urlGenerator, |
|
| 26 | - private IInitialState $initialState, |
|
| 27 | - private string $appName, |
|
| 28 | - ) { |
|
| 29 | - } |
|
| 20 | + public function __construct( |
|
| 21 | + private IConfig $config, |
|
| 22 | + private IL10N $l, |
|
| 23 | + private IManager $shareManager, |
|
| 24 | + private IAppManager $appManager, |
|
| 25 | + private IURLGenerator $urlGenerator, |
|
| 26 | + private IInitialState $initialState, |
|
| 27 | + private string $appName, |
|
| 28 | + ) { |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @return TemplateResponse |
|
| 33 | - */ |
|
| 34 | - public function getForm() { |
|
| 35 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 36 | - $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', ''); |
|
| 37 | - $excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', ''); |
|
| 38 | - $onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''); |
|
| 31 | + /** |
|
| 32 | + * @return TemplateResponse |
|
| 33 | + */ |
|
| 34 | + public function getForm() { |
|
| 35 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 36 | + $linksExcludedGroups = $this->config->getAppValue('core', 'shareapi_allow_links_exclude_groups', ''); |
|
| 37 | + $excludedPasswordGroups = $this->config->getAppValue('core', 'shareapi_enforce_links_password_excluded_groups', ''); |
|
| 38 | + $onlyShareWithGroupMembersExcludeGroupList = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''); |
|
| 39 | 39 | |
| 40 | - $parameters = [ |
|
| 41 | - // Built-In Sharing |
|
| 42 | - 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true), |
|
| 43 | - 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true), |
|
| 44 | - 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true), |
|
| 45 | - 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [], |
|
| 46 | - 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true), |
|
| 47 | - 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true), |
|
| 48 | - 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true), |
|
| 49 | - 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'), |
|
| 50 | - 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'), |
|
| 51 | - 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true), |
|
| 52 | - 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true), |
|
| 53 | - 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true), |
|
| 54 | - 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'), |
|
| 55 | - 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false), |
|
| 56 | - 'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [], |
|
| 57 | - 'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false), |
|
| 58 | - 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(), |
|
| 59 | - 'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [], |
|
| 60 | - 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'), |
|
| 61 | - 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
| 62 | - 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'), |
|
| 63 | - 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'), |
|
| 64 | - 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [], |
|
| 65 | - 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'), |
|
| 66 | - 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'), |
|
| 67 | - 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL), |
|
| 68 | - 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'), |
|
| 69 | - 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'), |
|
| 70 | - 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'), |
|
| 71 | - 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'), |
|
| 72 | - 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'), |
|
| 73 | - 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'), |
|
| 74 | - 'allowCustomTokens' => $this->shareManager->allowCustomTokens(), |
|
| 75 | - 'allowViewWithoutDownload' => $this->shareManager->allowViewWithoutDownload(), |
|
| 76 | - ]; |
|
| 40 | + $parameters = [ |
|
| 41 | + // Built-In Sharing |
|
| 42 | + 'enabled' => $this->getHumanBooleanConfig('core', 'shareapi_enabled', true), |
|
| 43 | + 'allowGroupSharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_group_sharing', true), |
|
| 44 | + 'allowLinks' => $this->getHumanBooleanConfig('core', 'shareapi_allow_links', true), |
|
| 45 | + 'allowLinksExcludeGroups' => json_decode($linksExcludedGroups, true) ?? [], |
|
| 46 | + 'allowPublicUpload' => $this->getHumanBooleanConfig('core', 'shareapi_allow_public_upload', true), |
|
| 47 | + 'allowResharing' => $this->getHumanBooleanConfig('core', 'shareapi_allow_resharing', true), |
|
| 48 | + 'allowShareDialogUserEnumeration' => $this->getHumanBooleanConfig('core', 'shareapi_allow_share_dialog_user_enumeration', true), |
|
| 49 | + 'restrictUserEnumerationToGroup' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_group'), |
|
| 50 | + 'restrictUserEnumerationToPhone' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_to_phone'), |
|
| 51 | + 'restrictUserEnumerationFullMatch' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match', true), |
|
| 52 | + 'restrictUserEnumerationFullMatchUserId' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_userid', true), |
|
| 53 | + 'restrictUserEnumerationFullMatchEmail' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_email', true), |
|
| 54 | + 'restrictUserEnumerationFullMatchIgnoreSecondDN' => $this->getHumanBooleanConfig('core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn'), |
|
| 55 | + 'enforceLinksPassword' => Util::isPublicLinkPasswordRequired(false), |
|
| 56 | + 'enforceLinksPasswordExcludedGroups' => json_decode($excludedPasswordGroups) ?? [], |
|
| 57 | + 'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false), |
|
| 58 | + 'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(), |
|
| 59 | + 'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [], |
|
| 60 | + 'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'), |
|
| 61 | + 'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
| 62 | + 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'), |
|
| 63 | + 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'), |
|
| 64 | + 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [], |
|
| 65 | + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'), |
|
| 66 | + 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'), |
|
| 67 | + 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL), |
|
| 68 | + 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'), |
|
| 69 | + 'internalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'), |
|
| 70 | + 'enforceInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_internal_expire_date'), |
|
| 71 | + 'defaultRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_remote_expire_date'), |
|
| 72 | + 'remoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'), |
|
| 73 | + 'enforceRemoteExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_remote_expire_date'), |
|
| 74 | + 'allowCustomTokens' => $this->shareManager->allowCustomTokens(), |
|
| 75 | + 'allowViewWithoutDownload' => $this->shareManager->allowViewWithoutDownload(), |
|
| 76 | + ]; |
|
| 77 | 77 | |
| 78 | - $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing')); |
|
| 79 | - $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing')); |
|
| 80 | - $this->initialState->provideInitialState('sharingSettings', $parameters); |
|
| 78 | + $this->initialState->provideInitialState('sharingAppEnabled', $this->appManager->isEnabledForUser('files_sharing')); |
|
| 79 | + $this->initialState->provideInitialState('sharingDocumentation', $this->urlGenerator->linkToDocs('admin-sharing')); |
|
| 80 | + $this->initialState->provideInitialState('sharingSettings', $parameters); |
|
| 81 | 81 | |
| 82 | - Util::addScript($this->appName, 'vue-settings-admin-sharing'); |
|
| 83 | - return new TemplateResponse($this->appName, 'settings/admin/sharing', [], ''); |
|
| 84 | - } |
|
| 82 | + Util::addScript($this->appName, 'vue-settings-admin-sharing'); |
|
| 83 | + return new TemplateResponse($this->appName, 'settings/admin/sharing', [], ''); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Helper function to retrive boolean values from human readable strings ('yes' / 'no') |
|
| 88 | - */ |
|
| 89 | - private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool { |
|
| 90 | - return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes'; |
|
| 91 | - } |
|
| 86 | + /** |
|
| 87 | + * Helper function to retrive boolean values from human readable strings ('yes' / 'no') |
|
| 88 | + */ |
|
| 89 | + private function getHumanBooleanConfig(string $app, string $key, bool $default = false): bool { |
|
| 90 | + return $this->config->getAppValue($app, $key, $default ? 'yes' : 'no') === 'yes'; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return string the section ID, e.g. 'sharing' |
|
| 95 | - */ |
|
| 96 | - public function getSection() { |
|
| 97 | - return 'sharing'; |
|
| 98 | - } |
|
| 93 | + /** |
|
| 94 | + * @return string the section ID, e.g. 'sharing' |
|
| 95 | + */ |
|
| 96 | + public function getSection() { |
|
| 97 | + return 'sharing'; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return int whether the form should be rather on the top or bottom of |
|
| 102 | - * the admin section. The forms are arranged in ascending order of the |
|
| 103 | - * priority values. It is required to return a value between 0 and 100. |
|
| 104 | - * |
|
| 105 | - * E.g.: 70 |
|
| 106 | - */ |
|
| 107 | - public function getPriority() { |
|
| 108 | - return 0; |
|
| 109 | - } |
|
| 100 | + /** |
|
| 101 | + * @return int whether the form should be rather on the top or bottom of |
|
| 102 | + * the admin section. The forms are arranged in ascending order of the |
|
| 103 | + * priority values. It is required to return a value between 0 and 100. |
|
| 104 | + * |
|
| 105 | + * E.g.: 70 |
|
| 106 | + */ |
|
| 107 | + public function getPriority() { |
|
| 108 | + return 0; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function getAuthorizedAppConfig(): array { |
|
| 112 | - return [ |
|
| 113 | - 'core' => ['/shareapi_.*/'], |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 111 | + public function getAuthorizedAppConfig(): array { |
|
| 112 | + return [ |
|
| 113 | + 'core' => ['/shareapi_.*/'], |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function getName(): ?string { |
|
| 118 | - return null; |
|
| 119 | - } |
|
| 117 | + public function getName(): ?string { |
|
| 118 | + return null; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -53,410 +53,410 @@ |
||
| 53 | 53 | * @package OCA\Files\Controller |
| 54 | 54 | */ |
| 55 | 55 | class ApiController extends Controller { |
| 56 | - public function __construct( |
|
| 57 | - string $appName, |
|
| 58 | - IRequest $request, |
|
| 59 | - private IUserSession $userSession, |
|
| 60 | - private TagService $tagService, |
|
| 61 | - private IPreview $previewManager, |
|
| 62 | - private IManager $shareManager, |
|
| 63 | - private IConfig $config, |
|
| 64 | - private ?Folder $userFolder, |
|
| 65 | - private UserConfig $userConfig, |
|
| 66 | - private ViewConfig $viewConfig, |
|
| 67 | - private IL10N $l10n, |
|
| 68 | - private IRootFolder $rootFolder, |
|
| 69 | - private LoggerInterface $logger, |
|
| 70 | - ) { |
|
| 71 | - parent::__construct($appName, $request); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Gets a thumbnail of the specified file |
|
| 76 | - * |
|
| 77 | - * @since API version 1.0 |
|
| 78 | - * @deprecated 32.0.0 Use the preview endpoint provided by core instead |
|
| 79 | - * |
|
| 80 | - * @param int $x Width of the thumbnail |
|
| 81 | - * @param int $y Height of the thumbnail |
|
| 82 | - * @param string $file URL-encoded filename |
|
| 83 | - * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{message?: string}, array{}> |
|
| 84 | - * |
|
| 85 | - * 200: Thumbnail returned |
|
| 86 | - * 400: Getting thumbnail is not possible |
|
| 87 | - * 404: File not found |
|
| 88 | - */ |
|
| 89 | - #[NoAdminRequired] |
|
| 90 | - #[NoCSRFRequired] |
|
| 91 | - #[StrictCookiesRequired] |
|
| 92 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 93 | - public function getThumbnail($x, $y, $file) { |
|
| 94 | - if ($x < 1 || $y < 1) { |
|
| 95 | - return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - try { |
|
| 99 | - $file = $this->userFolder?->get($file); |
|
| 100 | - if ($file === null |
|
| 101 | - || !($file instanceof File) |
|
| 102 | - || ($file->getId() <= 0) |
|
| 103 | - ) { |
|
| 104 | - throw new NotFoundException(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Validate the user is allowed to download the file (preview is some kind of download) |
|
| 108 | - /** @var ISharedStorage $storage */ |
|
| 109 | - $storage = $file->getStorage(); |
|
| 110 | - if ($storage->instanceOfStorage(ISharedStorage::class)) { |
|
| 111 | - /** @var IShare $share */ |
|
| 112 | - $share = $storage->getShare(); |
|
| 113 | - if (!$share->canSeeContent()) { |
|
| 114 | - throw new NotFoundException(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
| 119 | - |
|
| 120 | - return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
| 121 | - } catch (NotFoundException|NotPermittedException|InvalidPathException) { |
|
| 122 | - return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 123 | - } catch (\Exception $e) { |
|
| 124 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Updates the info of the specified file path |
|
| 130 | - * The passed tags are absolute, which means they will |
|
| 131 | - * replace the actual tag selection. |
|
| 132 | - * |
|
| 133 | - * @param string $path path |
|
| 134 | - * @param array|string $tags array of tags |
|
| 135 | - * @return DataResponse |
|
| 136 | - */ |
|
| 137 | - #[NoAdminRequired] |
|
| 138 | - public function updateFileTags($path, $tags = null) { |
|
| 139 | - $result = []; |
|
| 140 | - // if tags specified or empty array, update tags |
|
| 141 | - if (!is_null($tags)) { |
|
| 142 | - try { |
|
| 143 | - $this->tagService->updateFileTags($path, $tags); |
|
| 144 | - } catch (NotFoundException $e) { |
|
| 145 | - return new DataResponse([ |
|
| 146 | - 'message' => $e->getMessage() |
|
| 147 | - ], Http::STATUS_NOT_FOUND); |
|
| 148 | - } catch (StorageNotAvailableException $e) { |
|
| 149 | - return new DataResponse([ |
|
| 150 | - 'message' => $e->getMessage() |
|
| 151 | - ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 152 | - } catch (\Exception $e) { |
|
| 153 | - return new DataResponse([ |
|
| 154 | - 'message' => $e->getMessage() |
|
| 155 | - ], Http::STATUS_NOT_FOUND); |
|
| 156 | - } |
|
| 157 | - $result['tags'] = $tags; |
|
| 158 | - } |
|
| 159 | - return new DataResponse($result); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param \OCP\Files\Node[] $nodes |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - private function formatNodes(array $nodes) { |
|
| 167 | - $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
| 168 | - return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
| 169 | - $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
| 170 | - $file = Helper::formatFileInfo($node->getFileInfo()); |
|
| 171 | - $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
| 172 | - $parts = explode('/', dirname($node->getPath()), 4); |
|
| 173 | - if (isset($parts[3])) { |
|
| 174 | - $file['path'] = '/' . $parts[3]; |
|
| 175 | - } else { |
|
| 176 | - $file['path'] = '/'; |
|
| 177 | - } |
|
| 178 | - if (!empty($shareTypes)) { |
|
| 179 | - $file['shareTypes'] = $shareTypes; |
|
| 180 | - } |
|
| 181 | - return $file; |
|
| 182 | - }, $nodes)); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Get the share types for each node |
|
| 187 | - * |
|
| 188 | - * @param \OCP\Files\Node[] $nodes |
|
| 189 | - * @return array<int, int[]> list of share types for each fileid |
|
| 190 | - */ |
|
| 191 | - private function getShareTypesForNodes(array $nodes): array { |
|
| 192 | - $userId = $this->userSession->getUser()->getUID(); |
|
| 193 | - $requestedShareTypes = [ |
|
| 194 | - IShare::TYPE_USER, |
|
| 195 | - IShare::TYPE_GROUP, |
|
| 196 | - IShare::TYPE_LINK, |
|
| 197 | - IShare::TYPE_REMOTE, |
|
| 198 | - IShare::TYPE_EMAIL, |
|
| 199 | - IShare::TYPE_ROOM, |
|
| 200 | - IShare::TYPE_DECK, |
|
| 201 | - IShare::TYPE_SCIENCEMESH, |
|
| 202 | - ]; |
|
| 203 | - $shareTypes = []; |
|
| 204 | - |
|
| 205 | - $nodeIds = array_map(function (Node $node) { |
|
| 206 | - return $node->getId(); |
|
| 207 | - }, $nodes); |
|
| 208 | - |
|
| 209 | - foreach ($requestedShareTypes as $shareType) { |
|
| 210 | - $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
| 211 | - $offset = 0; |
|
| 212 | - |
|
| 213 | - // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
| 214 | - while (count($nodesLeft) > 0) { |
|
| 215 | - $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
| 216 | - foreach ($shares as $share) { |
|
| 217 | - $fileId = $share->getNodeId(); |
|
| 218 | - if (isset($nodesLeft[$fileId])) { |
|
| 219 | - if (!isset($shareTypes[$fileId])) { |
|
| 220 | - $shareTypes[$fileId] = []; |
|
| 221 | - } |
|
| 222 | - $shareTypes[$fileId][] = $shareType; |
|
| 223 | - unset($nodesLeft[$fileId]); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if (count($shares) < 100) { |
|
| 228 | - break; |
|
| 229 | - } else { |
|
| 230 | - $offset += count($shares); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - return $shareTypes; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Returns a list of recently modified files. |
|
| 239 | - * |
|
| 240 | - * @return DataResponse |
|
| 241 | - */ |
|
| 242 | - #[NoAdminRequired] |
|
| 243 | - public function getRecentFiles() { |
|
| 244 | - $nodes = $this->userFolder->getRecent(100); |
|
| 245 | - $files = $this->formatNodes($nodes); |
|
| 246 | - return new DataResponse(['files' => $files]); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param \OCP\Files\Node[] $nodes |
|
| 251 | - * @param int $depth The depth to traverse into the contents of each node |
|
| 252 | - */ |
|
| 253 | - private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0): array { |
|
| 254 | - if ($currentDepth >= $depth) { |
|
| 255 | - return []; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $children = []; |
|
| 259 | - foreach ($nodes as $node) { |
|
| 260 | - if (!($node instanceof Folder)) { |
|
| 261 | - continue; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $basename = basename($node->getPath()); |
|
| 265 | - $entry = [ |
|
| 266 | - 'id' => $node->getId(), |
|
| 267 | - 'basename' => $basename, |
|
| 268 | - 'children' => $this->getChildren($node->getDirectoryListing(), $depth, $currentDepth + 1), |
|
| 269 | - ]; |
|
| 270 | - $displayName = $node->getName(); |
|
| 271 | - if ($basename !== $displayName) { |
|
| 272 | - $entry['displayName'] = $displayName; |
|
| 273 | - } |
|
| 274 | - $children[] = $entry; |
|
| 275 | - } |
|
| 276 | - return $children; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Returns the folder tree of the user |
|
| 281 | - * |
|
| 282 | - * @param string $path The path relative to the user folder |
|
| 283 | - * @param int $depth The depth of the tree |
|
| 284 | - * |
|
| 285 | - * @return JSONResponse<Http::STATUS_OK, FilesFolderTree, array{}>|JSONResponse<Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{message: string}, array{}> |
|
| 286 | - * |
|
| 287 | - * 200: Folder tree returned successfully |
|
| 288 | - * 400: Invalid folder path |
|
| 289 | - * 401: Unauthorized |
|
| 290 | - * 404: Folder not found |
|
| 291 | - */ |
|
| 292 | - #[NoAdminRequired] |
|
| 293 | - #[ApiRoute(verb: 'GET', url: '/api/v1/folder-tree')] |
|
| 294 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 295 | - public function getFolderTree(string $path = '/', int $depth = 1): JSONResponse { |
|
| 296 | - $user = $this->userSession->getUser(); |
|
| 297 | - if (!($user instanceof IUser)) { |
|
| 298 | - return new JSONResponse([ |
|
| 299 | - 'message' => $this->l10n->t('Failed to authorize'), |
|
| 300 | - ], Http::STATUS_UNAUTHORIZED); |
|
| 301 | - } |
|
| 302 | - try { |
|
| 303 | - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
| 304 | - $userFolderPath = $userFolder->getPath(); |
|
| 305 | - $fullPath = implode('/', [$userFolderPath, trim($path, '/')]); |
|
| 306 | - $node = $this->rootFolder->get($fullPath); |
|
| 307 | - if (!($node instanceof Folder)) { |
|
| 308 | - return new JSONResponse([ |
|
| 309 | - 'message' => $this->l10n->t('Invalid folder path'), |
|
| 310 | - ], Http::STATUS_BAD_REQUEST); |
|
| 311 | - } |
|
| 312 | - $nodes = $node->getDirectoryListing(); |
|
| 313 | - $tree = $this->getChildren($nodes, $depth); |
|
| 314 | - } catch (NotFoundException $e) { |
|
| 315 | - return new JSONResponse([ |
|
| 316 | - 'message' => $this->l10n->t('Folder not found'), |
|
| 317 | - ], Http::STATUS_NOT_FOUND); |
|
| 318 | - } catch (Throwable $th) { |
|
| 319 | - $this->logger->error($th->getMessage(), ['exception' => $th]); |
|
| 320 | - $tree = []; |
|
| 321 | - } |
|
| 322 | - return new JSONResponse($tree); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Returns the current logged-in user's storage stats. |
|
| 327 | - * |
|
| 328 | - * @param ?string $dir the directory to get the storage stats from |
|
| 329 | - * @return JSONResponse |
|
| 330 | - */ |
|
| 331 | - #[NoAdminRequired] |
|
| 332 | - public function getStorageStats($dir = '/'): JSONResponse { |
|
| 333 | - $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
| 334 | - $response = new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
| 335 | - $response->cacheFor(5 * 60); |
|
| 336 | - return $response; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Set a user view config |
|
| 341 | - * |
|
| 342 | - * @param string $view |
|
| 343 | - * @param string $key |
|
| 344 | - * @param string|bool $value |
|
| 345 | - * @return JSONResponse |
|
| 346 | - */ |
|
| 347 | - #[NoAdminRequired] |
|
| 348 | - public function setViewConfig(string $view, string $key, $value): JSONResponse { |
|
| 349 | - try { |
|
| 350 | - $this->viewConfig->setConfig($view, $key, (string)$value); |
|
| 351 | - } catch (\InvalidArgumentException $e) { |
|
| 352 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfig($view)]); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Get the user view config |
|
| 361 | - * |
|
| 362 | - * @return JSONResponse |
|
| 363 | - */ |
|
| 364 | - #[NoAdminRequired] |
|
| 365 | - public function getViewConfigs(): JSONResponse { |
|
| 366 | - return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfigs()]); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Set a user config |
|
| 371 | - * |
|
| 372 | - * @param string $key |
|
| 373 | - * @param string|bool $value |
|
| 374 | - * @return JSONResponse |
|
| 375 | - */ |
|
| 376 | - #[NoAdminRequired] |
|
| 377 | - public function setConfig(string $key, $value): JSONResponse { |
|
| 378 | - try { |
|
| 379 | - $this->userConfig->setConfig($key, (string)$value); |
|
| 380 | - } catch (\InvalidArgumentException $e) { |
|
| 381 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Get the user config |
|
| 390 | - * |
|
| 391 | - * @return JSONResponse |
|
| 392 | - */ |
|
| 393 | - #[NoAdminRequired] |
|
| 394 | - public function getConfigs(): JSONResponse { |
|
| 395 | - return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Toggle default for showing/hiding hidden files |
|
| 400 | - * |
|
| 401 | - * @param bool $value |
|
| 402 | - * @return Response |
|
| 403 | - * @throws PreConditionNotMetException |
|
| 404 | - */ |
|
| 405 | - #[NoAdminRequired] |
|
| 406 | - public function showHiddenFiles(bool $value): Response { |
|
| 407 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
| 408 | - return new Response(); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Toggle default for cropping preview images |
|
| 413 | - * |
|
| 414 | - * @param bool $value |
|
| 415 | - * @return Response |
|
| 416 | - * @throws PreConditionNotMetException |
|
| 417 | - */ |
|
| 418 | - #[NoAdminRequired] |
|
| 419 | - public function cropImagePreviews(bool $value): Response { |
|
| 420 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
| 421 | - return new Response(); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Toggle default for files grid view |
|
| 426 | - * |
|
| 427 | - * @param bool $show |
|
| 428 | - * @return Response |
|
| 429 | - * @throws PreConditionNotMetException |
|
| 430 | - */ |
|
| 431 | - #[NoAdminRequired] |
|
| 432 | - public function showGridView(bool $show): Response { |
|
| 433 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
| 434 | - return new Response(); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Get default settings for the grid view |
|
| 439 | - */ |
|
| 440 | - #[NoAdminRequired] |
|
| 441 | - public function getGridView() { |
|
| 442 | - $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
| 443 | - return new JSONResponse(['gridview' => $status]); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - #[PublicPage] |
|
| 447 | - #[NoCSRFRequired] |
|
| 448 | - #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] |
|
| 449 | - public function serviceWorker(): StreamResponse { |
|
| 450 | - $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js'); |
|
| 451 | - $response->setHeaders([ |
|
| 452 | - 'Content-Type' => 'application/javascript', |
|
| 453 | - 'Service-Worker-Allowed' => '/' |
|
| 454 | - ]); |
|
| 455 | - $policy = new ContentSecurityPolicy(); |
|
| 456 | - $policy->addAllowedWorkerSrcDomain("'self'"); |
|
| 457 | - $policy->addAllowedScriptDomain("'self'"); |
|
| 458 | - $policy->addAllowedConnectDomain("'self'"); |
|
| 459 | - $response->setContentSecurityPolicy($policy); |
|
| 460 | - return $response; |
|
| 461 | - } |
|
| 56 | + public function __construct( |
|
| 57 | + string $appName, |
|
| 58 | + IRequest $request, |
|
| 59 | + private IUserSession $userSession, |
|
| 60 | + private TagService $tagService, |
|
| 61 | + private IPreview $previewManager, |
|
| 62 | + private IManager $shareManager, |
|
| 63 | + private IConfig $config, |
|
| 64 | + private ?Folder $userFolder, |
|
| 65 | + private UserConfig $userConfig, |
|
| 66 | + private ViewConfig $viewConfig, |
|
| 67 | + private IL10N $l10n, |
|
| 68 | + private IRootFolder $rootFolder, |
|
| 69 | + private LoggerInterface $logger, |
|
| 70 | + ) { |
|
| 71 | + parent::__construct($appName, $request); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Gets a thumbnail of the specified file |
|
| 76 | + * |
|
| 77 | + * @since API version 1.0 |
|
| 78 | + * @deprecated 32.0.0 Use the preview endpoint provided by core instead |
|
| 79 | + * |
|
| 80 | + * @param int $x Width of the thumbnail |
|
| 81 | + * @param int $y Height of the thumbnail |
|
| 82 | + * @param string $file URL-encoded filename |
|
| 83 | + * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{message?: string}, array{}> |
|
| 84 | + * |
|
| 85 | + * 200: Thumbnail returned |
|
| 86 | + * 400: Getting thumbnail is not possible |
|
| 87 | + * 404: File not found |
|
| 88 | + */ |
|
| 89 | + #[NoAdminRequired] |
|
| 90 | + #[NoCSRFRequired] |
|
| 91 | + #[StrictCookiesRequired] |
|
| 92 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 93 | + public function getThumbnail($x, $y, $file) { |
|
| 94 | + if ($x < 1 || $y < 1) { |
|
| 95 | + return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + try { |
|
| 99 | + $file = $this->userFolder?->get($file); |
|
| 100 | + if ($file === null |
|
| 101 | + || !($file instanceof File) |
|
| 102 | + || ($file->getId() <= 0) |
|
| 103 | + ) { |
|
| 104 | + throw new NotFoundException(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Validate the user is allowed to download the file (preview is some kind of download) |
|
| 108 | + /** @var ISharedStorage $storage */ |
|
| 109 | + $storage = $file->getStorage(); |
|
| 110 | + if ($storage->instanceOfStorage(ISharedStorage::class)) { |
|
| 111 | + /** @var IShare $share */ |
|
| 112 | + $share = $storage->getShare(); |
|
| 113 | + if (!$share->canSeeContent()) { |
|
| 114 | + throw new NotFoundException(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $preview = $this->previewManager->getPreview($file, $x, $y, true); |
|
| 119 | + |
|
| 120 | + return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]); |
|
| 121 | + } catch (NotFoundException|NotPermittedException|InvalidPathException) { |
|
| 122 | + return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 123 | + } catch (\Exception $e) { |
|
| 124 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Updates the info of the specified file path |
|
| 130 | + * The passed tags are absolute, which means they will |
|
| 131 | + * replace the actual tag selection. |
|
| 132 | + * |
|
| 133 | + * @param string $path path |
|
| 134 | + * @param array|string $tags array of tags |
|
| 135 | + * @return DataResponse |
|
| 136 | + */ |
|
| 137 | + #[NoAdminRequired] |
|
| 138 | + public function updateFileTags($path, $tags = null) { |
|
| 139 | + $result = []; |
|
| 140 | + // if tags specified or empty array, update tags |
|
| 141 | + if (!is_null($tags)) { |
|
| 142 | + try { |
|
| 143 | + $this->tagService->updateFileTags($path, $tags); |
|
| 144 | + } catch (NotFoundException $e) { |
|
| 145 | + return new DataResponse([ |
|
| 146 | + 'message' => $e->getMessage() |
|
| 147 | + ], Http::STATUS_NOT_FOUND); |
|
| 148 | + } catch (StorageNotAvailableException $e) { |
|
| 149 | + return new DataResponse([ |
|
| 150 | + 'message' => $e->getMessage() |
|
| 151 | + ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 152 | + } catch (\Exception $e) { |
|
| 153 | + return new DataResponse([ |
|
| 154 | + 'message' => $e->getMessage() |
|
| 155 | + ], Http::STATUS_NOT_FOUND); |
|
| 156 | + } |
|
| 157 | + $result['tags'] = $tags; |
|
| 158 | + } |
|
| 159 | + return new DataResponse($result); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param \OCP\Files\Node[] $nodes |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + private function formatNodes(array $nodes) { |
|
| 167 | + $shareTypesForNodes = $this->getShareTypesForNodes($nodes); |
|
| 168 | + return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { |
|
| 169 | + $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; |
|
| 170 | + $file = Helper::formatFileInfo($node->getFileInfo()); |
|
| 171 | + $file['hasPreview'] = $this->previewManager->isAvailable($node); |
|
| 172 | + $parts = explode('/', dirname($node->getPath()), 4); |
|
| 173 | + if (isset($parts[3])) { |
|
| 174 | + $file['path'] = '/' . $parts[3]; |
|
| 175 | + } else { |
|
| 176 | + $file['path'] = '/'; |
|
| 177 | + } |
|
| 178 | + if (!empty($shareTypes)) { |
|
| 179 | + $file['shareTypes'] = $shareTypes; |
|
| 180 | + } |
|
| 181 | + return $file; |
|
| 182 | + }, $nodes)); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Get the share types for each node |
|
| 187 | + * |
|
| 188 | + * @param \OCP\Files\Node[] $nodes |
|
| 189 | + * @return array<int, int[]> list of share types for each fileid |
|
| 190 | + */ |
|
| 191 | + private function getShareTypesForNodes(array $nodes): array { |
|
| 192 | + $userId = $this->userSession->getUser()->getUID(); |
|
| 193 | + $requestedShareTypes = [ |
|
| 194 | + IShare::TYPE_USER, |
|
| 195 | + IShare::TYPE_GROUP, |
|
| 196 | + IShare::TYPE_LINK, |
|
| 197 | + IShare::TYPE_REMOTE, |
|
| 198 | + IShare::TYPE_EMAIL, |
|
| 199 | + IShare::TYPE_ROOM, |
|
| 200 | + IShare::TYPE_DECK, |
|
| 201 | + IShare::TYPE_SCIENCEMESH, |
|
| 202 | + ]; |
|
| 203 | + $shareTypes = []; |
|
| 204 | + |
|
| 205 | + $nodeIds = array_map(function (Node $node) { |
|
| 206 | + return $node->getId(); |
|
| 207 | + }, $nodes); |
|
| 208 | + |
|
| 209 | + foreach ($requestedShareTypes as $shareType) { |
|
| 210 | + $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true)); |
|
| 211 | + $offset = 0; |
|
| 212 | + |
|
| 213 | + // fetch shares until we've either found shares for all nodes or there are no more shares left |
|
| 214 | + while (count($nodesLeft) > 0) { |
|
| 215 | + $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset); |
|
| 216 | + foreach ($shares as $share) { |
|
| 217 | + $fileId = $share->getNodeId(); |
|
| 218 | + if (isset($nodesLeft[$fileId])) { |
|
| 219 | + if (!isset($shareTypes[$fileId])) { |
|
| 220 | + $shareTypes[$fileId] = []; |
|
| 221 | + } |
|
| 222 | + $shareTypes[$fileId][] = $shareType; |
|
| 223 | + unset($nodesLeft[$fileId]); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if (count($shares) < 100) { |
|
| 228 | + break; |
|
| 229 | + } else { |
|
| 230 | + $offset += count($shares); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + return $shareTypes; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Returns a list of recently modified files. |
|
| 239 | + * |
|
| 240 | + * @return DataResponse |
|
| 241 | + */ |
|
| 242 | + #[NoAdminRequired] |
|
| 243 | + public function getRecentFiles() { |
|
| 244 | + $nodes = $this->userFolder->getRecent(100); |
|
| 245 | + $files = $this->formatNodes($nodes); |
|
| 246 | + return new DataResponse(['files' => $files]); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param \OCP\Files\Node[] $nodes |
|
| 251 | + * @param int $depth The depth to traverse into the contents of each node |
|
| 252 | + */ |
|
| 253 | + private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0): array { |
|
| 254 | + if ($currentDepth >= $depth) { |
|
| 255 | + return []; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $children = []; |
|
| 259 | + foreach ($nodes as $node) { |
|
| 260 | + if (!($node instanceof Folder)) { |
|
| 261 | + continue; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $basename = basename($node->getPath()); |
|
| 265 | + $entry = [ |
|
| 266 | + 'id' => $node->getId(), |
|
| 267 | + 'basename' => $basename, |
|
| 268 | + 'children' => $this->getChildren($node->getDirectoryListing(), $depth, $currentDepth + 1), |
|
| 269 | + ]; |
|
| 270 | + $displayName = $node->getName(); |
|
| 271 | + if ($basename !== $displayName) { |
|
| 272 | + $entry['displayName'] = $displayName; |
|
| 273 | + } |
|
| 274 | + $children[] = $entry; |
|
| 275 | + } |
|
| 276 | + return $children; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Returns the folder tree of the user |
|
| 281 | + * |
|
| 282 | + * @param string $path The path relative to the user folder |
|
| 283 | + * @param int $depth The depth of the tree |
|
| 284 | + * |
|
| 285 | + * @return JSONResponse<Http::STATUS_OK, FilesFolderTree, array{}>|JSONResponse<Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{message: string}, array{}> |
|
| 286 | + * |
|
| 287 | + * 200: Folder tree returned successfully |
|
| 288 | + * 400: Invalid folder path |
|
| 289 | + * 401: Unauthorized |
|
| 290 | + * 404: Folder not found |
|
| 291 | + */ |
|
| 292 | + #[NoAdminRequired] |
|
| 293 | + #[ApiRoute(verb: 'GET', url: '/api/v1/folder-tree')] |
|
| 294 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 295 | + public function getFolderTree(string $path = '/', int $depth = 1): JSONResponse { |
|
| 296 | + $user = $this->userSession->getUser(); |
|
| 297 | + if (!($user instanceof IUser)) { |
|
| 298 | + return new JSONResponse([ |
|
| 299 | + 'message' => $this->l10n->t('Failed to authorize'), |
|
| 300 | + ], Http::STATUS_UNAUTHORIZED); |
|
| 301 | + } |
|
| 302 | + try { |
|
| 303 | + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
| 304 | + $userFolderPath = $userFolder->getPath(); |
|
| 305 | + $fullPath = implode('/', [$userFolderPath, trim($path, '/')]); |
|
| 306 | + $node = $this->rootFolder->get($fullPath); |
|
| 307 | + if (!($node instanceof Folder)) { |
|
| 308 | + return new JSONResponse([ |
|
| 309 | + 'message' => $this->l10n->t('Invalid folder path'), |
|
| 310 | + ], Http::STATUS_BAD_REQUEST); |
|
| 311 | + } |
|
| 312 | + $nodes = $node->getDirectoryListing(); |
|
| 313 | + $tree = $this->getChildren($nodes, $depth); |
|
| 314 | + } catch (NotFoundException $e) { |
|
| 315 | + return new JSONResponse([ |
|
| 316 | + 'message' => $this->l10n->t('Folder not found'), |
|
| 317 | + ], Http::STATUS_NOT_FOUND); |
|
| 318 | + } catch (Throwable $th) { |
|
| 319 | + $this->logger->error($th->getMessage(), ['exception' => $th]); |
|
| 320 | + $tree = []; |
|
| 321 | + } |
|
| 322 | + return new JSONResponse($tree); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Returns the current logged-in user's storage stats. |
|
| 327 | + * |
|
| 328 | + * @param ?string $dir the directory to get the storage stats from |
|
| 329 | + * @return JSONResponse |
|
| 330 | + */ |
|
| 331 | + #[NoAdminRequired] |
|
| 332 | + public function getStorageStats($dir = '/'): JSONResponse { |
|
| 333 | + $storageInfo = \OC_Helper::getStorageInfo($dir ?: '/'); |
|
| 334 | + $response = new JSONResponse(['message' => 'ok', 'data' => $storageInfo]); |
|
| 335 | + $response->cacheFor(5 * 60); |
|
| 336 | + return $response; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Set a user view config |
|
| 341 | + * |
|
| 342 | + * @param string $view |
|
| 343 | + * @param string $key |
|
| 344 | + * @param string|bool $value |
|
| 345 | + * @return JSONResponse |
|
| 346 | + */ |
|
| 347 | + #[NoAdminRequired] |
|
| 348 | + public function setViewConfig(string $view, string $key, $value): JSONResponse { |
|
| 349 | + try { |
|
| 350 | + $this->viewConfig->setConfig($view, $key, (string)$value); |
|
| 351 | + } catch (\InvalidArgumentException $e) { |
|
| 352 | + return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfig($view)]); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Get the user view config |
|
| 361 | + * |
|
| 362 | + * @return JSONResponse |
|
| 363 | + */ |
|
| 364 | + #[NoAdminRequired] |
|
| 365 | + public function getViewConfigs(): JSONResponse { |
|
| 366 | + return new JSONResponse(['message' => 'ok', 'data' => $this->viewConfig->getConfigs()]); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Set a user config |
|
| 371 | + * |
|
| 372 | + * @param string $key |
|
| 373 | + * @param string|bool $value |
|
| 374 | + * @return JSONResponse |
|
| 375 | + */ |
|
| 376 | + #[NoAdminRequired] |
|
| 377 | + public function setConfig(string $key, $value): JSONResponse { |
|
| 378 | + try { |
|
| 379 | + $this->userConfig->setConfig($key, (string)$value); |
|
| 380 | + } catch (\InvalidArgumentException $e) { |
|
| 381 | + return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + return new JSONResponse(['message' => 'ok', 'data' => ['key' => $key, 'value' => $value]]); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Get the user config |
|
| 390 | + * |
|
| 391 | + * @return JSONResponse |
|
| 392 | + */ |
|
| 393 | + #[NoAdminRequired] |
|
| 394 | + public function getConfigs(): JSONResponse { |
|
| 395 | + return new JSONResponse(['message' => 'ok', 'data' => $this->userConfig->getConfigs()]); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Toggle default for showing/hiding hidden files |
|
| 400 | + * |
|
| 401 | + * @param bool $value |
|
| 402 | + * @return Response |
|
| 403 | + * @throws PreConditionNotMetException |
|
| 404 | + */ |
|
| 405 | + #[NoAdminRequired] |
|
| 406 | + public function showHiddenFiles(bool $value): Response { |
|
| 407 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', $value ? '1' : '0'); |
|
| 408 | + return new Response(); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Toggle default for cropping preview images |
|
| 413 | + * |
|
| 414 | + * @param bool $value |
|
| 415 | + * @return Response |
|
| 416 | + * @throws PreConditionNotMetException |
|
| 417 | + */ |
|
| 418 | + #[NoAdminRequired] |
|
| 419 | + public function cropImagePreviews(bool $value): Response { |
|
| 420 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', $value ? '1' : '0'); |
|
| 421 | + return new Response(); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Toggle default for files grid view |
|
| 426 | + * |
|
| 427 | + * @param bool $show |
|
| 428 | + * @return Response |
|
| 429 | + * @throws PreConditionNotMetException |
|
| 430 | + */ |
|
| 431 | + #[NoAdminRequired] |
|
| 432 | + public function showGridView(bool $show): Response { |
|
| 433 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', $show ? '1' : '0'); |
|
| 434 | + return new Response(); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Get default settings for the grid view |
|
| 439 | + */ |
|
| 440 | + #[NoAdminRequired] |
|
| 441 | + public function getGridView() { |
|
| 442 | + $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1'; |
|
| 443 | + return new JSONResponse(['gridview' => $status]); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + #[PublicPage] |
|
| 447 | + #[NoCSRFRequired] |
|
| 448 | + #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] |
|
| 449 | + public function serviceWorker(): StreamResponse { |
|
| 450 | + $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js'); |
|
| 451 | + $response->setHeaders([ |
|
| 452 | + 'Content-Type' => 'application/javascript', |
|
| 453 | + 'Service-Worker-Allowed' => '/' |
|
| 454 | + ]); |
|
| 455 | + $policy = new ContentSecurityPolicy(); |
|
| 456 | + $policy->addAllowedWorkerSrcDomain("'self'"); |
|
| 457 | + $policy->addAllowedScriptDomain("'self'"); |
|
| 458 | + $policy->addAllowedConnectDomain("'self'"); |
|
| 459 | + $response->setContentSecurityPolicy($policy); |
|
| 460 | + return $response; |
|
| 461 | + } |
|
| 462 | 462 | } |
@@ -41,260 +41,260 @@ |
||
| 41 | 41 | * @package OCA\Files\Controller |
| 42 | 42 | */ |
| 43 | 43 | class ApiControllerTest extends TestCase { |
| 44 | - private string $appName = 'files'; |
|
| 45 | - private IUser $user; |
|
| 46 | - private IRequest $request; |
|
| 47 | - private TagService $tagService; |
|
| 48 | - private IPreview&MockObject $preview; |
|
| 49 | - private ApiController $apiController; |
|
| 50 | - private IManager $shareManager; |
|
| 51 | - private IConfig $config; |
|
| 52 | - private Folder&MockObject $userFolder; |
|
| 53 | - private UserConfig&MockObject $userConfig; |
|
| 54 | - private ViewConfig&MockObject $viewConfig; |
|
| 55 | - private IL10N&MockObject $l10n; |
|
| 56 | - private IRootFolder&MockObject $rootFolder; |
|
| 57 | - private LoggerInterface&MockObject $logger; |
|
| 58 | - |
|
| 59 | - protected function setUp(): void { |
|
| 60 | - parent::setUp(); |
|
| 61 | - |
|
| 62 | - $this->request = $this->createMock(IRequest::class); |
|
| 63 | - $this->user = $this->createMock(IUser::class); |
|
| 64 | - $this->user->expects($this->any()) |
|
| 65 | - ->method('getUID') |
|
| 66 | - ->willReturn('user1'); |
|
| 67 | - $userSession = $this->createMock(IUserSession::class); |
|
| 68 | - $userSession->expects($this->any()) |
|
| 69 | - ->method('getUser') |
|
| 70 | - ->willReturn($this->user); |
|
| 71 | - $this->tagService = $this->createMock(TagService::class); |
|
| 72 | - $this->shareManager = $this->createMock(IManager::class); |
|
| 73 | - $this->preview = $this->createMock(IPreview::class); |
|
| 74 | - $this->config = $this->createMock(IConfig::class); |
|
| 75 | - $this->userFolder = $this->createMock(Folder::class); |
|
| 76 | - $this->userConfig = $this->createMock(UserConfig::class); |
|
| 77 | - $this->viewConfig = $this->createMock(ViewConfig::class); |
|
| 78 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 79 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 80 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 81 | - |
|
| 82 | - $this->apiController = new ApiController( |
|
| 83 | - $this->appName, |
|
| 84 | - $this->request, |
|
| 85 | - $userSession, |
|
| 86 | - $this->tagService, |
|
| 87 | - $this->preview, |
|
| 88 | - $this->shareManager, |
|
| 89 | - $this->config, |
|
| 90 | - $this->userFolder, |
|
| 91 | - $this->userConfig, |
|
| 92 | - $this->viewConfig, |
|
| 93 | - $this->l10n, |
|
| 94 | - $this->rootFolder, |
|
| 95 | - $this->logger, |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function testUpdateFileTagsEmpty(): void { |
|
| 100 | - $expected = new DataResponse([]); |
|
| 101 | - $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt')); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function testUpdateFileTagsWorking(): void { |
|
| 105 | - $this->tagService->expects($this->once()) |
|
| 106 | - ->method('updateFileTags') |
|
| 107 | - ->with('/path.txt', ['Tag1', 'Tag2']); |
|
| 108 | - |
|
| 109 | - $expected = new DataResponse([ |
|
| 110 | - 'tags' => [ |
|
| 111 | - 'Tag1', |
|
| 112 | - 'Tag2' |
|
| 113 | - ], |
|
| 114 | - ]); |
|
| 115 | - $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function testUpdateFileTagsNotFoundException(): void { |
|
| 119 | - $this->tagService->expects($this->once()) |
|
| 120 | - ->method('updateFileTags') |
|
| 121 | - ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 122 | - ->will($this->throwException(new NotFoundException('My error message'))); |
|
| 123 | - |
|
| 124 | - $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); |
|
| 125 | - $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function testUpdateFileTagsStorageNotAvailableException(): void { |
|
| 129 | - $this->tagService->expects($this->once()) |
|
| 130 | - ->method('updateFileTags') |
|
| 131 | - ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 132 | - ->will($this->throwException(new StorageNotAvailableException('My error message'))); |
|
| 133 | - |
|
| 134 | - $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 135 | - $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function testUpdateFileTagsStorageGenericException(): void { |
|
| 139 | - $this->tagService->expects($this->once()) |
|
| 140 | - ->method('updateFileTags') |
|
| 141 | - ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 142 | - ->will($this->throwException(new \Exception('My error message'))); |
|
| 143 | - |
|
| 144 | - $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); |
|
| 145 | - $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function testGetThumbnailInvalidSize(): void { |
|
| 149 | - $this->userFolder->method('get') |
|
| 150 | - ->with($this->equalTo('')) |
|
| 151 | - ->willThrowException(new NotFoundException()); |
|
| 152 | - $expected = new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 153 | - $this->assertEquals($expected, $this->apiController->getThumbnail(0, 0, '')); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function testGetThumbnailInvalidImage(): void { |
|
| 157 | - $storage = $this->createMock(IStorage::class); |
|
| 158 | - $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false); |
|
| 159 | - |
|
| 160 | - $file = $this->createMock(File::class); |
|
| 161 | - $file->method('getId')->willReturn(123); |
|
| 162 | - $file->method('getStorage')->willReturn($storage); |
|
| 163 | - $this->userFolder->method('get') |
|
| 164 | - ->with($this->equalTo('unknown.jpg')) |
|
| 165 | - ->willReturn($file); |
|
| 166 | - $this->preview->expects($this->once()) |
|
| 167 | - ->method('getPreview') |
|
| 168 | - ->with($file, 10, 10, true) |
|
| 169 | - ->willThrowException(new NotFoundException()); |
|
| 170 | - $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 171 | - $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - public function testGetThumbnailInvalidPartFile(): void { |
|
| 175 | - $file = $this->createMock(File::class); |
|
| 176 | - $file->method('getId')->willReturn(0); |
|
| 177 | - $this->userFolder->method('get') |
|
| 178 | - ->with($this->equalTo('unknown.jpg')) |
|
| 179 | - ->willReturn($file); |
|
| 180 | - $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 181 | - $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - public function testGetThumbnailSharedNoDownload(): void { |
|
| 185 | - $share = $this->createMock(IShare::class); |
|
| 186 | - $share->expects(self::once()) |
|
| 187 | - ->method('canSeeContent') |
|
| 188 | - ->willReturn(false); |
|
| 189 | - |
|
| 190 | - $storage = $this->createMock(ISharedStorage::class); |
|
| 191 | - $storage->expects(self::once()) |
|
| 192 | - ->method('instanceOfStorage') |
|
| 193 | - ->with(ISharedStorage::class) |
|
| 194 | - ->willReturn(true); |
|
| 195 | - $storage->expects(self::once()) |
|
| 196 | - ->method('getShare') |
|
| 197 | - ->willReturn($share); |
|
| 198 | - |
|
| 199 | - $file = $this->createMock(File::class); |
|
| 200 | - $file->method('getId')->willReturn(123); |
|
| 201 | - $file->method('getStorage')->willReturn($storage); |
|
| 202 | - |
|
| 203 | - $this->userFolder->method('get') |
|
| 204 | - ->with('unknown.jpg') |
|
| 205 | - ->willReturn($file); |
|
| 206 | - |
|
| 207 | - $this->preview->expects($this->never()) |
|
| 208 | - ->method('getPreview'); |
|
| 209 | - |
|
| 210 | - $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 211 | - $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - public function testGetThumbnailShared(): void { |
|
| 215 | - $share = $this->createMock(IShare::class); |
|
| 216 | - $share->expects(self::once()) |
|
| 217 | - ->method('canSeeContent') |
|
| 218 | - ->willReturn(true); |
|
| 219 | - |
|
| 220 | - $storage = $this->createMock(ISharedStorage::class); |
|
| 221 | - $storage->expects(self::once()) |
|
| 222 | - ->method('instanceOfStorage') |
|
| 223 | - ->with(ISharedStorage::class) |
|
| 224 | - ->willReturn(true); |
|
| 225 | - $storage->expects(self::once()) |
|
| 226 | - ->method('getShare') |
|
| 227 | - ->willReturn($share); |
|
| 228 | - |
|
| 229 | - $file = $this->createMock(File::class); |
|
| 230 | - $file->method('getId')->willReturn(123); |
|
| 231 | - $file->method('getStorage')->willReturn($storage); |
|
| 232 | - |
|
| 233 | - $this->userFolder->method('get') |
|
| 234 | - ->with($this->equalTo('known.jpg')) |
|
| 235 | - ->willReturn($file); |
|
| 236 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 237 | - $preview->method('getName')->willReturn('my name'); |
|
| 238 | - $preview->method('getMTime')->willReturn(42); |
|
| 239 | - $this->preview->expects($this->once()) |
|
| 240 | - ->method('getPreview') |
|
| 241 | - ->with($this->equalTo($file), 10, 10, true) |
|
| 242 | - ->willReturn($preview); |
|
| 243 | - |
|
| 244 | - $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); |
|
| 245 | - |
|
| 246 | - $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); |
|
| 247 | - $this->assertInstanceOf(FileDisplayResponse::class, $ret); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function testGetThumbnail(): void { |
|
| 251 | - $storage = $this->createMock(IStorage::class); |
|
| 252 | - $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false); |
|
| 253 | - |
|
| 254 | - $file = $this->createMock(File::class); |
|
| 255 | - $file->method('getId')->willReturn(123); |
|
| 256 | - $file->method('getStorage')->willReturn($storage); |
|
| 257 | - |
|
| 258 | - $this->userFolder->method('get') |
|
| 259 | - ->with($this->equalTo('known.jpg')) |
|
| 260 | - ->willReturn($file); |
|
| 261 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 262 | - $preview->method('getName')->willReturn('my name'); |
|
| 263 | - $preview->method('getMTime')->willReturn(42); |
|
| 264 | - $this->preview->expects($this->once()) |
|
| 265 | - ->method('getPreview') |
|
| 266 | - ->with($this->equalTo($file), 10, 10, true) |
|
| 267 | - ->willReturn($preview); |
|
| 268 | - |
|
| 269 | - $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); |
|
| 270 | - |
|
| 271 | - $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); |
|
| 272 | - $this->assertInstanceOf(FileDisplayResponse::class, $ret); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function testShowHiddenFiles(): void { |
|
| 276 | - $show = false; |
|
| 277 | - |
|
| 278 | - $this->config->expects($this->once()) |
|
| 279 | - ->method('setUserValue') |
|
| 280 | - ->with($this->user->getUID(), 'files', 'show_hidden', '0'); |
|
| 281 | - |
|
| 282 | - $expected = new Response(); |
|
| 283 | - $actual = $this->apiController->showHiddenFiles($show); |
|
| 284 | - |
|
| 285 | - $this->assertEquals($expected, $actual); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - public function testCropImagePreviews(): void { |
|
| 289 | - $crop = true; |
|
| 290 | - |
|
| 291 | - $this->config->expects($this->once()) |
|
| 292 | - ->method('setUserValue') |
|
| 293 | - ->with($this->user->getUID(), 'files', 'crop_image_previews', '1'); |
|
| 294 | - |
|
| 295 | - $expected = new Response(); |
|
| 296 | - $actual = $this->apiController->cropImagePreviews($crop); |
|
| 297 | - |
|
| 298 | - $this->assertEquals($expected, $actual); |
|
| 299 | - } |
|
| 44 | + private string $appName = 'files'; |
|
| 45 | + private IUser $user; |
|
| 46 | + private IRequest $request; |
|
| 47 | + private TagService $tagService; |
|
| 48 | + private IPreview&MockObject $preview; |
|
| 49 | + private ApiController $apiController; |
|
| 50 | + private IManager $shareManager; |
|
| 51 | + private IConfig $config; |
|
| 52 | + private Folder&MockObject $userFolder; |
|
| 53 | + private UserConfig&MockObject $userConfig; |
|
| 54 | + private ViewConfig&MockObject $viewConfig; |
|
| 55 | + private IL10N&MockObject $l10n; |
|
| 56 | + private IRootFolder&MockObject $rootFolder; |
|
| 57 | + private LoggerInterface&MockObject $logger; |
|
| 58 | + |
|
| 59 | + protected function setUp(): void { |
|
| 60 | + parent::setUp(); |
|
| 61 | + |
|
| 62 | + $this->request = $this->createMock(IRequest::class); |
|
| 63 | + $this->user = $this->createMock(IUser::class); |
|
| 64 | + $this->user->expects($this->any()) |
|
| 65 | + ->method('getUID') |
|
| 66 | + ->willReturn('user1'); |
|
| 67 | + $userSession = $this->createMock(IUserSession::class); |
|
| 68 | + $userSession->expects($this->any()) |
|
| 69 | + ->method('getUser') |
|
| 70 | + ->willReturn($this->user); |
|
| 71 | + $this->tagService = $this->createMock(TagService::class); |
|
| 72 | + $this->shareManager = $this->createMock(IManager::class); |
|
| 73 | + $this->preview = $this->createMock(IPreview::class); |
|
| 74 | + $this->config = $this->createMock(IConfig::class); |
|
| 75 | + $this->userFolder = $this->createMock(Folder::class); |
|
| 76 | + $this->userConfig = $this->createMock(UserConfig::class); |
|
| 77 | + $this->viewConfig = $this->createMock(ViewConfig::class); |
|
| 78 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 79 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
| 80 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 81 | + |
|
| 82 | + $this->apiController = new ApiController( |
|
| 83 | + $this->appName, |
|
| 84 | + $this->request, |
|
| 85 | + $userSession, |
|
| 86 | + $this->tagService, |
|
| 87 | + $this->preview, |
|
| 88 | + $this->shareManager, |
|
| 89 | + $this->config, |
|
| 90 | + $this->userFolder, |
|
| 91 | + $this->userConfig, |
|
| 92 | + $this->viewConfig, |
|
| 93 | + $this->l10n, |
|
| 94 | + $this->rootFolder, |
|
| 95 | + $this->logger, |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function testUpdateFileTagsEmpty(): void { |
|
| 100 | + $expected = new DataResponse([]); |
|
| 101 | + $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt')); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function testUpdateFileTagsWorking(): void { |
|
| 105 | + $this->tagService->expects($this->once()) |
|
| 106 | + ->method('updateFileTags') |
|
| 107 | + ->with('/path.txt', ['Tag1', 'Tag2']); |
|
| 108 | + |
|
| 109 | + $expected = new DataResponse([ |
|
| 110 | + 'tags' => [ |
|
| 111 | + 'Tag1', |
|
| 112 | + 'Tag2' |
|
| 113 | + ], |
|
| 114 | + ]); |
|
| 115 | + $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function testUpdateFileTagsNotFoundException(): void { |
|
| 119 | + $this->tagService->expects($this->once()) |
|
| 120 | + ->method('updateFileTags') |
|
| 121 | + ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 122 | + ->will($this->throwException(new NotFoundException('My error message'))); |
|
| 123 | + |
|
| 124 | + $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); |
|
| 125 | + $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function testUpdateFileTagsStorageNotAvailableException(): void { |
|
| 129 | + $this->tagService->expects($this->once()) |
|
| 130 | + ->method('updateFileTags') |
|
| 131 | + ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 132 | + ->will($this->throwException(new StorageNotAvailableException('My error message'))); |
|
| 133 | + |
|
| 134 | + $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 135 | + $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function testUpdateFileTagsStorageGenericException(): void { |
|
| 139 | + $this->tagService->expects($this->once()) |
|
| 140 | + ->method('updateFileTags') |
|
| 141 | + ->with('/path.txt', ['Tag1', 'Tag2']) |
|
| 142 | + ->will($this->throwException(new \Exception('My error message'))); |
|
| 143 | + |
|
| 144 | + $expected = new DataResponse(['message' => 'My error message'], Http::STATUS_NOT_FOUND); |
|
| 145 | + $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt', ['Tag1', 'Tag2'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function testGetThumbnailInvalidSize(): void { |
|
| 149 | + $this->userFolder->method('get') |
|
| 150 | + ->with($this->equalTo('')) |
|
| 151 | + ->willThrowException(new NotFoundException()); |
|
| 152 | + $expected = new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST); |
|
| 153 | + $this->assertEquals($expected, $this->apiController->getThumbnail(0, 0, '')); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function testGetThumbnailInvalidImage(): void { |
|
| 157 | + $storage = $this->createMock(IStorage::class); |
|
| 158 | + $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false); |
|
| 159 | + |
|
| 160 | + $file = $this->createMock(File::class); |
|
| 161 | + $file->method('getId')->willReturn(123); |
|
| 162 | + $file->method('getStorage')->willReturn($storage); |
|
| 163 | + $this->userFolder->method('get') |
|
| 164 | + ->with($this->equalTo('unknown.jpg')) |
|
| 165 | + ->willReturn($file); |
|
| 166 | + $this->preview->expects($this->once()) |
|
| 167 | + ->method('getPreview') |
|
| 168 | + ->with($file, 10, 10, true) |
|
| 169 | + ->willThrowException(new NotFoundException()); |
|
| 170 | + $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 171 | + $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + public function testGetThumbnailInvalidPartFile(): void { |
|
| 175 | + $file = $this->createMock(File::class); |
|
| 176 | + $file->method('getId')->willReturn(0); |
|
| 177 | + $this->userFolder->method('get') |
|
| 178 | + ->with($this->equalTo('unknown.jpg')) |
|
| 179 | + ->willReturn($file); |
|
| 180 | + $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 181 | + $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + public function testGetThumbnailSharedNoDownload(): void { |
|
| 185 | + $share = $this->createMock(IShare::class); |
|
| 186 | + $share->expects(self::once()) |
|
| 187 | + ->method('canSeeContent') |
|
| 188 | + ->willReturn(false); |
|
| 189 | + |
|
| 190 | + $storage = $this->createMock(ISharedStorage::class); |
|
| 191 | + $storage->expects(self::once()) |
|
| 192 | + ->method('instanceOfStorage') |
|
| 193 | + ->with(ISharedStorage::class) |
|
| 194 | + ->willReturn(true); |
|
| 195 | + $storage->expects(self::once()) |
|
| 196 | + ->method('getShare') |
|
| 197 | + ->willReturn($share); |
|
| 198 | + |
|
| 199 | + $file = $this->createMock(File::class); |
|
| 200 | + $file->method('getId')->willReturn(123); |
|
| 201 | + $file->method('getStorage')->willReturn($storage); |
|
| 202 | + |
|
| 203 | + $this->userFolder->method('get') |
|
| 204 | + ->with('unknown.jpg') |
|
| 205 | + ->willReturn($file); |
|
| 206 | + |
|
| 207 | + $this->preview->expects($this->never()) |
|
| 208 | + ->method('getPreview'); |
|
| 209 | + |
|
| 210 | + $expected = new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND); |
|
| 211 | + $this->assertEquals($expected, $this->apiController->getThumbnail(10, 10, 'unknown.jpg')); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + public function testGetThumbnailShared(): void { |
|
| 215 | + $share = $this->createMock(IShare::class); |
|
| 216 | + $share->expects(self::once()) |
|
| 217 | + ->method('canSeeContent') |
|
| 218 | + ->willReturn(true); |
|
| 219 | + |
|
| 220 | + $storage = $this->createMock(ISharedStorage::class); |
|
| 221 | + $storage->expects(self::once()) |
|
| 222 | + ->method('instanceOfStorage') |
|
| 223 | + ->with(ISharedStorage::class) |
|
| 224 | + ->willReturn(true); |
|
| 225 | + $storage->expects(self::once()) |
|
| 226 | + ->method('getShare') |
|
| 227 | + ->willReturn($share); |
|
| 228 | + |
|
| 229 | + $file = $this->createMock(File::class); |
|
| 230 | + $file->method('getId')->willReturn(123); |
|
| 231 | + $file->method('getStorage')->willReturn($storage); |
|
| 232 | + |
|
| 233 | + $this->userFolder->method('get') |
|
| 234 | + ->with($this->equalTo('known.jpg')) |
|
| 235 | + ->willReturn($file); |
|
| 236 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 237 | + $preview->method('getName')->willReturn('my name'); |
|
| 238 | + $preview->method('getMTime')->willReturn(42); |
|
| 239 | + $this->preview->expects($this->once()) |
|
| 240 | + ->method('getPreview') |
|
| 241 | + ->with($this->equalTo($file), 10, 10, true) |
|
| 242 | + ->willReturn($preview); |
|
| 243 | + |
|
| 244 | + $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); |
|
| 245 | + |
|
| 246 | + $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); |
|
| 247 | + $this->assertInstanceOf(FileDisplayResponse::class, $ret); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function testGetThumbnail(): void { |
|
| 251 | + $storage = $this->createMock(IStorage::class); |
|
| 252 | + $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false); |
|
| 253 | + |
|
| 254 | + $file = $this->createMock(File::class); |
|
| 255 | + $file->method('getId')->willReturn(123); |
|
| 256 | + $file->method('getStorage')->willReturn($storage); |
|
| 257 | + |
|
| 258 | + $this->userFolder->method('get') |
|
| 259 | + ->with($this->equalTo('known.jpg')) |
|
| 260 | + ->willReturn($file); |
|
| 261 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 262 | + $preview->method('getName')->willReturn('my name'); |
|
| 263 | + $preview->method('getMTime')->willReturn(42); |
|
| 264 | + $this->preview->expects($this->once()) |
|
| 265 | + ->method('getPreview') |
|
| 266 | + ->with($this->equalTo($file), 10, 10, true) |
|
| 267 | + ->willReturn($preview); |
|
| 268 | + |
|
| 269 | + $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); |
|
| 270 | + |
|
| 271 | + $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); |
|
| 272 | + $this->assertInstanceOf(FileDisplayResponse::class, $ret); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function testShowHiddenFiles(): void { |
|
| 276 | + $show = false; |
|
| 277 | + |
|
| 278 | + $this->config->expects($this->once()) |
|
| 279 | + ->method('setUserValue') |
|
| 280 | + ->with($this->user->getUID(), 'files', 'show_hidden', '0'); |
|
| 281 | + |
|
| 282 | + $expected = new Response(); |
|
| 283 | + $actual = $this->apiController->showHiddenFiles($show); |
|
| 284 | + |
|
| 285 | + $this->assertEquals($expected, $actual); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + public function testCropImagePreviews(): void { |
|
| 289 | + $crop = true; |
|
| 290 | + |
|
| 291 | + $this->config->expects($this->once()) |
|
| 292 | + ->method('setUserValue') |
|
| 293 | + ->with($this->user->getUID(), 'files', 'crop_image_previews', '1'); |
|
| 294 | + |
|
| 295 | + $expected = new Response(); |
|
| 296 | + $actual = $this->apiController->cropImagePreviews($crop); |
|
| 297 | + |
|
| 298 | + $this->assertEquals($expected, $actual); |
|
| 299 | + } |
|
| 300 | 300 | } |
@@ -26,180 +26,180 @@ |
||
| 26 | 26 | |
| 27 | 27 | class PublicPreviewController extends PublicShareController { |
| 28 | 28 | |
| 29 | - /** @var IShare */ |
|
| 30 | - private $share; |
|
| 31 | - |
|
| 32 | - public function __construct( |
|
| 33 | - string $appName, |
|
| 34 | - IRequest $request, |
|
| 35 | - private ShareManager $shareManager, |
|
| 36 | - ISession $session, |
|
| 37 | - private IPreview $previewManager, |
|
| 38 | - private IMimeIconProvider $mimeIconProvider, |
|
| 39 | - ) { |
|
| 40 | - parent::__construct($appName, $request, $session); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - protected function getPasswordHash(): ?string { |
|
| 44 | - return $this->share->getPassword(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function isValidToken(): bool { |
|
| 48 | - try { |
|
| 49 | - $this->share = $this->shareManager->getShareByToken($this->getToken()); |
|
| 50 | - return true; |
|
| 51 | - } catch (ShareNotFound $e) { |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function isPasswordProtected(): bool { |
|
| 57 | - return $this->share->getPassword() !== null; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get a preview for a shared file |
|
| 63 | - * |
|
| 64 | - * @param string $token Token of the share |
|
| 65 | - * @param string $file File in the share |
|
| 66 | - * @param int $x Width of the preview |
|
| 67 | - * @param int $y Height of the preview |
|
| 68 | - * @param bool $a Whether to not crop the preview |
|
| 69 | - * @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available |
|
| 70 | - * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}> |
|
| 71 | - * |
|
| 72 | - * 200: Preview returned |
|
| 73 | - * 303: Redirect to the mime icon url if mimeFallback is true |
|
| 74 | - * 400: Getting preview is not possible |
|
| 75 | - * 403: Getting preview is not allowed |
|
| 76 | - * 404: Share or preview not found |
|
| 77 | - */ |
|
| 78 | - #[PublicPage] |
|
| 79 | - #[NoCSRFRequired] |
|
| 80 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 81 | - public function getPreview( |
|
| 82 | - string $token, |
|
| 83 | - string $file = '', |
|
| 84 | - int $x = 32, |
|
| 85 | - int $y = 32, |
|
| 86 | - $a = false, |
|
| 87 | - bool $mimeFallback = false, |
|
| 88 | - ) { |
|
| 89 | - $cacheForSeconds = 60 * 60 * 24; // 1 day |
|
| 90 | - |
|
| 91 | - if ($token === '' || $x === 0 || $y === 0) { |
|
| 92 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - try { |
|
| 96 | - $share = $this->shareManager->getShareByToken($token); |
|
| 97 | - } catch (ShareNotFound $e) { |
|
| 98 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) { |
|
| 102 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Only explicitly set to false will forbid the download! |
|
| 106 | - $downloadForbidden = !$share->canSeeContent(); |
|
| 107 | - |
|
| 108 | - // Is this header is set it means our UI is doing a preview for no-download shares |
|
| 109 | - // we check a header so we at least prevent people from using the link directly (obfuscation) |
|
| 110 | - $isPublicPreview = $this->request->getHeader('x-nc-preview') === 'true'; |
|
| 111 | - |
|
| 112 | - if ($isPublicPreview && $downloadForbidden) { |
|
| 113 | - // Only cache for 15 minutes on public preview requests to quickly remove from cache |
|
| 114 | - $cacheForSeconds = 15 * 60; |
|
| 115 | - } elseif ($downloadForbidden) { |
|
| 116 | - // This is not a public share preview so we only allow a preview if download permissions are granted |
|
| 117 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - try { |
|
| 121 | - $node = $share->getNode(); |
|
| 122 | - if ($node instanceof Folder) { |
|
| 123 | - $file = $node->get($file); |
|
| 124 | - } else { |
|
| 125 | - $file = $node; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $f = $this->previewManager->getPreview($file, $x, $y, !$a); |
|
| 129 | - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 130 | - $response->cacheFor($cacheForSeconds); |
|
| 131 | - return $response; |
|
| 132 | - } catch (NotFoundException $e) { |
|
| 133 | - // If we have no preview enabled, we can redirect to the mime icon if any |
|
| 134 | - if ($mimeFallback) { |
|
| 135 | - if ($url = $this->mimeIconProvider->getMimeIconUrl($file->getMimeType())) { |
|
| 136 | - return new RedirectResponse($url); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 140 | - } catch (\InvalidArgumentException $e) { |
|
| 141 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @NoSameSiteCookieRequired |
|
| 147 | - * |
|
| 148 | - * Get a direct link preview for a shared file |
|
| 149 | - * |
|
| 150 | - * @param string $token Token of the share |
|
| 151 | - * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}> |
|
| 152 | - * |
|
| 153 | - * 200: Preview returned |
|
| 154 | - * 400: Getting preview is not possible |
|
| 155 | - * 403: Getting preview is not allowed |
|
| 156 | - * 404: Share or preview not found |
|
| 157 | - */ |
|
| 158 | - #[PublicPage] |
|
| 159 | - #[NoCSRFRequired] |
|
| 160 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 161 | - public function directLink(string $token) { |
|
| 162 | - // No token no image |
|
| 163 | - if ($token === '') { |
|
| 164 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // No share no image |
|
| 168 | - try { |
|
| 169 | - $share = $this->shareManager->getShareByToken($token); |
|
| 170 | - } catch (ShareNotFound $e) { |
|
| 171 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // No permissions no image |
|
| 175 | - if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) { |
|
| 176 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Password protected shares have no direct link! |
|
| 180 | - if ($share->getPassword() !== null) { |
|
| 181 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (!$share->canSeeContent()) { |
|
| 185 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - try { |
|
| 189 | - $node = $share->getNode(); |
|
| 190 | - if ($node instanceof Folder) { |
|
| 191 | - // Direct link only works for single files |
|
| 192 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $f = $this->previewManager->getPreview($node, -1, -1, false); |
|
| 196 | - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 197 | - $response->cacheFor(3600 * 24); |
|
| 198 | - return $response; |
|
| 199 | - } catch (NotFoundException $e) { |
|
| 200 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 201 | - } catch (\InvalidArgumentException $e) { |
|
| 202 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 203 | - } |
|
| 204 | - } |
|
| 29 | + /** @var IShare */ |
|
| 30 | + private $share; |
|
| 31 | + |
|
| 32 | + public function __construct( |
|
| 33 | + string $appName, |
|
| 34 | + IRequest $request, |
|
| 35 | + private ShareManager $shareManager, |
|
| 36 | + ISession $session, |
|
| 37 | + private IPreview $previewManager, |
|
| 38 | + private IMimeIconProvider $mimeIconProvider, |
|
| 39 | + ) { |
|
| 40 | + parent::__construct($appName, $request, $session); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + protected function getPasswordHash(): ?string { |
|
| 44 | + return $this->share->getPassword(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function isValidToken(): bool { |
|
| 48 | + try { |
|
| 49 | + $this->share = $this->shareManager->getShareByToken($this->getToken()); |
|
| 50 | + return true; |
|
| 51 | + } catch (ShareNotFound $e) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function isPasswordProtected(): bool { |
|
| 57 | + return $this->share->getPassword() !== null; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get a preview for a shared file |
|
| 63 | + * |
|
| 64 | + * @param string $token Token of the share |
|
| 65 | + * @param string $file File in the share |
|
| 66 | + * @param int $x Width of the preview |
|
| 67 | + * @param int $y Height of the preview |
|
| 68 | + * @param bool $a Whether to not crop the preview |
|
| 69 | + * @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available |
|
| 70 | + * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}> |
|
| 71 | + * |
|
| 72 | + * 200: Preview returned |
|
| 73 | + * 303: Redirect to the mime icon url if mimeFallback is true |
|
| 74 | + * 400: Getting preview is not possible |
|
| 75 | + * 403: Getting preview is not allowed |
|
| 76 | + * 404: Share or preview not found |
|
| 77 | + */ |
|
| 78 | + #[PublicPage] |
|
| 79 | + #[NoCSRFRequired] |
|
| 80 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 81 | + public function getPreview( |
|
| 82 | + string $token, |
|
| 83 | + string $file = '', |
|
| 84 | + int $x = 32, |
|
| 85 | + int $y = 32, |
|
| 86 | + $a = false, |
|
| 87 | + bool $mimeFallback = false, |
|
| 88 | + ) { |
|
| 89 | + $cacheForSeconds = 60 * 60 * 24; // 1 day |
|
| 90 | + |
|
| 91 | + if ($token === '' || $x === 0 || $y === 0) { |
|
| 92 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + try { |
|
| 96 | + $share = $this->shareManager->getShareByToken($token); |
|
| 97 | + } catch (ShareNotFound $e) { |
|
| 98 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) { |
|
| 102 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Only explicitly set to false will forbid the download! |
|
| 106 | + $downloadForbidden = !$share->canSeeContent(); |
|
| 107 | + |
|
| 108 | + // Is this header is set it means our UI is doing a preview for no-download shares |
|
| 109 | + // we check a header so we at least prevent people from using the link directly (obfuscation) |
|
| 110 | + $isPublicPreview = $this->request->getHeader('x-nc-preview') === 'true'; |
|
| 111 | + |
|
| 112 | + if ($isPublicPreview && $downloadForbidden) { |
|
| 113 | + // Only cache for 15 minutes on public preview requests to quickly remove from cache |
|
| 114 | + $cacheForSeconds = 15 * 60; |
|
| 115 | + } elseif ($downloadForbidden) { |
|
| 116 | + // This is not a public share preview so we only allow a preview if download permissions are granted |
|
| 117 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + try { |
|
| 121 | + $node = $share->getNode(); |
|
| 122 | + if ($node instanceof Folder) { |
|
| 123 | + $file = $node->get($file); |
|
| 124 | + } else { |
|
| 125 | + $file = $node; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $f = $this->previewManager->getPreview($file, $x, $y, !$a); |
|
| 129 | + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 130 | + $response->cacheFor($cacheForSeconds); |
|
| 131 | + return $response; |
|
| 132 | + } catch (NotFoundException $e) { |
|
| 133 | + // If we have no preview enabled, we can redirect to the mime icon if any |
|
| 134 | + if ($mimeFallback) { |
|
| 135 | + if ($url = $this->mimeIconProvider->getMimeIconUrl($file->getMimeType())) { |
|
| 136 | + return new RedirectResponse($url); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 140 | + } catch (\InvalidArgumentException $e) { |
|
| 141 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @NoSameSiteCookieRequired |
|
| 147 | + * |
|
| 148 | + * Get a direct link preview for a shared file |
|
| 149 | + * |
|
| 150 | + * @param string $token Token of the share |
|
| 151 | + * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}> |
|
| 152 | + * |
|
| 153 | + * 200: Preview returned |
|
| 154 | + * 400: Getting preview is not possible |
|
| 155 | + * 403: Getting preview is not allowed |
|
| 156 | + * 404: Share or preview not found |
|
| 157 | + */ |
|
| 158 | + #[PublicPage] |
|
| 159 | + #[NoCSRFRequired] |
|
| 160 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 161 | + public function directLink(string $token) { |
|
| 162 | + // No token no image |
|
| 163 | + if ($token === '') { |
|
| 164 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // No share no image |
|
| 168 | + try { |
|
| 169 | + $share = $this->shareManager->getShareByToken($token); |
|
| 170 | + } catch (ShareNotFound $e) { |
|
| 171 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // No permissions no image |
|
| 175 | + if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) { |
|
| 176 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Password protected shares have no direct link! |
|
| 180 | + if ($share->getPassword() !== null) { |
|
| 181 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (!$share->canSeeContent()) { |
|
| 185 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + try { |
|
| 189 | + $node = $share->getNode(); |
|
| 190 | + if ($node instanceof Folder) { |
|
| 191 | + // Direct link only works for single files |
|
| 192 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $f = $this->previewManager->getPreview($node, -1, -1, false); |
|
| 196 | + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
| 197 | + $response->cacheFor(3600 * 24); |
|
| 198 | + return $response; |
|
| 199 | + } catch (NotFoundException $e) { |
|
| 200 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 201 | + } catch (\InvalidArgumentException $e) { |
|
| 202 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -27,265 +27,265 @@ |
||
| 27 | 27 | |
| 28 | 28 | class PublicPreviewControllerTest extends TestCase { |
| 29 | 29 | |
| 30 | - private IPreview&MockObject $previewManager; |
|
| 31 | - private IManager&MockObject $shareManager; |
|
| 32 | - private ITimeFactory&MockObject $timeFactory; |
|
| 33 | - private IRequest&MockObject $request; |
|
| 30 | + private IPreview&MockObject $previewManager; |
|
| 31 | + private IManager&MockObject $shareManager; |
|
| 32 | + private ITimeFactory&MockObject $timeFactory; |
|
| 33 | + private IRequest&MockObject $request; |
|
| 34 | 34 | |
| 35 | - private PublicPreviewController $controller; |
|
| 35 | + private PublicPreviewController $controller; |
|
| 36 | 36 | |
| 37 | - protected function setUp(): void { |
|
| 38 | - parent::setUp(); |
|
| 37 | + protected function setUp(): void { |
|
| 38 | + parent::setUp(); |
|
| 39 | 39 | |
| 40 | - $this->previewManager = $this->createMock(IPreview::class); |
|
| 41 | - $this->shareManager = $this->createMock(IManager::class); |
|
| 42 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 43 | - $this->request = $this->createMock(IRequest::class); |
|
| 40 | + $this->previewManager = $this->createMock(IPreview::class); |
|
| 41 | + $this->shareManager = $this->createMock(IManager::class); |
|
| 42 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 43 | + $this->request = $this->createMock(IRequest::class); |
|
| 44 | 44 | |
| 45 | - $this->timeFactory->method('getTime') |
|
| 46 | - ->willReturn(1337); |
|
| 45 | + $this->timeFactory->method('getTime') |
|
| 46 | + ->willReturn(1337); |
|
| 47 | 47 | |
| 48 | - $this->overwriteService(ITimeFactory::class, $this->timeFactory); |
|
| 48 | + $this->overwriteService(ITimeFactory::class, $this->timeFactory); |
|
| 49 | 49 | |
| 50 | - $this->controller = new PublicPreviewController( |
|
| 51 | - 'files_sharing', |
|
| 52 | - $this->request, |
|
| 53 | - $this->shareManager, |
|
| 54 | - $this->createMock(ISession::class), |
|
| 55 | - $this->previewManager, |
|
| 56 | - $this->createMock(IMimeIconProvider::class), |
|
| 57 | - ); |
|
| 58 | - } |
|
| 50 | + $this->controller = new PublicPreviewController( |
|
| 51 | + 'files_sharing', |
|
| 52 | + $this->request, |
|
| 53 | + $this->shareManager, |
|
| 54 | + $this->createMock(ISession::class), |
|
| 55 | + $this->previewManager, |
|
| 56 | + $this->createMock(IMimeIconProvider::class), |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function testInvalidToken(): void { |
|
| 61 | - $res = $this->controller->getPreview('', 'file', 10, 10, ''); |
|
| 62 | - $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 60 | + public function testInvalidToken(): void { |
|
| 61 | + $res = $this->controller->getPreview('', 'file', 10, 10, ''); |
|
| 62 | + $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 63 | 63 | |
| 64 | - $this->assertEquals($expected, $res); |
|
| 65 | - } |
|
| 64 | + $this->assertEquals($expected, $res); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function testInvalidWidth(): void { |
|
| 68 | - $res = $this->controller->getPreview('token', 'file', 0); |
|
| 69 | - $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 67 | + public function testInvalidWidth(): void { |
|
| 68 | + $res = $this->controller->getPreview('token', 'file', 0); |
|
| 69 | + $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 70 | 70 | |
| 71 | - $this->assertEquals($expected, $res); |
|
| 72 | - } |
|
| 71 | + $this->assertEquals($expected, $res); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function testInvalidHeight(): void { |
|
| 75 | - $res = $this->controller->getPreview('token', 'file', 10, 0); |
|
| 76 | - $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 74 | + public function testInvalidHeight(): void { |
|
| 75 | + $res = $this->controller->getPreview('token', 'file', 10, 0); |
|
| 76 | + $expected = new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
| 77 | 77 | |
| 78 | - $this->assertEquals($expected, $res); |
|
| 79 | - } |
|
| 78 | + $this->assertEquals($expected, $res); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function testInvalidShare(): void { |
|
| 82 | - $this->shareManager->method('getShareByToken') |
|
| 83 | - ->with($this->equalTo('token')) |
|
| 84 | - ->willThrowException(new ShareNotFound()); |
|
| 85 | - |
|
| 86 | - $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 87 | - $expected = new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 81 | + public function testInvalidShare(): void { |
|
| 82 | + $this->shareManager->method('getShareByToken') |
|
| 83 | + ->with($this->equalTo('token')) |
|
| 84 | + ->willThrowException(new ShareNotFound()); |
|
| 85 | + |
|
| 86 | + $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 87 | + $expected = new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 88 | 88 | |
| 89 | - $this->assertEquals($expected, $res); |
|
| 90 | - } |
|
| 89 | + $this->assertEquals($expected, $res); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function testShareNotAccessable(): void { |
|
| 93 | - $share = $this->createMock(IShare::class); |
|
| 94 | - $this->shareManager->method('getShareByToken') |
|
| 95 | - ->with($this->equalTo('token')) |
|
| 96 | - ->willReturn($share); |
|
| 97 | - |
|
| 98 | - $share->method('getPermissions') |
|
| 99 | - ->willReturn(0); |
|
| 100 | - |
|
| 101 | - $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 102 | - $expected = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 103 | - |
|
| 104 | - $this->assertEquals($expected, $res); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function testShareNoDownload() { |
|
| 108 | - $share = $this->createMock(IShare::class); |
|
| 109 | - $this->shareManager->method('getShareByToken') |
|
| 110 | - ->with($this->equalTo('token')) |
|
| 111 | - ->willReturn($share); |
|
| 92 | + public function testShareNotAccessable(): void { |
|
| 93 | + $share = $this->createMock(IShare::class); |
|
| 94 | + $this->shareManager->method('getShareByToken') |
|
| 95 | + ->with($this->equalTo('token')) |
|
| 96 | + ->willReturn($share); |
|
| 97 | + |
|
| 98 | + $share->method('getPermissions') |
|
| 99 | + ->willReturn(0); |
|
| 100 | + |
|
| 101 | + $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 102 | + $expected = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 103 | + |
|
| 104 | + $this->assertEquals($expected, $res); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function testShareNoDownload() { |
|
| 108 | + $share = $this->createMock(IShare::class); |
|
| 109 | + $this->shareManager->method('getShareByToken') |
|
| 110 | + ->with($this->equalTo('token')) |
|
| 111 | + ->willReturn($share); |
|
| 112 | 112 | |
| 113 | - $share->method('getPermissions') |
|
| 114 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 115 | - |
|
| 116 | - $share->method('canSeeContent') |
|
| 117 | - ->willReturn(false); |
|
| 118 | - |
|
| 119 | - $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 120 | - $expected = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 121 | - |
|
| 122 | - $this->assertEquals($expected, $res); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function testShareNoDownloadButPreviewHeader() { |
|
| 126 | - $share = $this->createMock(IShare::class); |
|
| 127 | - $this->shareManager->method('getShareByToken') |
|
| 128 | - ->with($this->equalTo('token')) |
|
| 129 | - ->willReturn($share); |
|
| 130 | - |
|
| 131 | - $share->method('getPermissions') |
|
| 132 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 133 | - |
|
| 134 | - $share->method('canSeeContent') |
|
| 135 | - ->willReturn(false); |
|
| 136 | - |
|
| 137 | - $this->request->method('getHeader') |
|
| 138 | - ->with('x-nc-preview') |
|
| 139 | - ->willReturn('true'); |
|
| 140 | - |
|
| 141 | - $file = $this->createMock(File::class); |
|
| 142 | - $share->method('getNode') |
|
| 143 | - ->willReturn($file); |
|
| 144 | - |
|
| 145 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 146 | - $preview->method('getName')->willReturn('name'); |
|
| 147 | - $preview->method('getMTime')->willReturn(42); |
|
| 148 | - $this->previewManager->method('getPreview') |
|
| 149 | - ->with($this->equalTo($file), 10, 10, false) |
|
| 150 | - ->willReturn($preview); |
|
| 151 | - |
|
| 152 | - $preview->method('getMimeType') |
|
| 153 | - ->willReturn('myMime'); |
|
| 154 | - |
|
| 155 | - $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 156 | - $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 157 | - $expected->cacheFor(15 * 60); |
|
| 158 | - $this->assertEquals($expected, $res); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function testShareWithAttributes() { |
|
| 162 | - $share = $this->createMock(IShare::class); |
|
| 163 | - $this->shareManager->method('getShareByToken') |
|
| 164 | - ->with($this->equalTo('token')) |
|
| 165 | - ->willReturn($share); |
|
| 166 | - |
|
| 167 | - $share->method('getPermissions') |
|
| 168 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 169 | - |
|
| 170 | - $share->method('canSeeContent') |
|
| 171 | - ->willReturn(true); |
|
| 172 | - |
|
| 173 | - $this->request->method('getHeader') |
|
| 174 | - ->with('x-nc-preview') |
|
| 175 | - ->willReturn('true'); |
|
| 176 | - |
|
| 177 | - $file = $this->createMock(File::class); |
|
| 178 | - $share->method('getNode') |
|
| 179 | - ->willReturn($file); |
|
| 180 | - |
|
| 181 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 182 | - $preview->method('getName')->willReturn('name'); |
|
| 183 | - $preview->method('getMTime')->willReturn(42); |
|
| 184 | - $this->previewManager->method('getPreview') |
|
| 185 | - ->with($this->equalTo($file), 10, 10, false) |
|
| 186 | - ->willReturn($preview); |
|
| 187 | - |
|
| 188 | - $preview->method('getMimeType') |
|
| 189 | - ->willReturn('myMime'); |
|
| 190 | - |
|
| 191 | - $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 192 | - $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 193 | - $expected->cacheFor(3600 * 24); |
|
| 194 | - $this->assertEquals($expected, $res); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public function testPreviewFile() { |
|
| 198 | - $share = $this->createMock(IShare::class); |
|
| 199 | - $this->shareManager->method('getShareByToken') |
|
| 200 | - ->with($this->equalTo('token')) |
|
| 201 | - ->willReturn($share); |
|
| 202 | - |
|
| 203 | - $share->method('getPermissions') |
|
| 204 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 205 | - |
|
| 206 | - $file = $this->createMock(File::class); |
|
| 207 | - $share->method('getNode') |
|
| 208 | - ->willReturn($file); |
|
| 209 | - |
|
| 210 | - $share->method('canSeeContent') |
|
| 211 | - ->willReturn(true); |
|
| 212 | - |
|
| 213 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 214 | - $preview->method('getName')->willReturn('name'); |
|
| 215 | - $preview->method('getMTime')->willReturn(42); |
|
| 216 | - $this->previewManager->method('getPreview') |
|
| 217 | - ->with($this->equalTo($file), 10, 10, false) |
|
| 218 | - ->willReturn($preview); |
|
| 219 | - |
|
| 220 | - $preview->method('getMimeType') |
|
| 221 | - ->willReturn('myMime'); |
|
| 222 | - |
|
| 223 | - $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 224 | - $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 225 | - $expected->cacheFor(3600 * 24); |
|
| 226 | - $this->assertEquals($expected, $res); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public function testPreviewFolderInvalidFile(): void { |
|
| 230 | - $share = $this->createMock(IShare::class); |
|
| 231 | - $this->shareManager->method('getShareByToken') |
|
| 232 | - ->with($this->equalTo('token')) |
|
| 233 | - ->willReturn($share); |
|
| 234 | - |
|
| 235 | - $share->method('getPermissions') |
|
| 236 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 237 | - |
|
| 238 | - $folder = $this->createMock(Folder::class); |
|
| 239 | - $share->method('getNode') |
|
| 240 | - ->willReturn($folder); |
|
| 241 | - |
|
| 242 | - $share->method('canSeeContent') |
|
| 243 | - ->willReturn(true); |
|
| 244 | - |
|
| 245 | - $folder->method('get') |
|
| 246 | - ->with($this->equalTo('file')) |
|
| 247 | - ->willThrowException(new NotFoundException()); |
|
| 248 | - |
|
| 249 | - $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 250 | - $expected = new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 251 | - $this->assertEquals($expected, $res); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - public function testPreviewFolderValidFile(): void { |
|
| 256 | - $share = $this->createMock(IShare::class); |
|
| 257 | - $this->shareManager->method('getShareByToken') |
|
| 258 | - ->with($this->equalTo('token')) |
|
| 259 | - ->willReturn($share); |
|
| 260 | - |
|
| 261 | - $share->method('getPermissions') |
|
| 262 | - ->willReturn(Constants::PERMISSION_READ); |
|
| 263 | - |
|
| 264 | - $folder = $this->createMock(Folder::class); |
|
| 265 | - $share->method('getNode') |
|
| 266 | - ->willReturn($folder); |
|
| 267 | - |
|
| 268 | - $share->method('canSeeContent') |
|
| 269 | - ->willReturn(true); |
|
| 270 | - |
|
| 271 | - $file = $this->createMock(File::class); |
|
| 272 | - $folder->method('get') |
|
| 273 | - ->with($this->equalTo('file')) |
|
| 274 | - ->willReturn($file); |
|
| 275 | - |
|
| 276 | - $preview = $this->createMock(ISimpleFile::class); |
|
| 277 | - $preview->method('getName')->willReturn('name'); |
|
| 278 | - $preview->method('getMTime')->willReturn(42); |
|
| 279 | - $this->previewManager->method('getPreview') |
|
| 280 | - ->with($this->equalTo($file), 10, 10, false) |
|
| 281 | - ->willReturn($preview); |
|
| 282 | - |
|
| 283 | - $preview->method('getMimeType') |
|
| 284 | - ->willReturn('myMime'); |
|
| 285 | - |
|
| 286 | - $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 287 | - $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 288 | - $expected->cacheFor(3600 * 24); |
|
| 289 | - $this->assertEquals($expected, $res); |
|
| 290 | - } |
|
| 113 | + $share->method('getPermissions') |
|
| 114 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 115 | + |
|
| 116 | + $share->method('canSeeContent') |
|
| 117 | + ->willReturn(false); |
|
| 118 | + |
|
| 119 | + $res = $this->controller->getPreview('token', 'file', 10, 10); |
|
| 120 | + $expected = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 121 | + |
|
| 122 | + $this->assertEquals($expected, $res); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function testShareNoDownloadButPreviewHeader() { |
|
| 126 | + $share = $this->createMock(IShare::class); |
|
| 127 | + $this->shareManager->method('getShareByToken') |
|
| 128 | + ->with($this->equalTo('token')) |
|
| 129 | + ->willReturn($share); |
|
| 130 | + |
|
| 131 | + $share->method('getPermissions') |
|
| 132 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 133 | + |
|
| 134 | + $share->method('canSeeContent') |
|
| 135 | + ->willReturn(false); |
|
| 136 | + |
|
| 137 | + $this->request->method('getHeader') |
|
| 138 | + ->with('x-nc-preview') |
|
| 139 | + ->willReturn('true'); |
|
| 140 | + |
|
| 141 | + $file = $this->createMock(File::class); |
|
| 142 | + $share->method('getNode') |
|
| 143 | + ->willReturn($file); |
|
| 144 | + |
|
| 145 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 146 | + $preview->method('getName')->willReturn('name'); |
|
| 147 | + $preview->method('getMTime')->willReturn(42); |
|
| 148 | + $this->previewManager->method('getPreview') |
|
| 149 | + ->with($this->equalTo($file), 10, 10, false) |
|
| 150 | + ->willReturn($preview); |
|
| 151 | + |
|
| 152 | + $preview->method('getMimeType') |
|
| 153 | + ->willReturn('myMime'); |
|
| 154 | + |
|
| 155 | + $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 156 | + $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 157 | + $expected->cacheFor(15 * 60); |
|
| 158 | + $this->assertEquals($expected, $res); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function testShareWithAttributes() { |
|
| 162 | + $share = $this->createMock(IShare::class); |
|
| 163 | + $this->shareManager->method('getShareByToken') |
|
| 164 | + ->with($this->equalTo('token')) |
|
| 165 | + ->willReturn($share); |
|
| 166 | + |
|
| 167 | + $share->method('getPermissions') |
|
| 168 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 169 | + |
|
| 170 | + $share->method('canSeeContent') |
|
| 171 | + ->willReturn(true); |
|
| 172 | + |
|
| 173 | + $this->request->method('getHeader') |
|
| 174 | + ->with('x-nc-preview') |
|
| 175 | + ->willReturn('true'); |
|
| 176 | + |
|
| 177 | + $file = $this->createMock(File::class); |
|
| 178 | + $share->method('getNode') |
|
| 179 | + ->willReturn($file); |
|
| 180 | + |
|
| 181 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 182 | + $preview->method('getName')->willReturn('name'); |
|
| 183 | + $preview->method('getMTime')->willReturn(42); |
|
| 184 | + $this->previewManager->method('getPreview') |
|
| 185 | + ->with($this->equalTo($file), 10, 10, false) |
|
| 186 | + ->willReturn($preview); |
|
| 187 | + |
|
| 188 | + $preview->method('getMimeType') |
|
| 189 | + ->willReturn('myMime'); |
|
| 190 | + |
|
| 191 | + $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 192 | + $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 193 | + $expected->cacheFor(3600 * 24); |
|
| 194 | + $this->assertEquals($expected, $res); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public function testPreviewFile() { |
|
| 198 | + $share = $this->createMock(IShare::class); |
|
| 199 | + $this->shareManager->method('getShareByToken') |
|
| 200 | + ->with($this->equalTo('token')) |
|
| 201 | + ->willReturn($share); |
|
| 202 | + |
|
| 203 | + $share->method('getPermissions') |
|
| 204 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 205 | + |
|
| 206 | + $file = $this->createMock(File::class); |
|
| 207 | + $share->method('getNode') |
|
| 208 | + ->willReturn($file); |
|
| 209 | + |
|
| 210 | + $share->method('canSeeContent') |
|
| 211 | + ->willReturn(true); |
|
| 212 | + |
|
| 213 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 214 | + $preview->method('getName')->willReturn('name'); |
|
| 215 | + $preview->method('getMTime')->willReturn(42); |
|
| 216 | + $this->previewManager->method('getPreview') |
|
| 217 | + ->with($this->equalTo($file), 10, 10, false) |
|
| 218 | + ->willReturn($preview); |
|
| 219 | + |
|
| 220 | + $preview->method('getMimeType') |
|
| 221 | + ->willReturn('myMime'); |
|
| 222 | + |
|
| 223 | + $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 224 | + $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 225 | + $expected->cacheFor(3600 * 24); |
|
| 226 | + $this->assertEquals($expected, $res); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public function testPreviewFolderInvalidFile(): void { |
|
| 230 | + $share = $this->createMock(IShare::class); |
|
| 231 | + $this->shareManager->method('getShareByToken') |
|
| 232 | + ->with($this->equalTo('token')) |
|
| 233 | + ->willReturn($share); |
|
| 234 | + |
|
| 235 | + $share->method('getPermissions') |
|
| 236 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 237 | + |
|
| 238 | + $folder = $this->createMock(Folder::class); |
|
| 239 | + $share->method('getNode') |
|
| 240 | + ->willReturn($folder); |
|
| 241 | + |
|
| 242 | + $share->method('canSeeContent') |
|
| 243 | + ->willReturn(true); |
|
| 244 | + |
|
| 245 | + $folder->method('get') |
|
| 246 | + ->with($this->equalTo('file')) |
|
| 247 | + ->willThrowException(new NotFoundException()); |
|
| 248 | + |
|
| 249 | + $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 250 | + $expected = new DataResponse([], Http::STATUS_NOT_FOUND); |
|
| 251 | + $this->assertEquals($expected, $res); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + public function testPreviewFolderValidFile(): void { |
|
| 256 | + $share = $this->createMock(IShare::class); |
|
| 257 | + $this->shareManager->method('getShareByToken') |
|
| 258 | + ->with($this->equalTo('token')) |
|
| 259 | + ->willReturn($share); |
|
| 260 | + |
|
| 261 | + $share->method('getPermissions') |
|
| 262 | + ->willReturn(Constants::PERMISSION_READ); |
|
| 263 | + |
|
| 264 | + $folder = $this->createMock(Folder::class); |
|
| 265 | + $share->method('getNode') |
|
| 266 | + ->willReturn($folder); |
|
| 267 | + |
|
| 268 | + $share->method('canSeeContent') |
|
| 269 | + ->willReturn(true); |
|
| 270 | + |
|
| 271 | + $file = $this->createMock(File::class); |
|
| 272 | + $folder->method('get') |
|
| 273 | + ->with($this->equalTo('file')) |
|
| 274 | + ->willReturn($file); |
|
| 275 | + |
|
| 276 | + $preview = $this->createMock(ISimpleFile::class); |
|
| 277 | + $preview->method('getName')->willReturn('name'); |
|
| 278 | + $preview->method('getMTime')->willReturn(42); |
|
| 279 | + $this->previewManager->method('getPreview') |
|
| 280 | + ->with($this->equalTo($file), 10, 10, false) |
|
| 281 | + ->willReturn($preview); |
|
| 282 | + |
|
| 283 | + $preview->method('getMimeType') |
|
| 284 | + ->willReturn('myMime'); |
|
| 285 | + |
|
| 286 | + $res = $this->controller->getPreview('token', 'file', 10, 10, true); |
|
| 287 | + $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); |
|
| 288 | + $expected->cacheFor(3600 * 24); |
|
| 289 | + $this->assertEquals($expected, $res); |
|
| 290 | + } |
|
| 291 | 291 | } |