summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-12-03 16:03:35 +0100
committerJulius Härtl <jus@bitgrid.net>2020-12-09 13:20:24 +0100
commitf3150f29a7256a502df6990dd9f8126d76fe3a80 (patch)
tree8a203382fef58ebc3374ef3733453b51e47a9967
parentbac1651380f8330a5660d44d098f427f1cef8b4b (diff)
downloadnextcloud-server-f3150f29a7256a502df6990dd9f8126d76fe3a80.tar.gz
nextcloud-server-f3150f29a7256a502df6990dd9f8126d76fe3a80.zip
Introduce deck share type to ShareAPIController
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--apps/files/lib/Controller/ApiController.php3
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php2
-rw-r--r--apps/files_sharing/lib/Controller/DeletedShareAPIController.php28
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php68
-rw-r--r--lib/private/Share20/ProviderFactory.php11
5 files changed, 105 insertions, 7 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index ee4d86bc360..7c0f9bba259 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -221,7 +221,8 @@ class ApiController extends Controller {
IShare::TYPE_LINK,
IShare::TYPE_REMOTE,
IShare::TYPE_EMAIL,
- IShare::TYPE_ROOM
+ IShare::TYPE_ROOM,
+ IShare::TYPE_DECK
];
foreach ($requestedShareTypes as $requestedShareType) {
// one of each type is enough to find out about the types
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index fa979c2006a..bd8520b92fc 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -252,7 +252,7 @@ class OwnershipTransferService {
$shares = [];
$progress = new ProgressBar($output);
- foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE] as $shareType) {
+ foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE, IShare::TYPE_DECK] as $shareType) {
$offset = 0;
while (true) {
$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);
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);
}
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index db333ee99a2..9f93df46ac0 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -345,6 +345,17 @@ class ProviderFactory implements IProviderFactory {
$shares[] = $roomShare;
}
+ foreach ($this->registeredShareProviders as $shareProvider) {
+ /** @var IShareProvider $instance */
+ $instance = $this->serverContainer->get($shareProvider);
+ if (!isset($this->shareProviders[$instance->identifier()])) {
+ $this->shareProviders[$instance->identifier()] = $instance;
+ }
+ $shares[] = $this->shareProviders[$instance->identifier()];
+ }
+
+
+
return $shares;
}
}