From 185b9c6edd56157f45c72800fdea104bd360925a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 27 Jan 2016 12:13:53 +0100 Subject: [PATCH] [Share 2.0] Move IShare to OCP --- apps/files_sharing/api/share20ocs.php | 12 ++- .../lib/controllers/sharecontroller.php | 5 +- .../tests/api/share20ocstest.php | 38 +++++----- .../tests/controller/sharecontroller.php | 16 ++-- lib/private/share20/defaultshareprovider.php | 25 ++++--- lib/private/share20/manager.php | 65 ++++++++-------- lib/private/share20/providerfactory.php | 1 + lib/private/share20/share.php | 2 +- .../share}/iproviderfactory.php | 6 +- .../share20 => public/share}/ishare.php | 74 ++++++++++++++----- .../share}/ishareprovider.php | 48 +++++++----- .../lib/share20/defaultshareprovidertest.php | 6 +- tests/lib/share20/managertest.php | 44 +++++------ 13 files changed, 192 insertions(+), 150 deletions(-) rename lib/{private/share20 => public/share}/iproviderfactory.php (94%) rename lib/{private/share20 => public/share}/ishare.php (74%) rename lib/{private/share20 => public/share}/ishareprovider.php (77%) diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 3048eb7cd1..8e216c8c3c 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -20,8 +20,6 @@ */ namespace OCA\Files_Sharing\API; -use OC\Share20\IShare; - use OCP\IGroupManager; use OCP\IUserManager; use OCP\IRequest; @@ -73,10 +71,10 @@ class Share20OCS { /** * Convert an IShare to an array for OCS output * - * @param IShare $share + * @param \OCP\Share\IShare $share * @return array */ - protected function formatShare($share) { + protected function formatShare(\OCP\Share\IShare $share) { $result = [ 'id' => $share->getId(), 'share_type' => $share->getShareType(), @@ -353,7 +351,7 @@ class Share20OCS { } $nodes = $folder->getDirectoryListing(); - /** @var IShare[] $shares */ + /** @var \OCP\Share\IShare[] $shares */ $shares = []; foreach ($nodes as $node) { $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); @@ -494,10 +492,10 @@ class Share20OCS { } /** - * @param IShare $share + * @param \OCP\Share\IShare $share * @return bool */ - protected function canAccessShare(IShare $share) { + protected function canAccessShare(\OCP\Share\IShare $share) { // A file with permissions 0 can't be accessed by us. So Don't show it if ($share->getPermissions() === 0) { return false; diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index 6f9a8d742c..407207c0ef 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -51,7 +51,6 @@ use OCA\Files_Sharing\Helper; use OCP\Util; use OCA\Files_Sharing\Activity; use \OCP\Files\NotFoundException; -use \OC\Share20\IShare; use OCP\Files\IRootFolder; /** @@ -168,11 +167,11 @@ class ShareController extends Controller { * This is a modified version of Helper::authenticate * TODO: Try to merge back eventually with Helper::authenticate * - * @param IShare $share + * @param \OCP\Share\IShare $share * @param string|null $password * @return bool */ - private function linkShareAuth(IShare $share, $password = null) { + private function linkShareAuth(\OCP\Share\IShare $share, $password = null) { if ($password !== null) { if ($this->shareManager->checkPassword($share, $password)) { $this->session->set('public_link_authenticated', (string)$share->getId()); diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php index f38af98815..ebacf6c20f 100644 --- a/apps/files_sharing/tests/api/share20ocstest.php +++ b/apps/files_sharing/tests/api/share20ocstest.php @@ -20,7 +20,6 @@ */ namespace OCA\Files_Sharing\Tests\API; -use OC\Share20\IShare; use OCA\Files_Sharing\API\Share20OCS; use OCP\IGroupManager; use OCP\IUserManager; @@ -90,7 +89,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testDeleteShareCouldNotDelete() { - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareOwner')->willReturn($this->currentUser); $this->shareManager ->expects($this->once()) @@ -109,7 +108,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testDeleteShare() { - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getSharedBy')->willReturn($this->currentUser); $this->shareManager ->expects($this->once()) @@ -143,7 +142,7 @@ class Share20OCSTest extends \Test\TestCase { public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, $shareTime, $expiration, $parent, $target, $mail_send, $token=null, $password=null) { - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getId')->willReturn($id); $share->method('getShareType')->willReturn($shareType); $share->method('getSharedWith')->willReturn($sharedWith); @@ -345,7 +344,7 @@ class Share20OCSTest extends \Test\TestCase { /** * @dataProvider dataGetShare */ - public function testGetShare(\OC\Share20\IShare $share, array $result) { + public function testGetShare(\OCP\Share\IShare $share, array $result) { $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ $this->shareManager, @@ -384,39 +383,39 @@ class Share20OCSTest extends \Test\TestCase { } public function testCanAccessShare() { - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareOwner')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getSharedBy')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $share->method('getSharedWith')->willReturn($this->currentUser); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $share->method('getSharedWith')->willReturn($this->getMock('OCP\IUser')); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $group = $this->getMock('OCP\IGroup'); $group->method('inGroup')->with($this->currentUser)->willReturn(true); $share->method('getSharedWith')->willReturn($group); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $group = $this->getMock('OCP\IGroup'); $group->method('inGroup')->with($this->currentUser)->willReturn(false); $share->method('getSharedWith')->willReturn($group); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); } @@ -457,7 +456,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareInvalidPermissions() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -488,7 +487,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoShareWith() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -520,7 +519,7 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUserNoValidShareWith() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); $this->request @@ -553,8 +552,9 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareUser() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); + $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ @@ -611,8 +611,9 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroupNoValidShareWith() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); + $this->shareManager->method('createShare')->will($this->returnArgument(0)); $this->request ->method('getParam') @@ -644,8 +645,9 @@ class Share20OCSTest extends \Test\TestCase { } public function testCreateShareGroup() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager->method('newShare')->willReturn($share); + $this->shareManager->method('createShare')->will($this->returnArgument(0)); $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') ->setConstructorArgs([ diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php index 43db17f5ab..7d13753d32 100644 --- a/apps/files_sharing/tests/controller/sharecontroller.php +++ b/apps/files_sharing/tests/controller/sharecontroller.php @@ -116,7 +116,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testShowAuthenticateNotAuthenticated() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->shareManager ->expects($this->once()) @@ -130,7 +130,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testShowAuthenticateAuthenticatedForDifferentShare() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn(1); $this->shareManager @@ -148,7 +148,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testShowAuthenticateCorrectShare() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn(1); $this->shareManager @@ -183,7 +183,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testAuthenticateValidPassword() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn(42); $this->shareManager @@ -214,7 +214,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testAuthenticateInvalidPassword() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn(42); $this->shareManager @@ -252,7 +252,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testShowShareNotAuthenticated() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getPassword')->willReturn('password'); $this->shareManager @@ -283,7 +283,7 @@ class ShareControllerTest extends \Test\TestCase { $file->method('getMimetype')->willReturn('text/plain'); $file->method('getSize')->willReturn(33); - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn('42'); $share->method('getPassword')->willReturn('password'); $share->method('getShareOwner')->willReturn($owner); @@ -340,7 +340,7 @@ class ShareControllerTest extends \Test\TestCase { } public function testDownloadShare() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getPassword')->willReturn('password'); $this->shareManager diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 36ba56d63a..74dd408ad2 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -20,6 +20,7 @@ */ namespace OC\Share20; +use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; use OC\Share20\Exception\ShareNotFound; @@ -87,12 +88,12 @@ class DefaultShareProvider implements IShareProvider { /** * Share a path * - * @param IShare $share - * @return IShare The share object + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object * @throws ShareNotFound * @throws \Exception */ - public function create(IShare $share) { + public function create(\OCP\Share\IShare $share) { $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share'); @@ -179,10 +180,10 @@ class DefaultShareProvider implements IShareProvider { /** * Update a share * - * @param IShare $share - * @return IShare The share object + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object */ - public function update(IShare $share) { + public function update(\OCP\Share\IShare $share) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { /* * We allow updating the recipient on user shares. @@ -251,10 +252,10 @@ class DefaultShareProvider implements IShareProvider { /** * Get all children of this share * - * @param IShare $parent + * @param \OCP\Share\IShare $parent * @return IShare[] */ - public function getChildren(IShare $parent) { + public function getChildren(\OCP\Share\IShare $parent) { $children = []; $qb = $this->dbConn->getQueryBuilder(); @@ -286,10 +287,10 @@ class DefaultShareProvider implements IShareProvider { /** * Delete a share * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws BackendError */ - public function delete(IShare $share) { + public function delete(\OCP\Share\IShare $share) { // Fetch share to make sure it exists $share = $this->getShareById($share->getId()); @@ -308,12 +309,12 @@ class DefaultShareProvider implements IShareProvider { * Unshare a share from the recipient. If this is a group share * this means we need a special entry in the share db. * - * @param IShare $share + * @param \OCP\Share\IShare $share * @param IUser $recipient * @throws BackendError * @throws ProviderException */ - public function deleteFromSelf(IShare $share, IUser $recipient) { + public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { /** @var IGroup $group */ diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 673cea9b94..867849102c 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -20,9 +20,8 @@ */ namespace OC\Share20; - +use OCP\Share\IProviderFactory; use OC\Share20\Exception\BackendError; -use OC\Share20\Exception\ProviderException; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -45,9 +44,6 @@ class Manager { /** @var IProviderFactory */ private $factory; - /** @var array */ - private $type2provider; - /** @var ILogger */ private $logger; @@ -91,9 +87,6 @@ class Manager { IL10N $l, IProviderFactory $factory ) { - $this->providers = []; - $this->type2provider = []; - $this->logger = $logger; $this->config = $config; $this->secureRandom = $secureRandom; @@ -147,10 +140,10 @@ class Manager { /** * Check for generic requirements before creating a share * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws \Exception */ - protected function generalCreateChecks(IShare $share) { + protected function generalCreateChecks(\OCP\Share\IShare $share) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { // We expect a valid user as sharedWith for user shares if (!($share->getSharedWith() instanceof \OCP\IUser)) { @@ -266,10 +259,10 @@ class Manager { /** * Check for pre share requirements for user shares * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws \Exception */ - protected function userCreateChecks(IShare $share) { + protected function userCreateChecks(\OCP\Share\IShare $share) { // Check if we can share with group members only if ($this->shareWithGroupMembersOnly()) { // Verify we can share with this user @@ -312,10 +305,10 @@ class Manager { /** * Check for pre share requirements for group shares * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws \Exception */ - protected function groupCreateChecks(IShare $share) { + protected function groupCreateChecks(\OCP\Share\IShare $share) { // Verify if the user can share with this group if ($this->shareWithGroupMembersOnly()) { if (!$share->getSharedWith()->inGroup($share->getSharedBy())) { @@ -344,10 +337,10 @@ class Manager { /** * Check for pre share requirements for link shares * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws \Exception */ - protected function linkCreateChecks(IShare $share) { + protected function linkCreateChecks(\OCP\Share\IShare $share) { // Are link shares allowed? if (!$this->shareApiAllowLinks()) { throw new \Exception('Link sharing not allowed'); @@ -388,10 +381,10 @@ class Manager { /** * Check if the user that is sharing can actually share * - * @param IShare $share + * @param \OCP\Share\IShare $share * @return bool */ - protected function canShare(IShare $share) { + protected function canShare(\OCP\Share\IShare $share) { if (!$this->shareApiEnabled()) { return false; } @@ -406,13 +399,13 @@ class Manager { /** * Share a path * - * @param IShare $share + * @param \OCP\Share\IShare $share * @return Share The share object * @throws \Exception * * TODO: handle link share permissions or check them */ - public function createShare(IShare $share) { + public function createShare(\OCP\Share\IShare $share) { if (!$this->canShare($share)) { throw new \Exception('The Share API is disabled'); } @@ -528,10 +521,10 @@ class Manager { /** * Update a share * - * @param IShare $share - * @return IShare The share object + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object */ - public function updateShare(IShare $share) { + public function updateShare(\OCP\Share\IShare $share) { $expirationDateUpdated = false; if (!$this->canShare($share)) { @@ -604,10 +597,10 @@ class Manager { /** * Delete all the children of this share * - * @param IShare $share - * @return IShare[] List of deleted shares + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare[] List of deleted shares */ - protected function deleteChildren(IShare $share) { + protected function deleteChildren(\OCP\Share\IShare $share) { $deletedShares = []; $provider = $this->factory->getProviderForType($share->getShareType()); @@ -626,16 +619,16 @@ class Manager { /** * Delete a share * - * @param IShare $share + * @param \OCP\Share\IShare $share * @throws ShareNotFound * @throws BackendError * @throws ShareNotFound */ - public function deleteShare(IShare $share) { + public function deleteShare(\OCP\Share\IShare $share) { // Just to make sure we have all the info $share = $this->getShareById($share->getFullId()); - $formatHookParams = function(IShare $share) { + $formatHookParams = function(\OCP\Share\IShare $share) { // Prepare hook $shareType = $share->getShareType(); $sharedWith = ''; @@ -694,10 +687,10 @@ class Manager { * the users in a groups deletes that share. But the provider should * handle this. * - * @param IShare $share + * @param \OCP\Share\IShare $share * @param IUser $recipient */ - public function deleteFromSelf(IShare $share, IUser $recipient) { + public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient) { list($providerId, $id) = $this->splitFullId($share->getId()); $provider = $this->factory->getProvider($providerId); @@ -713,7 +706,7 @@ class Manager { * @param bool $reshares * @param int $limit The maximum number of returned results, -1 for all results * @param int $offset - * @return IShare[] + * @return \OCP\Share\IShare[] */ public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { if ($path !== null && @@ -734,7 +727,7 @@ class Manager { * @param int $shareType * @param int $limit The maximum number of shares returned, -1 for all * @param int $offset - * @return IShare[] + * @return \OCP\Share\IShare[] */ public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) { $provider = $this->factory->getProviderForType($shareType); @@ -797,11 +790,11 @@ class Manager { /** * Verify the password of a public share * - * @param IShare $share + * @param \OCP\Share\IShare $share * @param string $password * @return bool */ - public function checkPassword(IShare $share, $password) { + public function checkPassword(\OCP\Share\IShare $share, $password) { if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) { //TODO maybe exception? return false; @@ -852,7 +845,7 @@ class Manager { /** * Create a new share - * @return IShare; + * @return \OCP\Share\IShare; */ public function newShare() { return new \OC\Share20\Share(); diff --git a/lib/private/share20/providerfactory.php b/lib/private/share20/providerfactory.php index 2e5282c1eb..6414735559 100644 --- a/lib/private/share20/providerfactory.php +++ b/lib/private/share20/providerfactory.php @@ -20,6 +20,7 @@ */ namespace OC\Share20; +use OCP\Share\IProviderFactory; use OC\Share20\Exception\ProviderException; use OCP\IServerContainer; diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php index 3e42d50847..6b38d2db49 100644 --- a/lib/private/share20/share.php +++ b/lib/private/share20/share.php @@ -24,7 +24,7 @@ use OCP\Files\Node; use OCP\IUser; use OCP\IGroup; -class Share implements IShare { +class Share implements \OCP\Share\IShare { /** @var string */ private $id; diff --git a/lib/private/share20/iproviderfactory.php b/lib/public/share/iproviderfactory.php similarity index 94% rename from lib/private/share20/iproviderfactory.php rename to lib/public/share/iproviderfactory.php index b38666978d..3a8baccf33 100644 --- a/lib/private/share20/iproviderfactory.php +++ b/lib/public/share/iproviderfactory.php @@ -18,7 +18,8 @@ * along with this program. If not, see * */ -namespace OC\Share20; + +namespace OCP\Share; use OC\Share20\Exception\ProviderException; use OCP\IServerContainer; @@ -34,6 +35,7 @@ interface IProviderFactory { /** * IProviderFactory constructor. * @param IServerContainer $serverContainer + * @since 9.0.0 */ public function __construct(IServerContainer $serverContainer); @@ -41,6 +43,7 @@ interface IProviderFactory { * @param string $id * @return IShareProvider * @throws ProviderException + * @since 9.0.0 */ public function getProvider($id); @@ -48,6 +51,7 @@ interface IProviderFactory { * @param int $shareType * @return IShareProvider * @throws ProviderException + * @since 9.0.0 */ public function getProviderForType($shareType); } diff --git a/lib/private/share20/ishare.php b/lib/public/share/ishare.php similarity index 74% rename from lib/private/share20/ishare.php rename to lib/public/share/ishare.php index d3ffd417fe..1038ccf438 100644 --- a/lib/private/share20/ishare.php +++ b/lib/public/share/ishare.php @@ -18,7 +18,8 @@ * along with this program. If not, see * */ -namespace OC\Share20; + +namespace OCP\Share; use OCP\Files\File; use OCP\Files\Folder; @@ -26,12 +27,19 @@ use OCP\Files\Node; use OCP\IUser; use OCP\IGroup; +/** + * Interface IShare + * + * @package OCP\Share + * @since 9.0.0 + */ interface IShare { /** * Get the id of the share * * @return string + * @since 9.0.0 */ public function getId(); @@ -39,7 +47,8 @@ interface IShare { * Set the id of the share * * @param string $id - * @return IShare The modified share object + * @return \OCP\Share\IShare The modified share object + * @since 9.0.0 */ public function setId($id); @@ -47,6 +56,7 @@ interface IShare { * Get the full share id * * @return string + * @since 9.0.0 */ public function getFullId(); @@ -54,7 +64,8 @@ interface IShare { * Set the provider id * * @param string $id - * @return IShare The modified share object + * @return \OCP\Share\IShare The modified share object\ + * @since 9.0.0 */ public function setProviderId($id); @@ -62,14 +73,16 @@ interface IShare { * Set the path of this share * * @param Node $path - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setPath(Node $path); /** * Get the path of this share for the current user - * + * * @return File|Folder + * @since 9.0.0 */ public function getPath(); @@ -77,14 +90,16 @@ interface IShare { * Set the shareType * * @param int $shareType - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setShareType($shareType); /** - * Get the shareType + * Get the shareType * * @return int + * @since 9.0.0 */ public function getShareType(); @@ -92,7 +107,8 @@ interface IShare { * Set the receiver of this share * * @param IUser|IGroup|string - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setSharedWith($sharedWith); @@ -100,6 +116,7 @@ interface IShare { * Get the receiver of this share * * @return IUser|IGroup|string + * @since 9.0.0 */ public function getSharedWith(); @@ -107,7 +124,8 @@ interface IShare { * Set the permissions * * @param int $permissions - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setPermissions($permissions); @@ -115,6 +133,7 @@ interface IShare { * Get the share permissions * * @return int + * @since 9.0.0 */ public function getPermissions(); @@ -122,7 +141,8 @@ interface IShare { * Set the expiration date * * @param \DateTime $expireDate - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setExpirationDate($expireDate); @@ -130,6 +150,7 @@ interface IShare { * Get the share expiration date * * @return \DateTime + * @since 9.0.0 */ public function getExpirationDate(); @@ -137,7 +158,8 @@ interface IShare { * Set the sharer of the path * * @param IUser|string $sharedBy - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setSharedBy($sharedBy); @@ -145,6 +167,7 @@ interface IShare { * Get share sharer * * @return IUser|string + * @since 9.0.0 */ public function getSharedBy(); @@ -152,15 +175,16 @@ interface IShare { * Set the original share owner (who owns the path) * * @param IUser|string - * - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setShareOwner($shareOwner); /** * Get the original share owner (who owns the path) - * + * * @return IUser|string + * @since 9.0.0 */ public function getShareOwner(); @@ -168,8 +192,8 @@ interface IShare { * Set the password * * @param string $password - * - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setPassword($password); @@ -177,6 +201,7 @@ interface IShare { * Is a password set for this share * * @return string + * @since 9.0.0 */ public function getPassword(); @@ -184,7 +209,8 @@ interface IShare { * Set the token * * @param string $token - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setToken($token); @@ -192,6 +218,7 @@ interface IShare { * Get the token * * @return string + * @since 9.0.0 */ public function getToken(); @@ -199,6 +226,7 @@ interface IShare { * Get the parent it * * @return int + * @since 9.0.0 */ public function getParent(); @@ -206,7 +234,8 @@ interface IShare { * Set the target of this share * * @param string $target - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setTarget($target); @@ -214,6 +243,7 @@ interface IShare { * Get the target of this share * * @return string + * @since 9.0.0 */ public function getTarget(); @@ -221,7 +251,8 @@ interface IShare { * Set the time this share was created * * @param int $shareTime - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setShareTime($shareTime); @@ -229,6 +260,7 @@ interface IShare { * Get the timestamp this share was created * * @return int + * @since 9.0.0 */ public function getShareTime(); @@ -236,7 +268,8 @@ interface IShare { * Set mailSend * * @param bool $mailSend - * @return IShare The modified object + * @return \OCP\Share\IShare The modified object + * @since 9.0.0 */ public function setMailSend($mailSend); @@ -244,6 +277,7 @@ interface IShare { * Get mailSend * * @return bool + * @since 9.0.0 */ public function getMailSend(); } diff --git a/lib/private/share20/ishareprovider.php b/lib/public/share/ishareprovider.php similarity index 77% rename from lib/private/share20/ishareprovider.php rename to lib/public/share/ishareprovider.php index 17ee4abb9a..fa1b63d2d1 100644 --- a/lib/private/share20/ishareprovider.php +++ b/lib/public/share/ishareprovider.php @@ -18,53 +18,64 @@ * along with this program. If not, see * */ -namespace OC\Share20; + +namespace OCP\Share; use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\BackendError; use OCP\IUser; +/** + * Interface IShareProvider + * + * @package OCP\Share + * @since 9.0.0 + */ interface IShareProvider { /** * Return the identifier of this provider. * * @return string Containing only [a-zA-Z0-9] + * @since 9.0.0 */ public function identifier(); /** * Share a path * - * @param IShare $share - * @return IShare The share object + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object + * @since 9.0.0 */ - public function create(IShare $share); + public function create(\OCP\Share\IShare $share); /** * Update a share * - * @param IShare $share - * @return IShare The share object + * @param \OCP\Share\IShare $share + * @return \OCP\Share\IShare The share object + * @since 9.0.0 */ - public function update(IShare $share); + public function update(\OCP\Share\IShare $share); /** * Delete a share * - * @param IShare $share - * @throws BackendError + * @param \OCP\Share\IShare $share + * @since 9.0.0 */ - public function delete(IShare $share); + public function delete(\OCP\Share\IShare $share); /** * Unshare a file from self as recipient. * This may require special handling. * - * @param IShare $share + * @param \OCP\Share\IShare $share * @param IUser $recipient + * @since 9.0.0 */ - public function deleteFromSelf(IShare $share, IUser $recipient); + public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient); /** * Get all shares by the given user @@ -76,6 +87,7 @@ interface IShareProvider { * @param int $limit The maximum number of shares to be returned, -1 for all shares * @param int $offset * @return Share[] + * @since 9.0.0 */ public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset); @@ -85,22 +97,16 @@ interface IShareProvider { * @param int $id * @return IShare * @throws ShareNotFound + * @since 9.0.0 */ public function getShareById($id); - /** - * Get children - * - * @param IShare $parent - * @return IShare[] - */ - public function getChildren(IShare $parent); - /** * Get shares for a given path * * @param \OCP\Files\Node $path * @return IShare[] + * @since 9.0.0 */ public function getSharesByPath(\OCP\Files\Node $path); @@ -112,6 +118,7 @@ interface IShareProvider { * @param int $limit The max number of entries returned, -1 for all * @param int $offset * @param Share + * @since 9.0.0 */ public function getSharedWith(IUser $user, $shareType, $limit, $offset); @@ -121,6 +128,7 @@ interface IShareProvider { * @param string $token * @return IShare * @throws ShareNotFound + * @since 9.0.0 */ public function getShareByToken($token); } diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 2bbcdfa048..565c5e97aa 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -326,7 +326,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share->method('getId')->willReturn($id); $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') @@ -361,7 +361,7 @@ class DefaultShareProviderTest extends \Test\TestCase { * @expectedException \OC\Share20\Exception\BackendError */ public function testDeleteFails() { - $share = $this->getMock('OC\Share20\IShare'); + $share = $this->getMock('OCP\Share\IShare'); $share ->method('getId') ->willReturn(42); @@ -510,7 +510,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['group1', $group1] ])); - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn($id); $children = $this->provider->getChildren($share); diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index ef602fc8e4..6dcfb37e12 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -20,8 +20,8 @@ */ namespace Test\Share20; -use OC\Share20\IProviderFactory; -use OC\Share20\IShare; +use OCP\Share\IProviderFactory; +use OCP\Share\IShare; use OC\Share20\Manager; use OC\Share20\Exception; @@ -29,7 +29,7 @@ use OC\Share20\Share; use OCP\IL10N; use OCP\ILogger; use OCP\IConfig; -use OC\Share20\IShareProvider; +use OCP\Share\IShareProvider; use OCP\Security\ISecureRandom; use OCP\Security\IHasher; use OCP\Files\Mount\IMountManager; @@ -102,7 +102,9 @@ class ManagerTest extends \Test\TestCase { $this->factory ); - $this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider'); + $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') + ->disableOriginalConstructor() + ->getMock(); $this->defaultProvider->method('identifier')->willReturn('default'); $this->factory->setProvider($this->defaultProvider); @@ -130,7 +132,7 @@ class ManagerTest extends \Test\TestCase { * @expectedException \OC\Share20\Exception\ShareNotFound */ public function testDeleteNoShareId() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share ->expects($this->once()) @@ -170,7 +172,7 @@ class ManagerTest extends \Test\TestCase { $path = $this->getMock('\OCP\Files\File'); $path->method('getId')->willReturn(1); - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getId')->willReturn(42); $share->method('getFullId')->willReturn('prov:42'); $share->method('getShareType')->willReturn($shareType); @@ -261,7 +263,7 @@ class ManagerTest extends \Test\TestCase { $path = $this->getMock('\OCP\Files\File'); $path->method('getId')->willReturn(1); - $share1 = $this->getMock('\OC\Share20\IShare'); + $share1 = $this->getMock('\OCP\Share\IShare'); $share1->method('getId')->willReturn(42); $share1->method('getFullId')->willReturn('prov:42'); $share1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); @@ -270,7 +272,7 @@ class ManagerTest extends \Test\TestCase { $share1->method('getPath')->willReturn($path); $share1->method('getTarget')->willReturn('myTarget1'); - $share2 = $this->getMock('\OC\Share20\IShare'); + $share2 = $this->getMock('\OCP\Share\IShare'); $share2->method('getId')->willReturn(43); $share2->method('getFullId')->willReturn('prov:43'); $share2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); @@ -280,7 +282,7 @@ class ManagerTest extends \Test\TestCase { $share2->method('getTarget')->willReturn('myTarget2'); $share2->method('getParent')->willReturn(42); - $share3 = $this->getMock('\OC\Share20\IShare'); + $share3 = $this->getMock('\OCP\Share\IShare'); $share3->method('getId')->willReturn(44); $share3->method('getFullId')->willReturn('prov:44'); $share3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); @@ -383,14 +385,14 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['deleteShare']) ->getMock(); - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child1 = $this->getMock('\OC\Share20\IShare'); + $child1 = $this->getMock('\OCP\Share\IShare'); $child1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child2 = $this->getMock('\OC\Share20\IShare'); + $child2 = $this->getMock('\OCP\Share\IShare'); $child2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child3 = $this->getMock('\OC\Share20\IShare'); + $child3 = $this->getMock('\OCP\Share\IShare'); $child3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $shares = [ @@ -419,7 +421,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareById() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $this->defaultProvider ->expects($this->once()) @@ -487,7 +489,7 @@ class ManagerTest extends \Test\TestCase { public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, $permissions, $expireDate = null, $password = null) { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn($type); $share->method('getSharedWith')->willReturn($sharedWith); @@ -1487,7 +1489,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareByToken() { - $factory = $this->getMock('\OC\Share20\IProviderFactory'); + $factory = $this->getMock('\OCP\Share\IProviderFactory'); $manager = new Manager( $this->logger, @@ -1500,7 +1502,7 @@ class ManagerTest extends \Test\TestCase { $factory ); - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $factory->expects($this->once()) ->method('getProviderForType') @@ -1517,13 +1519,13 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordNoLinkShare() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $this->assertFalse($this->manager->checkPassword($share, 'password')); } public function testCheckPasswordNoPassword() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $this->assertFalse($this->manager->checkPassword($share, 'password')); @@ -1532,7 +1534,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordInvalidPassword() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('password'); @@ -1542,7 +1544,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordValidPassword() { - $share = $this->getMock('\OC\Share20\IShare'); + $share = $this->getMock('\OCP\Share\IShare'); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('passwordHash');