Introduce deck share type to ShareAPIController

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/24605/head
Julius Härtl 4 years ago
parent bac1651380
commit f3150f29a7
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
  1. 3
      apps/files/lib/Controller/ApiController.php
  2. 2
      apps/files/lib/Service/OwnershipTransferService.php
  3. 28
      apps/files_sharing/lib/Controller/DeletedShareAPIController.php
  4. 68
      apps/files_sharing/lib/Controller/ShareAPIController.php
  5. 11
      lib/private/Share20/ProviderFactory.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

@ -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);

@ -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');
}
}

@ -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);
}

@ -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;
}
}

Loading…
Cancel
Save