Fix getting the information of group share as a sharee

When the receiver of a group share modifies it (for example, by moving
it to a different folder) the original share is not modified, but a
"ghost" share that keeps track of the changes made by that specific user
is used instead.

By default, the method "getShareById" in the share provider returns the
share from the point of view of the sharer, but it can be used too to
get the share from the point of view of a sharee by providing the
"recipient" parameter (and if the sharee is not found then the share is
returned from the point of view of the sharer).

The "ShareAPIController" always formats the share from the point of view
of the current user, but when getting the information of a specific
share the "recipient" parameter was not given, so it was always returned
from the point of view of the sharer, even if the current user was a
sharee. Now the "recipient" parameter is set to the current user, and
thus the information of the share is returned from the point of view of
the current user, be it the sharer or a sharee.

Note that this special behaviour of "getShareById" happens only with
group shares; with other types of shares the share is the same for the
sharer and the sharee, and thus the parameter is ignored; it was added
for them too just for consistency.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-06-28 12:34:04 +02:00
parent 61842f66ee
commit 6cb2cb33ac
2 changed files with 7 additions and 7 deletions

View File

@ -908,7 +908,7 @@ class ShareAPIController extends OCSController {
// First check if it is an internal share.
try {
$share = $this->shareManager->getShareById('ocinternal:' . $id);
$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->currentUser);
return $share;
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
@ -917,7 +917,7 @@ class ShareAPIController extends OCSController {
try {
if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) {
$share = $this->shareManager->getShareById('ocCircleShare:' . $id);
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->currentUser);
return $share;
}
} catch (ShareNotFound $e) {
@ -926,7 +926,7 @@ class ShareAPIController extends OCSController {
try {
if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
$share = $this->shareManager->getShareById('ocMailShare:' . $id);
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->currentUser);
return $share;
}
} catch (ShareNotFound $e) {
@ -936,7 +936,7 @@ class ShareAPIController extends OCSController {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
throw new ShareNotFound();
}
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id);
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);
return $share;
}

View File

@ -229,7 +229,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
->with('ocinternal:42')
->with('ocinternal:42', 'currentUser')
->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
$expected = new \OC\OCS\Result(null, 404, 'wrong share ID, share doesn\'t exist.');
@ -457,7 +457,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
->with($share->getFullId())
->with($share->getFullId(), 'currentUser')
->willReturn($share);
$userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
@ -517,7 +517,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager
->expects($this->once())
->method('getShareById')
->with('ocinternal:42')
->with('ocinternal:42', 'currentUser')
->willReturn($share);
$this->ocs->getShare(42);