diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-12-10 16:30:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 16:30:08 +0300 |
commit | 3c693db0ca770fccd5521ecdc4da6d77ae966a73 (patch) | |
tree | 387539171b181bc1169c7ab81abf2ab2729e8486 /apps/files_sharing/lib | |
parent | 16be144aab96796f093b557f29652e277482a2c3 (diff) | |
parent | c4ea37b8a102adec16cf13085dba2fd7ef893195 (diff) |
Merge pull request #24605 from nextcloud/enh/share-deck
Add deck share provider support
Diffstat (limited to 'apps/files_sharing/lib')
4 files changed, 105 insertions, 7 deletions
diff --git a/apps/files_sharing/lib/Controller/DeletedShareAPIController.php b/apps/files_sharing/lib/Controller/DeletedShareAPIController.php index 9b367e06544..9a757412316 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); @@ -211,6 +220,23 @@ class DeletedShareAPIController extends OCSController { throw new QueryException(); } - return $this->serverContainer->query('\OCA\Talk\Share\Helper\DeletedShareAPIController'); + return $this->serverContainer->get('\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->get('\OCA\Deck\Sharing\ShareAPIHelper'); } } diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index aaca16b32e6..65de654be92 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(); } @@ -1517,9 +1558,25 @@ class ShareAPIController extends OCSController { throw new QueryException(); } - return $this->serverContainer->query('\OCA\Talk\Share\Helper\ShareAPIController'); + return $this->serverContainer->get('\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->get('\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); } diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 0509ba72f1a..a2b39b40772 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -83,6 +83,7 @@ class ShareesAPIController extends OCSController { 'emails' => [], 'circles' => [], 'rooms' => [], + 'deck' => [], ], 'users' => [], 'groups' => [], @@ -92,6 +93,7 @@ class ShareesAPIController extends OCSController { 'lookup' => [], 'circles' => [], 'rooms' => [], + 'deck' => [], 'lookupEnabled' => false, ]; @@ -183,6 +185,10 @@ class ShareesAPIController extends OCSController { if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { $shareTypes[] = IShare::TYPE_ROOM; } + + if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { + $shareTypes[] = IShare::TYPE_DECK; + } } else { $shareTypes[] = IShare::TYPE_GROUP; $shareTypes[] = IShare::TYPE_EMAIL; @@ -193,6 +199,10 @@ class ShareesAPIController extends OCSController { $shareTypes[] = IShare::TYPE_CIRCLE; } + if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { + $shareTypes[] = IShare::TYPE_DECK; + } + if ($shareType !== null && is_array($shareType)) { $shareTypes = array_intersect($shareTypes, $shareType); } elseif (is_numeric($shareType)) { diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 3e703a4a6bb..3ab3185b95e 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -78,6 +78,8 @@ class MountProvider implements IMountProvider { $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, -1)); $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_CIRCLE, null, -1)); $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_ROOM, null, -1)); + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_DECK, null, -1)); + // filter out excluded shares and group shares that includes self $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |