, array{}> * * 200: Pending remote shares returned */ #[NoAdminRequired] public function getOpenShares(): DataResponse { $shares = $this->externalManager->getOpenShares(); $shares = array_map($this->extendShareInfo(...), $shares); return new DataResponse($shares); } /** * Accept a remote share. * * @param string $id ID of the share * @return DataResponse, array{}> * @throws OCSNotFoundException Share not found * * 200: Share accepted successfully */ #[NoAdminRequired] public function acceptShare(string $id): DataResponse { $externalShare = $this->externalManager->getShare($id); if ($externalShare === false) { $this->logger->error('Could not accept federated share with id: ' . $id . ' Share not found.', ['app' => 'files_sharing']); throw new OCSNotFoundException('Wrong share ID, share does not exist.'); } if (!$this->externalManager->acceptShare($externalShare)) { $this->logger->error('Could not accept federated share with id: ' . $id, ['app' => 'files_sharing']); throw new OCSNotFoundException('Wrong share ID, share does not exist.'); } return new DataResponse(); } /** * Decline a remote share. * * @param string $id ID of the share * @return DataResponse, array{}> * @throws OCSNotFoundException Share not found * * 200: Share declined successfully */ #[NoAdminRequired] public function declineShare(string $id): DataResponse { $externalShare = $this->externalManager->getShare($id); if ($externalShare === false) { $this->logger->error('Could not decline federated share with id: ' . $id . ' Share not found.', ['app' => 'files_sharing']); throw new OCSNotFoundException('Wrong share ID, share does not exist.'); } if (!$this->externalManager->declineShare($externalShare)) { $this->logger->error('Could not decline federated share with id: ' . $id, ['app' => 'files_sharing']); throw new OCSNotFoundException('Wrong share ID, share does not exist.'); } return new DataResponse(); } /** * @param ExternalShare $share Share with info from the share_external table * @return Files_SharingRemoteShare Enriched share info with data from the filecache */ private function extendShareInfo(ExternalShare $share): array { $shareData = $share->jsonSerialize(); $shareData['parent'] = $shareData['parent'] !== '-1' ? $shareData['parent'] : null; $userFolder = $this->rootFolder->getUserFolder($this->userId); try { $mountPointNode = $userFolder->get($share->getMountpoint()); } catch (\Exception) { return $shareData; } $shareData['mimetype'] = $mountPointNode->getMimetype(); $shareData['mtime'] = $mountPointNode->getMTime(); $shareData['permissions'] = $mountPointNode->getPermissions(); $shareData['type'] = $mountPointNode->getType(); $shareData['file_id'] = $mountPointNode->getId(); return $shareData; } /** * Get a list of accepted remote shares * * @return DataResponse, array{}> * * 200: Accepted remote shares returned */ #[NoAdminRequired] public function getShares(): DataResponse { $shares = $this->externalManager->getAcceptedShares(); $shares = array_map(fn (ExternalShare $share) => $this->extendShareInfo($share), $shares); return new DataResponse($shares); } /** * Get info of a remote share * * @param string $id ID of the share * @return DataResponse * @throws OCSNotFoundException Share not found * * 200: Share returned */ #[NoAdminRequired] public function getShare(string $id): DataResponse { $shareInfo = $this->externalManager->getShare($id); if ($shareInfo === false) { throw new OCSNotFoundException('share does not exist'); } else { $shareInfo = $this->extendShareInfo($shareInfo); return new DataResponse($shareInfo); } } /** * Unshare a remote share * * @param string $id ID of the share * @return DataResponse, array{}> * @throws OCSNotFoundException Share not found * @throws OCSForbiddenException Unsharing is not possible * * 200: Share unshared successfully */ #[NoAdminRequired] public function unshare(string $id): DataResponse { $shareInfo = $this->externalManager->getShare($id); if ($shareInfo === false) { throw new OCSNotFoundException('Share does not exist'); } $mountPoint = '/' . $this->userId . '/files' . $shareInfo->getMountpoint(); if ($this->externalManager->removeShare($mountPoint) === true) { return new DataResponse(); } else { throw new OCSForbiddenException('Could not unshare'); } } }