$share->getFullId(), 'share_type' => $share->getShareType(), 'uid_owner' => $share->getSharedBy(), 'displayname_owner' => $this->userManager->get($share->getSharedBy())->getDisplayName(), 'permissions' => 0, 'stime' => $share->getShareTime()->getTimestamp(), 'parent' => null, 'expiration' => null, 'token' => null, 'uid_file_owner' => $share->getShareOwner(), 'displayname_file_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(), 'path' => $share->getTarget(), ]; $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); $node = $userFolder->getFirstNodeById($share->getNodeId()); if (!$node) { // fallback to guessing the path $node = $userFolder->get($share->getTarget()); if ($node === null || $share->getTarget() === '') { throw new NotFoundException(); } } $result['path'] = $userFolder->getRelativePath($node->getPath()); if ($node instanceof Folder) { $result['item_type'] = 'folder'; } else { $result['item_type'] = 'file'; } $result['mimetype'] = $node->getMimetype(); $result['storage_id'] = $node->getStorage()->getId(); $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); $result['item_source'] = $node->getId(); $result['file_source'] = $node->getId(); $result['file_parent'] = $node->getParent()->getId(); $result['file_target'] = $share->getTarget(); $result['item_size'] = $node->getSize(); $result['item_mtime'] = $node->getMTime(); $expiration = $share->getExpirationDate(); if ($expiration !== null) { $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); } if ($share->getShareType() === IShare::TYPE_GROUP) { $group = $this->groupManager->get($share->getSharedWith()); $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); } elseif ($share->getShareType() === IShare::TYPE_ROOM) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = ''; try { $result = array_merge($result, $this->getRoomShareHelper()->formatShare($share)); } catch (QueryException $e) { } } elseif ($share->getShareType() === IShare::TYPE_DECK) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = ''; try { $result = array_merge($result, $this->getDeckShareHelper()->formatShare($share)); } catch (QueryException $e) { } } elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) { $result['share_with'] = $share->getSharedWith(); $result['share_with_displayname'] = ''; try { $result = array_merge($result, $this->getSciencemeshShareHelper()->formatShare($share)); } catch (QueryException $e) { } } return $result; } /** * Get a list of all deleted shares * * @return DataResponse, array{}> * * 200: Deleted shares returned */ #[NoAdminRequired] public function index(): DataResponse { $groupShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_GROUP, null, -1, 0); $roomShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_ROOM, null, -1, 0); $deckShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_DECK, null, -1, 0); $sciencemeshShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_SCIENCEMESH, null, -1, 0); $shares = array_merge($groupShares, $roomShares, $deckShares, $sciencemeshShares); $shares = array_values(array_map(function (IShare $share) { return $this->formatShare($share); }, $shares)); return new DataResponse($shares); } /** * Undelete a deleted share * * @param string $id ID of the share * @return DataResponse, array{}> * @throws OCSException * @throws OCSNotFoundException Share not found * * 200: Share undeleted successfully */ #[NoAdminRequired] public function undelete(string $id): DataResponse { try { $share = $this->shareManager->getShareById($id, $this->userId); } catch (ShareNotFound $e) { throw new OCSNotFoundException('Share not found'); } if ($share->getPermissions() !== 0) { throw new OCSNotFoundException('No deleted share found'); } try { $this->shareManager->restoreShare($share, $this->userId); } catch (GenericShareException $e) { throw new OCSException('Something went wrong'); } return new DataResponse([]); } /** * Returns the helper of DeletedShareAPIController for room shares. * * If the Talk application is not enabled or the helper is not available * a QueryException is thrown instead. * * @return \OCA\Talk\Share\Helper\DeletedShareAPIController * @throws QueryException */ private function getRoomShareHelper() { if (!$this->appManager->isEnabledForUser('spreed')) { throw new QueryException(); } return $this->serverContainer->get('\OCA\Talk\Share\Helper\DeletedShareAPIController'); } /** * Returns the helper of DeletedShareAPIHelper for deck shares. * * If the Deck application is not enabled or the helper is not available * a QueryException is thrown instead. * * @return \OCA\Deck\Sharing\ShareAPIHelper * @throws QueryException */ private function getDeckShareHelper() { if (!$this->appManager->isEnabledForUser('deck')) { throw new QueryException(); } return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper'); } /** * Returns the helper of DeletedShareAPIHelper for sciencemesh shares. * * If the sciencemesh application is not enabled or the helper is not available * a QueryException is thrown instead. * * @return \OCA\Deck\Sharing\ShareAPIHelper * @throws QueryException */ private function getSciencemeshShareHelper() { if (!$this->appManager->isEnabledForUser('sciencemesh')) { throw new QueryException(); } return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper'); } }