OCS Share API should not return invalid shares
Since we have lazy shares it can happen that a share is actually invalid. See https://github.com/owncloud/core/issues/20908 This add checks for the get methods to handle the NotFound exception.
This commit is contained in:
parent
7b0f83b616
commit
2aa0b885f6
2 changed files with 31 additions and 7 deletions
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
namespace OCA\Files_Sharing\API;
|
||||
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IRequest;
|
||||
|
@ -83,6 +84,7 @@ class Share20OCS {
|
|||
*
|
||||
* @param \OCP\Share\IShare $share
|
||||
* @return array
|
||||
* @throws NotFoundException In case the node can't be resolved.
|
||||
*/
|
||||
protected function formatShare(\OCP\Share\IShare $share) {
|
||||
$sharedBy = $this->userManager->get($share->getSharedBy());
|
||||
|
@ -177,13 +179,17 @@ class Share20OCS {
|
|||
}
|
||||
|
||||
if ($this->canAccessShare($share)) {
|
||||
try {
|
||||
$share = $this->formatShare($share);
|
||||
return new \OC_OCS_Result([$share]);
|
||||
} else {
|
||||
return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
|
||||
} catch (NotFoundException $e) {
|
||||
//Fall trough
|
||||
}
|
||||
}
|
||||
|
||||
return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a share
|
||||
*
|
||||
|
@ -368,7 +374,11 @@ class Share20OCS {
|
|||
$formatted = [];
|
||||
foreach ($shares as $share) {
|
||||
if ($this->canAccessShare($share)) {
|
||||
try {
|
||||
$formatted[] = $this->formatShare($share);
|
||||
} catch (NotFoundException $e) {
|
||||
// Ignore this share
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,7 +408,11 @@ class Share20OCS {
|
|||
|
||||
$formatted = [];
|
||||
foreach ($shares as $share) {
|
||||
try {
|
||||
$formatted[] = $this->formatShare($share);
|
||||
} catch (NotFoundException $e) {
|
||||
//Ignore this share
|
||||
}
|
||||
}
|
||||
|
||||
return new \OC_OCS_Result($formatted);
|
||||
|
@ -458,7 +472,11 @@ class Share20OCS {
|
|||
|
||||
$formatted = [];
|
||||
foreach ($shares as $share) {
|
||||
try {
|
||||
$formatted[] = $this->formatShare($share);
|
||||
} catch (NotFoundException $e) {
|
||||
//Ignore share
|
||||
}
|
||||
}
|
||||
|
||||
return new \OC_OCS_Result($formatted);
|
||||
|
|
|
@ -28,6 +28,12 @@ use OCP\IURLGenerator;
|
|||
use OCP\IUser;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
||||
/**
|
||||
* Class Share20OCSTest
|
||||
*
|
||||
* @package OCA\Files_Sharing\Tests\API
|
||||
* @group DB
|
||||
*/
|
||||
class Share20OCSTest extends \Test\TestCase {
|
||||
|
||||
/** @var \OC\Share20\Manager | \PHPUnit_Framework_MockObject_MockObject */
|
||||
|
|
Loading…
Reference in a new issue