1
0

AcceptController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Sharing\Controller;
  8. use OCA\Files_Sharing\AppInfo\Application;
  9. use OCP\AppFramework\Controller;
  10. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  11. use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
  12. use OCP\AppFramework\Http\Attribute\OpenAPI;
  13. use OCP\AppFramework\Http\NotFoundResponse;
  14. use OCP\AppFramework\Http\RedirectResponse;
  15. use OCP\AppFramework\Http\Response;
  16. use OCP\IRequest;
  17. use OCP\IURLGenerator;
  18. use OCP\IUserSession;
  19. use OCP\Share\Exceptions\ShareNotFound;
  20. use OCP\Share\IManager as ShareManager;
  21. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  22. class AcceptController extends Controller {
  23. public function __construct(
  24. IRequest $request,
  25. private ShareManager $shareManager,
  26. private IUserSession $userSession,
  27. private IURLGenerator $urlGenerator,
  28. ) {
  29. parent::__construct(Application::APP_ID, $request);
  30. }
  31. #[NoAdminRequired]
  32. #[NoCSRFRequired]
  33. public function accept(string $shareId): Response {
  34. try {
  35. $share = $this->shareManager->getShareById($shareId);
  36. } catch (ShareNotFound $e) {
  37. return new NotFoundResponse();
  38. }
  39. $user = $this->userSession->getUser();
  40. if ($user === null) {
  41. return new NotFoundResponse();
  42. }
  43. try {
  44. $share = $this->shareManager->acceptShare($share, $user->getUID());
  45. } catch (\Exception $e) {
  46. // Just ignore
  47. }
  48. $url = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]);
  49. return new RedirectResponse($url);
  50. }
  51. }