diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-12-03 18:03:35 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-12-09 15:20:24 +0300 |
commit | f3150f29a7256a502df6990dd9f8126d76fe3a80 (patch) | |
tree | 8a203382fef58ebc3374ef3733453b51e47a9967 /apps/files_sharing/lib | |
parent | bac1651380f8330a5660d44d098f427f1cef8b4b (diff) |
Introduce deck share type to ShareAPIController
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Controller/DeletedShareAPIController.php | 28 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 68 |
2 files changed, 91 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php index 9b367e06544..1981c0c1945 100644 --- a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php +++ b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php @@ -151,6 +151,14 @@ class DeletedShareAPIController extends OCSController { $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) { + } } return $result; @@ -162,8 +170,9 @@ class DeletedShareAPIController extends OCSController { 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); - $shares = array_merge($groupShares, $roomShares); + $shares = array_merge($groupShares, $roomShares, $deckShares); $shares = array_map(function (IShare $share) { return $this->formatShare($share); @@ -213,4 +222,21 @@ class DeletedShareAPIController extends OCSController { return $this->serverContainer->query('\OCA\Talk\Share\Helper\DeletedShareAPIController'); } + + /** + * Returns the helper of ShareAPIHelper 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->query('\OCA\Deck\Sharing\ShareAPIHelper'); + } } diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index aaca16b32e6..399ff18fba8 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -303,6 +303,14 @@ class ShareAPIController extends OCSController { $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) { + } } @@ -603,6 +611,12 @@ class ShareAPIController extends OCSController { } catch (QueryException $e) { throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()])); } + } elseif ($shareType === IShare::TYPE_DECK) { + try { + $this->getDeckShareHelper()->createShare($share, $shareWith, $permissions, $expireDate); + } catch (QueryException $e) { + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()])); + } } else { throw new OCSBadRequestException($this->l->t('Unknown share type')); } @@ -635,8 +649,9 @@ class ShareAPIController extends OCSController { $groupShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_GROUP, $node, -1, 0); $circleShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_CIRCLE, $node, -1, 0); $roomShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_ROOM, $node, -1, 0); + $deckShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_DECK, $node, -1, 0); - $shares = array_merge($userShares, $groupShares, $circleShares, $roomShares); + $shares = array_merge($userShares, $groupShares, $circleShares, $roomShares, $deckShares); $filteredShares = array_filter($shares, function (IShare $share) { return $share->getShareOwner() !== $this->currentUser; @@ -1296,6 +1311,14 @@ class ShareAPIController extends OCSController { } } + if ($share->getShareType() === IShare::TYPE_DECK) { + try { + return $this->getDeckShareHelper()->canAccessShare($share, $this->currentUser); + } catch (QueryException $e) { + return false; + } + } + return false; } @@ -1371,7 +1394,8 @@ class ShareAPIController extends OCSController { */ protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool { if ($share->getShareType() !== IShare::TYPE_GROUP && - $share->getShareType() !== IShare::TYPE_ROOM + $share->getShareType() !== IShare::TYPE_ROOM && + $share->getShareType() !== IShare::TYPE_DECK ) { return false; } @@ -1400,6 +1424,14 @@ class ShareAPIController extends OCSController { } } + if ($share->getShareType() === IShare::TYPE_DECK) { + try { + return $this->getDeckShareHelper()->canAccessShare($share, $this->currentUser); + } catch (QueryException $e) { + return false; + } + } + return false; } @@ -1474,6 +1506,15 @@ class ShareAPIController extends OCSController { // Do nothing, just try the other share type } + try { + if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { + $share = $this->shareManager->getShareById('deck:' . $id, $this->currentUser); + return $share; + } + } catch (ShareNotFound $e) { + // Do nothing, just try the other share type + } + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { throw new ShareNotFound(); } @@ -1520,6 +1561,22 @@ class ShareAPIController extends OCSController { return $this->serverContainer->query('\OCA\Talk\Share\Helper\ShareAPIController'); } + /** + * Returns the helper of ShareAPIHelper 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->query('\OCA\Deck\Sharing\ShareAPIHelper'); + } /** * @param string $viewer @@ -1536,7 +1593,8 @@ class ShareAPIController extends OCSController { IShare::TYPE_EMAIL, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE, - IShare::TYPE_ROOM + IShare::TYPE_ROOM, + IShare::TYPE_DECK ]; // Should we assume that the (currentUser) viewer is the owner of the node !? @@ -1689,6 +1747,8 @@ class ShareAPIController extends OCSController { // TALK SHARES $roomShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_ROOM, $path, $reshares, -1, 0); + $deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0); + // FEDERATION if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); @@ -1701,7 +1761,7 @@ class ShareAPIController extends OCSController { $federatedGroupShares = []; } - return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $federatedShares, $federatedGroupShares); + return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares, $federatedGroupShares); } |