*/
namespace OCA\Files_Sharing\API;
-use OC\Share20\IShare;
-
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IRequest;
/**
* 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(),
}
$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));
}
/**
- * @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;
use OCP\Util;
use OCA\Files_Sharing\Activity;
use \OCP\Files\NotFoundException;
-use \OC\Share20\IShare;
use OCP\Files\IRootFolder;
/**
* 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());
*/
namespace OCA\Files_Sharing\Tests\API;
-use OC\Share20\IShare;
use OCA\Files_Sharing\API\Share20OCS;
use OCP\IGroupManager;
use OCP\IUserManager;
}
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())
}
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())
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);
/**
* @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,
}
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]));
}
}
public function testCreateShareInvalidPermissions() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share);
$this->request
}
public function testCreateShareUserNoShareWith() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share);
$this->request
}
public function testCreateShareUserNoValidShareWith() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share);
$this->request
}
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([
}
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')
}
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([
}
public function testShowAuthenticateNotAuthenticated() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager
->expects($this->once())
}
public function testShowAuthenticateAuthenticatedForDifferentShare() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(1);
$this->shareManager
}
public function testShowAuthenticateCorrectShare() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(1);
$this->shareManager
}
public function testAuthenticateValidPassword() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(42);
$this->shareManager
}
public function testAuthenticateInvalidPassword() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(42);
$this->shareManager
}
public function testShowShareNotAuthenticated() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getPassword')->willReturn('password');
$this->shareManager
$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);
}
public function testDownloadShare() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getPassword')->willReturn('password');
$this->shareManager
*/
namespace OC\Share20;
+use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException;
use OC\Share20\Exception\ShareNotFound;
/**
* 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');
/**
* 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.
/**
* 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();
/**
* 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());
* 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 */
+++ /dev/null
-<?php
-/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Share20;
-
-use OC\Share20\Exception\ProviderException;
-use OCP\IServerContainer;
-
-/**
- * Interface IProviderFactory
- *
- * @package OC\Share20
- * @since 9.0.0
- */
-interface IProviderFactory {
-
- /**
- * IProviderFactory constructor.
- * @param IServerContainer $serverContainer
- */
- public function __construct(IServerContainer $serverContainer);
-
- /**
- * @param string $id
- * @return IShareProvider
- * @throws ProviderException
- */
- public function getProvider($id);
-
- /**
- * @param int $shareType
- * @return IShareProvider
- * @throws ProviderException
- */
- public function getProviderForType($shareType);
-}
+++ /dev/null
-<?php
-/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Share20;
-
-use OCP\Files\File;
-use OCP\Files\Folder;
-use OCP\Files\Node;
-use OCP\IUser;
-use OCP\IGroup;
-
-interface IShare {
-
- /**
- * Get the id of the share
- *
- * @return string
- */
- public function getId();
-
- /**
- * Set the id of the share
- *
- * @param string $id
- * @return IShare The modified share object
- */
- public function setId($id);
-
- /**
- * Get the full share id
- *
- * @return string
- */
- public function getFullId();
-
- /**
- * Set the provider id
- *
- * @param string $id
- * @return IShare The modified share object
- */
- public function setProviderId($id);
-
- /**
- * Set the path of this share
- *
- * @param Node $path
- * @return IShare The modified object
- */
- public function setPath(Node $path);
-
- /**
- * Get the path of this share for the current user
- *
- * @return File|Folder
- */
- public function getPath();
-
- /**
- * Set the shareType
- *
- * @param int $shareType
- * @return IShare The modified object
- */
- public function setShareType($shareType);
-
- /**
- * Get the shareType
- *
- * @return int
- */
- public function getShareType();
-
- /**
- * Set the receiver of this share
- *
- * @param IUser|IGroup|string
- * @return IShare The modified object
- */
- public function setSharedWith($sharedWith);
-
- /**
- * Get the receiver of this share
- *
- * @return IUser|IGroup|string
- */
- public function getSharedWith();
-
- /**
- * Set the permissions
- *
- * @param int $permissions
- * @return IShare The modified object
- */
- public function setPermissions($permissions);
-
- /**
- * Get the share permissions
- *
- * @return int
- */
- public function getPermissions();
-
- /**
- * Set the expiration date
- *
- * @param \DateTime $expireDate
- * @return IShare The modified object
- */
- public function setExpirationDate($expireDate);
-
- /**
- * Get the share expiration date
- *
- * @return \DateTime
- */
- public function getExpirationDate();
-
- /**
- * Set the sharer of the path
- *
- * @param IUser|string $sharedBy
- * @return IShare The modified object
- */
- public function setSharedBy($sharedBy);
-
- /**
- * Get share sharer
- *
- * @return IUser|string
- */
- public function getSharedBy();
-
- /**
- * Set the original share owner (who owns the path)
- *
- * @param IUser|string
- *
- * @return IShare The modified object
- */
- public function setShareOwner($shareOwner);
-
- /**
- * Get the original share owner (who owns the path)
- *
- * @return IUser|string
- */
- public function getShareOwner();
-
- /**
- * Set the password
- *
- * @param string $password
- *
- * @return IShare The modified object
- */
- public function setPassword($password);
-
- /**
- * Is a password set for this share
- *
- * @return string
- */
- public function getPassword();
-
- /**
- * Set the token
- *
- * @param string $token
- * @return IShare The modified object
- */
- public function setToken($token);
-
- /**
- * Get the token
- *
- * @return string
- */
- public function getToken();
-
- /**
- * Get the parent it
- *
- * @return int
- */
- public function getParent();
-
- /**
- * Set the target of this share
- *
- * @param string $target
- * @return IShare The modified object
- */
- public function setTarget($target);
-
- /**
- * Get the target of this share
- *
- * @return string
- */
- public function getTarget();
-
- /**
- * Set the time this share was created
- *
- * @param int $shareTime
- * @return IShare The modified object
- */
- public function setShareTime($shareTime);
-
- /**
- * Get the timestamp this share was created
- *
- * @return int
- */
- public function getShareTime();
-
- /**
- * Set mailSend
- *
- * @param bool $mailSend
- * @return IShare The modified object
- */
- public function setMailSend($mailSend);
-
- /**
- * Get mailSend
- *
- * @return bool
- */
- public function getMailSend();
-}
+++ /dev/null
-<?php
-/**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Share20;
-
-use OC\Share20\Exception\ShareNotFound;
-use OC\Share20\Exception\BackendError;
-use OCP\IUser;
-
-interface IShareProvider {
-
- /**
- * Return the identifier of this provider.
- *
- * @return string Containing only [a-zA-Z0-9]
- */
- public function identifier();
-
- /**
- * Share a path
- *
- * @param IShare $share
- * @return IShare The share object
- */
- public function create(IShare $share);
-
- /**
- * Update a share
- *
- * @param IShare $share
- * @return IShare The share object
- */
- public function update(IShare $share);
-
- /**
- * Delete a share
- *
- * @param IShare $share
- * @throws BackendError
- */
- public function delete(IShare $share);
-
- /**
- * Unshare a file from self as recipient.
- * This may require special handling.
- *
- * @param IShare $share
- * @param IUser $recipient
- */
- public function deleteFromSelf(IShare $share, IUser $recipient);
-
- /**
- * Get all shares by the given user
- *
- * @param IUser $user
- * @param int $shareType
- * @param \OCP\Files\File|\OCP\Files\Folder $node
- * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
- * @param int $limit The maximum number of shares to be returned, -1 for all shares
- * @param int $offset
- * @return Share[]
- */
- public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset);
-
- /**
- * Get share by id
- *
- * @param int $id
- * @return IShare
- * @throws ShareNotFound
- */
- 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[]
- */
- public function getSharesByPath(\OCP\Files\Node $path);
-
- /**
- * Get shared with the given user
- *
- * @param IUser $user get shares where this user is the recipient
- * @param int $shareType
- * @param int $limit The max number of entries returned, -1 for all
- * @param int $offset
- * @param Share
- */
- public function getSharedWith(IUser $user, $shareType, $limit, $offset);
-
- /**
- * Get a share by token
- *
- * @param string $token
- * @return IShare
- * @throws ShareNotFound
- */
- public function getShareByToken($token);
-}
*/
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;
/** @var IProviderFactory */
private $factory;
- /** @var array */
- private $type2provider;
-
/** @var ILogger */
private $logger;
IL10N $l,
IProviderFactory $factory
) {
- $this->providers = [];
- $this->type2provider = [];
-
$this->logger = $logger;
$this->config = $config;
$this->secureRandom = $secureRandom;
/**
* 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)) {
/**
* 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
/**
* 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())) {
/**
* 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');
/**
* 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;
}
/**
* 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');
}
/**
* 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)) {
/**
* 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());
/**
* 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 = '';
* 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);
* @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 &&
* @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);
/**
* 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;
/**
* Create a new share
- * @return IShare;
+ * @return \OCP\Share\IShare;
*/
public function newShare() {
return new \OC\Share20\Share();
*/
namespace OC\Share20;
+use OCP\Share\IProviderFactory;
use OC\Share20\Exception\ProviderException;
use OCP\IServerContainer;
use OCP\IUser;
use OCP\IGroup;
-class Share implements IShare {
+class Share implements \OCP\Share\IShare {
/** @var string */
private $id;
--- /dev/null
+<?php
+/**
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\Share;
+
+use OC\Share20\Exception\ProviderException;
+use OCP\IServerContainer;
+
+/**
+ * Interface IProviderFactory
+ *
+ * @package OC\Share20
+ * @since 9.0.0
+ */
+interface IProviderFactory {
+
+ /**
+ * IProviderFactory constructor.
+ * @param IServerContainer $serverContainer
+ * @since 9.0.0
+ */
+ public function __construct(IServerContainer $serverContainer);
+
+ /**
+ * @param string $id
+ * @return IShareProvider
+ * @throws ProviderException
+ * @since 9.0.0
+ */
+ public function getProvider($id);
+
+ /**
+ * @param int $shareType
+ * @return IShareProvider
+ * @throws ProviderException
+ * @since 9.0.0
+ */
+ public function getProviderForType($shareType);
+}
--- /dev/null
+<?php
+/**
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\Share;
+
+use OCP\Files\File;
+use OCP\Files\Folder;
+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();
+
+ /**
+ * Set the id of the share
+ *
+ * @param string $id
+ * @return \OCP\Share\IShare The modified share object
+ * @since 9.0.0
+ */
+ public function setId($id);
+
+ /**
+ * Get the full share id
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getFullId();
+
+ /**
+ * Set the provider id
+ *
+ * @param string $id
+ * @return \OCP\Share\IShare The modified share object\
+ * @since 9.0.0
+ */
+ public function setProviderId($id);
+
+ /**
+ * Set the path of this share
+ *
+ * @param Node $path
+ * @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();
+
+ /**
+ * Set the shareType
+ *
+ * @param int $shareType
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setShareType($shareType);
+
+ /**
+ * Get the shareType
+ *
+ * @return int
+ * @since 9.0.0
+ */
+ public function getShareType();
+
+ /**
+ * Set the receiver of this share
+ *
+ * @param IUser|IGroup|string
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setSharedWith($sharedWith);
+
+ /**
+ * Get the receiver of this share
+ *
+ * @return IUser|IGroup|string
+ * @since 9.0.0
+ */
+ public function getSharedWith();
+
+ /**
+ * Set the permissions
+ *
+ * @param int $permissions
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setPermissions($permissions);
+
+ /**
+ * Get the share permissions
+ *
+ * @return int
+ * @since 9.0.0
+ */
+ public function getPermissions();
+
+ /**
+ * Set the expiration date
+ *
+ * @param \DateTime $expireDate
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setExpirationDate($expireDate);
+
+ /**
+ * Get the share expiration date
+ *
+ * @return \DateTime
+ * @since 9.0.0
+ */
+ public function getExpirationDate();
+
+ /**
+ * Set the sharer of the path
+ *
+ * @param IUser|string $sharedBy
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setSharedBy($sharedBy);
+
+ /**
+ * Get share sharer
+ *
+ * @return IUser|string
+ * @since 9.0.0
+ */
+ public function getSharedBy();
+
+ /**
+ * Set the original share owner (who owns the path)
+ *
+ * @param IUser|string
+ * @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();
+
+ /**
+ * Set the password
+ *
+ * @param string $password
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setPassword($password);
+
+ /**
+ * Is a password set for this share
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getPassword();
+
+ /**
+ * Set the token
+ *
+ * @param string $token
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setToken($token);
+
+ /**
+ * Get the token
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getToken();
+
+ /**
+ * Get the parent it
+ *
+ * @return int
+ * @since 9.0.0
+ */
+ public function getParent();
+
+ /**
+ * Set the target of this share
+ *
+ * @param string $target
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setTarget($target);
+
+ /**
+ * Get the target of this share
+ *
+ * @return string
+ * @since 9.0.0
+ */
+ public function getTarget();
+
+ /**
+ * Set the time this share was created
+ *
+ * @param int $shareTime
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setShareTime($shareTime);
+
+ /**
+ * Get the timestamp this share was created
+ *
+ * @return int
+ * @since 9.0.0
+ */
+ public function getShareTime();
+
+ /**
+ * Set mailSend
+ *
+ * @param bool $mailSend
+ * @return \OCP\Share\IShare The modified object
+ * @since 9.0.0
+ */
+ public function setMailSend($mailSend);
+
+ /**
+ * Get mailSend
+ *
+ * @return bool
+ * @since 9.0.0
+ */
+ public function getMailSend();
+}
--- /dev/null
+<?php
+/**
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+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 \OCP\Share\IShare $share
+ * @return \OCP\Share\IShare The share object
+ * @since 9.0.0
+ */
+ public function create(\OCP\Share\IShare $share);
+
+ /**
+ * Update a share
+ *
+ * @param \OCP\Share\IShare $share
+ * @return \OCP\Share\IShare The share object
+ * @since 9.0.0
+ */
+ public function update(\OCP\Share\IShare $share);
+
+ /**
+ * Delete a share
+ *
+ * @param \OCP\Share\IShare $share
+ * @since 9.0.0
+ */
+ public function delete(\OCP\Share\IShare $share);
+
+ /**
+ * Unshare a file from self as recipient.
+ * This may require special handling.
+ *
+ * @param \OCP\Share\IShare $share
+ * @param IUser $recipient
+ * @since 9.0.0
+ */
+ public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient);
+
+ /**
+ * Get all shares by the given user
+ *
+ * @param IUser $user
+ * @param int $shareType
+ * @param \OCP\Files\File|\OCP\Files\Folder $node
+ * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
+ * @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);
+
+ /**
+ * Get share by id
+ *
+ * @param int $id
+ * @return IShare
+ * @throws ShareNotFound
+ * @since 9.0.0
+ */
+ public function getShareById($id);
+
+ /**
+ * Get shares for a given path
+ *
+ * @param \OCP\Files\Node $path
+ * @return IShare[]
+ * @since 9.0.0
+ */
+ public function getSharesByPath(\OCP\Files\Node $path);
+
+ /**
+ * Get shared with the given user
+ *
+ * @param IUser $user get shares where this user is the recipient
+ * @param int $shareType
+ * @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);
+
+ /**
+ * Get a share by token
+ *
+ * @param string $token
+ * @return IShare
+ * @throws ShareNotFound
+ * @since 9.0.0
+ */
+ public function getShareByToken($token);
+}
$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')
* @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);
['group1', $group1]
]));
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn($id);
$children = $this->provider->getChildren($share);
*/
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;
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;
$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);
* @expectedException \OC\Share20\Exception\ShareNotFound
*/
public function testDeleteNoShareId() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$share
->expects($this->once())
$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);
$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);
$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);
$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);
->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 = [
}
public function testGetShareById() {
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$this->defaultProvider
->expects($this->once())
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);
}
public function testGetShareByToken() {
- $factory = $this->getMock('\OC\Share20\IProviderFactory');
+ $factory = $this->getMock('\OCP\Share\IProviderFactory');
$manager = new Manager(
$this->logger,
$factory
);
- $share = $this->getMock('\OC\Share20\IShare');
+ $share = $this->getMock('\OCP\Share\IShare');
$factory->expects($this->once())
->method('getProviderForType')
}
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'));
}
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');
}
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');