diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 42d0218de8cd3..f61b9dac58afe 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -39,7 +39,6 @@ use OCP\AppFramework\OCSController; use OCP\AppFramework\QueryException; use OCP\Constants; -use OCP\Files\Folder; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -242,6 +241,9 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0); $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' ')); + if (is_bool($shareWithLength)) { + $shareWithLength = -1; + } $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); } else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) { $result['share_with'] = $share->getSharedWith(); @@ -730,15 +732,29 @@ public function getShares( $shares = array_merge($shares, $federatedShares); } - $formatted = []; + $formatted = $miniFormatted = []; + $resharingRight = false; foreach ($shares as $share) { + /** @var IShare $share */ try { - $formatted[] = $this->formatShare($share, $path); - } catch (NotFoundException $e) { + $format = $this->formatShare($share, $path); + $formatted[] = $format; + if ($share->getSharedBy() === $this->currentUser) { + $miniFormatted[] = $format; + } + + if (!$resharingRight && $this->shareProviderResharingRights($this->currentUser, $share, $path)) { + $resharingRight = true; + } + } catch (\Exception $e) { //Ignore share } } + if (!$resharingRight) { + $formatted = $miniFormatted; + } + if ($include_tags) { $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); } @@ -1122,4 +1138,64 @@ private function getRoomShareHelper() { return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController'); } + + + /** + * Returns if we can find resharing rights in an IShare object for a specific user. + * + * @suppress PhanUndeclaredClassMethod + * + * @param string $userId + * @param IShare $share + * @param Node $node + * @return bool + * @throws NotFoundException + * @throws \OCP\Files\InvalidPathException + */ + private function shareProviderResharingRights(string $userId, IShare $share, $node): bool { + + if ($share->getShareOwner() === $userId) { + return true; + } + + // we check that current user have parent resharing rights on the current file + if ($node !== null && ($node->getPermissions() & \OCP\Constants::PERMISSION_SHARE) !== 0) { + return true; + } + + if ((\OCP\Constants::PERMISSION_SHARE & $share->getPermissions()) === 0) { + return false; + } + + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $userId) { + return true; + } + + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $this->groupManager->isInGroup($userId, $share->getSharedWith())) { + return true; + } + + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') && + class_exists('\OCA\Circles\Api\v1\Circles')) { + $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); + $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); + $shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' ')); + if (is_bool($shareWithLength)) { + $shareWithLength = -1; + } + $sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); + try { + $member = \OCA\Circles\Api\v1\Circles::getMember($sharedWith, $userId, 1); + if ($member->getLevel() >= 4) { + return true; + } + return false; + } catch (QueryException $e) { + return false; + } + } + + return false; + } + } diff --git a/core/js/share/sharedialogshareelistview.handlebars b/core/js/share/sharedialogshareelistview.handlebars index 92c07f80290db..18ff219c12a20 100644 --- a/core/js/share/sharedialogshareelistview.handlebars +++ b/core/js/share/sharedialogshareelistview.handlebars @@ -1,8 +1,10 @@ \n"; },"useData":true}); templates['sharedialogshareelistview_popover_menu'] = template({"1":function(container,depth0,helpers,partials,data) { diff --git a/core/js/tests/specs/sharedialogshareelistview.js b/core/js/tests/specs/sharedialogshareelistview.js index 4f84fa0e08fe7..ff353404bccc3 100644 --- a/core/js/tests/specs/sharedialogshareelistview.js +++ b/core/js/tests/specs/sharedialogshareelistview.js @@ -129,6 +129,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); @@ -144,6 +145,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user _.@-\'', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); @@ -159,6 +161,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); @@ -174,6 +177,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user _.@-\'', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); @@ -189,7 +193,8 @@ describe('OC.Share.ShareDialogShareeListView', function () { permissions: 1, share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', - share_with_displayname: 'User One' + share_with_displayname: 'User One', + uid_owner: oc_current_user, }]); shareModel.set('itemType', 'folder'); listView.render(); @@ -206,6 +211,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); @@ -223,6 +229,7 @@ describe('OC.Share.ShareDialogShareeListView', function () { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', share_with_displayname: 'User One', + uid_owner: oc_current_user, itemType: 'folder' }]); shareModel.set('itemType', 'folder'); diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 589b64fc58a6a..a2388012fe7ab 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -623,12 +623,14 @@ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offs if ($reshares === false) { $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); } else { - $qb->andWhere( - $qb->expr()->orX( - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) - ) - ); + if ($node === null) { + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) + ) + ); + } } if ($node !== null) {