Merge pull request #21957 from owncloud/share2_to_ocp

[Share 2.0] Move interfaces to OCP
This commit is contained in:
Morris Jobke 2016-01-28 10:41:39 +01:00
commit 0e95aeab75
19 changed files with 825 additions and 630 deletions

View File

@ -20,8 +20,6 @@
*/ */
namespace OCA\Files_Sharing\API; namespace OCA\Files_Sharing\API;
use OC\Share20\IShare;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IRequest; use OCP\IRequest;
@ -73,36 +71,36 @@ class Share20OCS {
/** /**
* Convert an IShare to an array for OCS output * Convert an IShare to an array for OCS output
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return array * @return array
*/ */
protected function formatShare($share) { protected function formatShare(\OCP\Share\IShare $share) {
$result = [ $result = [
'id' => $share->getId(), 'id' => $share->getId(),
'share_type' => $share->getShareType(), 'share_type' => $share->getShareType(),
'uid_owner' => $share->getSharedBy()->getUID(), 'uid_owner' => $share->getSharedBy()->getUID(),
'displayname_owner' => $share->getSharedBy()->getDisplayName(), 'displayname_owner' => $share->getSharedBy()->getDisplayName(),
'permissions' => $share->getPermissions(), 'permissions' => $share->getPermissions(),
'stime' => $share->getShareTime(), 'stime' => $share->getShareTime()->getTimestamp(),
'parent' => $share->getParent(), 'parent' => null,
'expiration' => null, 'expiration' => null,
'token' => null, 'token' => null,
'uid_file_owner' => $share->getShareOwner()->getUID(), 'uid_file_owner' => $share->getShareOwner()->getUID(),
'displayname_file_owner' => $share->getShareOwner()->getDisplayName(), 'displayname_file_owner' => $share->getShareOwner()->getDisplayName(),
]; ];
$path = $share->getPath(); $node = $share->getNode();
$result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($path->getPath()); $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($node->getPath());
if ($path instanceOf \OCP\Files\Folder) { if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder'; $result['item_type'] = 'folder';
} else { } else {
$result['item_type'] = 'file'; $result['item_type'] = 'file';
} }
$result['storage_id'] = $path->getStorage()->getId(); $result['storage_id'] = $node->getStorage()->getId();
$result['storage'] = $path->getStorage()->getCache()->getNumericStorageId(); $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
$result['item_source'] = $path->getId(); $result['item_source'] = $node->getId();
$result['file_source'] = $path->getId(); $result['file_source'] = $node->getId();
$result['file_parent'] = $path->getParent()->getId(); $result['file_parent'] = $node->getParent()->getId();
$result['file_target'] = $share->getTarget(); $result['file_target'] = $share->getTarget();
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
@ -222,7 +220,7 @@ class Share20OCS {
return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist'); return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist');
} }
$share->setPath($path); $share->setNode($path);
// Parse permissions (if available) // Parse permissions (if available)
$permissions = $this->request->getParam('permissions', null); $permissions = $this->request->getParam('permissions', null);
@ -353,7 +351,7 @@ class Share20OCS {
} }
$nodes = $folder->getDirectoryListing(); $nodes = $folder->getDirectoryListing();
/** @var IShare[] $shares */ /** @var \OCP\Share\IShare[] $shares */
$shares = []; $shares = [];
foreach ($nodes as $node) { foreach ($nodes as $node) {
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); $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 * @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 // A file with permissions 0 can't be accessed by us. So Don't show it
if ($share->getPermissions() === 0) { if ($share->getPermissions() === 0) {
return false; return false;

View File

@ -51,7 +51,6 @@ use OCA\Files_Sharing\Helper;
use OCP\Util; use OCP\Util;
use OCA\Files_Sharing\Activity; use OCA\Files_Sharing\Activity;
use \OCP\Files\NotFoundException; use \OCP\Files\NotFoundException;
use \OC\Share20\IShare;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
/** /**
@ -168,11 +167,11 @@ class ShareController extends Controller {
* This is a modified version of Helper::authenticate * This is a modified version of Helper::authenticate
* TODO: Try to merge back eventually with Helper::authenticate * TODO: Try to merge back eventually with Helper::authenticate
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @param string|null $password * @param string|null $password
* @return bool * @return bool
*/ */
private function linkShareAuth(IShare $share, $password = null) { private function linkShareAuth(\OCP\Share\IShare $share, $password = null) {
if ($password !== null) { if ($password !== null) {
if ($this->shareManager->checkPassword($share, $password)) { if ($this->shareManager->checkPassword($share, $password)) {
$this->session->set('public_link_authenticated', (string)$share->getId()); $this->session->set('public_link_authenticated', (string)$share->getId());
@ -215,14 +214,14 @@ class ShareController extends Controller {
} }
// We can't get the path of a file share // We can't get the path of a file share
if ($share->getPath() instanceof \OCP\Files\File && $path !== '') { if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
throw new NotFoundException(); throw new NotFoundException();
} }
$rootFolder = null; $rootFolder = null;
if ($share->getPath() instanceof \OCP\Files\Folder) { if ($share->getNode() instanceof \OCP\Files\Folder) {
/** @var \OCP\Files\Folder $rootFolder */ /** @var \OCP\Files\Folder $rootFolder */
$rootFolder = $share->getPath(); $rootFolder = $share->getNode();
try { try {
$path = $rootFolder->get($path); $path = $rootFolder->get($path);
@ -234,26 +233,26 @@ class ShareController extends Controller {
$shareTmpl = []; $shareTmpl = [];
$shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName(); $shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
$shareTmpl['owner'] = $share->getShareOwner()->getUID(); $shareTmpl['owner'] = $share->getShareOwner()->getUID();
$shareTmpl['filename'] = $share->getPath()->getName(); $shareTmpl['filename'] = $share->getNode()->getName();
$shareTmpl['directory_path'] = $share->getTarget(); $shareTmpl['directory_path'] = $share->getTarget();
$shareTmpl['mimetype'] = $share->getPath()->getMimetype(); $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getPath()->getMimetype()); $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
$shareTmpl['dirToken'] = $token; $shareTmpl['dirToken'] = $token;
$shareTmpl['sharingToken'] = $token; $shareTmpl['sharingToken'] = $token;
$shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled(); $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
$shareTmpl['dir'] = ''; $shareTmpl['dir'] = '';
$shareTmpl['nonHumanFileSize'] = $share->getPath()->getSize(); $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getPath()->getSize()); $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
// Show file list // Show file list
if ($share->getPath() instanceof \OCP\Files\Folder) { if ($share->getNode() instanceof \OCP\Files\Folder) {
$shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath()); $shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
/* /*
* The OC_Util methods require a view. This just uses the node API * The OC_Util methods require a view. This just uses the node API
*/ */
$freeSpace = $share->getPath()->getStorage()->free_space($share->getPath()->getInternalPath()); $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) { if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) {
$freeSpace = max($freeSpace, 0); $freeSpace = max($freeSpace, 0);
} else { } else {
@ -321,23 +320,23 @@ class ShareController extends Controller {
} }
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID()); $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
$originalSharePath = $userFolder->getRelativePath($share->getPath()->getPath()); $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
// Single file share // Single file share
if ($share->getPath() instanceof \OCP\Files\File) { if ($share->getNode() instanceof \OCP\Files\File) {
// Single file download // Single file download
$event = $this->activityManager->generateEvent(); $event = $this->activityManager->generateEvent();
$event->setApp('files_sharing') $event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS) ->setType(Activity::TYPE_PUBLIC_LINKS)
->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getPath()->getPath())]) ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())])
->setAffectedUser($share->getShareOwner()->getUID()) ->setAffectedUser($share->getShareOwner()->getUID())
->setObject('files', $share->getPath()->getId(), $userFolder->getRelativePath($share->getPath()->getPath())); ->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath()));
$this->activityManager->publish($event); $this->activityManager->publish($event);
} }
// Directory share // Directory share
else { else {
/** @var \OCP\Files\Folder $node */ /** @var \OCP\Files\Folder $node */
$node = $share->getPath(); $node = $share->getNode();
// Try to get the path // Try to get the path
if ($path !== '') { if ($path !== '') {

View File

@ -20,7 +20,6 @@
*/ */
namespace OCA\Files_Sharing\Tests\API; namespace OCA\Files_Sharing\Tests\API;
use OC\Share20\IShare;
use OCA\Files_Sharing\API\Share20OCS; use OCA\Files_Sharing\API\Share20OCS;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUserManager; use OCP\IUserManager;
@ -90,7 +89,7 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testDeleteShareCouldNotDelete() { public function testDeleteShareCouldNotDelete() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareOwner')->willReturn($this->currentUser); $share->method('getShareOwner')->willReturn($this->currentUser);
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
@ -109,7 +108,7 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testDeleteShare() { public function testDeleteShare() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getSharedBy')->willReturn($this->currentUser); $share->method('getSharedBy')->willReturn($this->currentUser);
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
@ -143,17 +142,18 @@ class Share20OCSTest extends \Test\TestCase {
public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $token=null, $shareTime, $expiration, $parent, $target, $mail_send, $token=null,
$password=null) { $password=null) {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getId')->willReturn($id); $share->method('getId')->willReturn($id);
$share->method('getShareType')->willReturn($shareType); $share->method('getShareType')->willReturn($shareType);
$share->method('getSharedWith')->willReturn($sharedWith); $share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy); $share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getShareOwner')->willReturn($shareOwner); $share->method('getShareOwner')->willReturn($shareOwner);
$share->method('getPath')->willReturn($path); $share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions); $share->method('getPermissions')->willReturn($permissions);
$share->method('getShareTime')->willReturn($shareTime); $time = new \DateTime();
$time->setTimestamp($shareTime);
$share->method('getShareTime')->willReturn($time);
$share->method('getExpirationDate')->willReturn($expiration); $share->method('getExpirationDate')->willReturn($expiration);
$share->method('getParent')->willReturn($parent);
$share->method('getTarget')->willReturn($target); $share->method('getTarget')->willReturn($target);
$share->method('getMailSend')->willReturn($mail_send); $share->method('getMailSend')->willReturn($mail_send);
$share->method('getToken')->willReturn($token); $share->method('getToken')->willReturn($token);
@ -243,7 +243,7 @@ class Share20OCSTest extends \Test\TestCase {
'expiration' => null, 'expiration' => null,
'permissions' => 4, 'permissions' => 4,
'stime' => 5, 'stime' => 5,
'parent' => 6, 'parent' => null,
'storage_id' => 'STORAGE', 'storage_id' => 'STORAGE',
'path' => 'file', 'path' => 'file',
'storage' => 101, 'storage' => 101,
@ -284,7 +284,7 @@ class Share20OCSTest extends \Test\TestCase {
'expiration' => null, 'expiration' => null,
'permissions' => 4, 'permissions' => 4,
'stime' => 5, 'stime' => 5,
'parent' => 6, 'parent' => null,
'storage_id' => 'STORAGE', 'storage_id' => 'STORAGE',
'path' => 'folder', 'path' => 'folder',
'storage' => 101, 'storage' => 101,
@ -328,7 +328,7 @@ class Share20OCSTest extends \Test\TestCase {
'expiration' => '2000-01-02 00:00:00', 'expiration' => '2000-01-02 00:00:00',
'permissions' => 4, 'permissions' => 4,
'stime' => 5, 'stime' => 5,
'parent' => 6, 'parent' => null,
'storage_id' => 'STORAGE', 'storage_id' => 'STORAGE',
'path' => 'folder', 'path' => 'folder',
'storage' => 101, 'storage' => 101,
@ -345,7 +345,7 @@ class Share20OCSTest extends \Test\TestCase {
/** /**
* @dataProvider dataGetShare * @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') $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([ ->setConstructorArgs([
$this->shareManager, $this->shareManager,
@ -384,39 +384,39 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCanAccessShare() { public function testCanAccessShare() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getShareOwner')->willReturn($this->currentUser); $share->method('getShareOwner')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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); $share->method('getSharedBy')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser); $share->method('getSharedWith')->willReturn($this->currentUser);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$share->method('getSharedWith')->willReturn($this->getMock('OCP\IUser')); $share->method('getSharedWith')->willReturn($this->getMock('OCP\IUser'));
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$group = $this->getMock('OCP\IGroup'); $group = $this->getMock('OCP\IGroup');
$group->method('inGroup')->with($this->currentUser)->willReturn(true); $group->method('inGroup')->with($this->currentUser)->willReturn(true);
$share->method('getSharedWith')->willReturn($group); $share->method('getSharedWith')->willReturn($group);
$this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$group = $this->getMock('OCP\IGroup'); $group = $this->getMock('OCP\IGroup');
$group->method('inGroup')->with($this->currentUser)->willReturn(false); $group->method('inGroup')->with($this->currentUser)->willReturn(false);
$share->method('getSharedWith')->willReturn($group); $share->method('getSharedWith')->willReturn($group);
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $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); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
} }
@ -457,7 +457,7 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareInvalidPermissions() { public function testCreateShareInvalidPermissions() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->request $this->request
@ -488,7 +488,7 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareUserNoShareWith() { public function testCreateShareUserNoShareWith() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->request $this->request
@ -520,7 +520,7 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareUserNoValidShareWith() { public function testCreateShareUserNoValidShareWith() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->request $this->request
@ -553,8 +553,9 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareUser() { public function testCreateShareUser() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->will($this->returnArgument(0));
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([ ->setConstructorArgs([
@ -611,8 +612,9 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareGroupNoValidShareWith() { public function testCreateShareGroupNoValidShareWith() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->will($this->returnArgument(0));
$this->request $this->request
->method('getParam') ->method('getParam')
@ -644,8 +646,9 @@ class Share20OCSTest extends \Test\TestCase {
} }
public function testCreateShareGroup() { public function testCreateShareGroup() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->will($this->returnArgument(0));
$ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')
->setConstructorArgs([ ->setConstructorArgs([

View File

@ -116,7 +116,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testShowAuthenticateNotAuthenticated() { public function testShowAuthenticateNotAuthenticated() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->shareManager $this->shareManager
->expects($this->once()) ->expects($this->once())
@ -130,7 +130,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testShowAuthenticateAuthenticatedForDifferentShare() { public function testShowAuthenticateAuthenticatedForDifferentShare() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(1); $share->method('getId')->willReturn(1);
$this->shareManager $this->shareManager
@ -148,7 +148,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testShowAuthenticateCorrectShare() { public function testShowAuthenticateCorrectShare() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(1); $share->method('getId')->willReturn(1);
$this->shareManager $this->shareManager
@ -183,7 +183,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testAuthenticateValidPassword() { public function testAuthenticateValidPassword() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(42); $share->method('getId')->willReturn(42);
$this->shareManager $this->shareManager
@ -214,7 +214,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testAuthenticateInvalidPassword() { public function testAuthenticateInvalidPassword() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn(42); $share->method('getId')->willReturn(42);
$this->shareManager $this->shareManager
@ -252,7 +252,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testShowShareNotAuthenticated() { public function testShowShareNotAuthenticated() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getPassword')->willReturn('password'); $share->method('getPassword')->willReturn('password');
$this->shareManager $this->shareManager
@ -283,11 +283,11 @@ class ShareControllerTest extends \Test\TestCase {
$file->method('getMimetype')->willReturn('text/plain'); $file->method('getMimetype')->willReturn('text/plain');
$file->method('getSize')->willReturn(33); $file->method('getSize')->willReturn(33);
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn('42'); $share->method('getId')->willReturn('42');
$share->method('getPassword')->willReturn('password'); $share->method('getPassword')->willReturn('password');
$share->method('getShareOwner')->willReturn($owner); $share->method('getShareOwner')->willReturn($owner);
$share->method('getPath')->willReturn($file); $share->method('getNode')->willReturn($file);
$share->method('getTarget')->willReturn('/file1.txt'); $share->method('getTarget')->willReturn('/file1.txt');
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true); $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
@ -340,7 +340,7 @@ class ShareControllerTest extends \Test\TestCase {
} }
public function testDownloadShare() { public function testDownloadShare() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getPassword')->willReturn('password'); $share->method('getPassword')->willReturn('password');
$this->shareManager $this->shareManager

View File

@ -227,6 +227,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getSecureRandom(); return $this->getServer()->getSecureRandom();
}); });
$this->registerService('OCP\\Share\\IManager', function($c) {
return $this->getServer()->getShareManager();
});
$this->registerService('OCP\\SystemTag\\ISystemTagManager', function() { $this->registerService('OCP\\SystemTag\\ISystemTagManager', function() {
return $this->getServer()->getSystemTagManager(); return $this->getServer()->getSystemTagManager();
}); });

View File

@ -1256,9 +1256,8 @@ class Server extends ServerContainer implements IServerContainer {
return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserStoragesService'); return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserStoragesService');
} }
/** /**
* @return \OC\Share20\Manager * @return \OCP\Share\IManager
*/ */
public function getShareManager() { public function getShareManager() {
return $this->query('ShareManager'); return $this->query('ShareManager');

View File

@ -20,6 +20,7 @@
*/ */
namespace OC\Share20; namespace OC\Share20;
use OCP\Share\IShareProvider;
use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\InvalidShare;
use OC\Share20\Exception\ProviderException; use OC\Share20\Exception\ProviderException;
use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\ShareNotFound;
@ -87,12 +88,12 @@ class DefaultShareProvider implements IShareProvider {
/** /**
* Share a path * Share a path
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare The share object * @return \OCP\Share\IShare The share object
* @throws ShareNotFound * @throws ShareNotFound
* @throws \Exception * @throws \Exception
*/ */
public function create(IShare $share) { public function create(\OCP\Share\IShare $share) {
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
$qb->insert('share'); $qb->insert('share');
@ -127,15 +128,15 @@ class DefaultShareProvider implements IShareProvider {
// Set what is shares // Set what is shares
$qb->setValue('item_type', $qb->createParameter('itemType')); $qb->setValue('item_type', $qb->createParameter('itemType'));
if ($share->getPath() instanceof \OCP\Files\File) { if ($share->getNode() instanceof \OCP\Files\File) {
$qb->setParameter('itemType', 'file'); $qb->setParameter('itemType', 'file');
} else { } else {
$qb->setParameter('itemType', 'folder'); $qb->setParameter('itemType', 'folder');
} }
// Set the file id // Set the file id
$qb->setValue('item_source', $qb->createNamedParameter($share->getPath()->getId())); $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
$qb->setValue('file_source', $qb->createNamedParameter($share->getPath()->getId())); $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
// set the permissions // set the permissions
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
@ -179,10 +180,10 @@ class DefaultShareProvider implements IShareProvider {
/** /**
* Update a share * Update a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare The share object * @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) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
/* /*
* We allow updating the recipient on user shares. * We allow updating the recipient on user shares.
@ -194,8 +195,8 @@ class DefaultShareProvider implements IShareProvider {
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute(); ->execute();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
@ -204,8 +205,8 @@ class DefaultShareProvider implements IShareProvider {
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute(); ->execute();
/* /*
@ -216,8 +217,8 @@ class DefaultShareProvider implements IShareProvider {
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('item_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute(); ->execute();
/* /*
@ -238,8 +239,8 @@ class DefaultShareProvider implements IShareProvider {
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID())) ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID())) ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions())) ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
->set('item_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('file_source', $qb->createNamedParameter($share->getPath()->getId())) ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('token', $qb->createNamedParameter($share->getToken())) ->set('token', $qb->createNamedParameter($share->getToken()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
->execute(); ->execute();
@ -251,10 +252,10 @@ class DefaultShareProvider implements IShareProvider {
/** /**
* Get all children of this share * Get all children of this share
* *
* @param IShare $parent * @param \OCP\Share\IShare $parent
* @return IShare[] * @return IShare[]
*/ */
public function getChildren(IShare $parent) { public function getChildren(\OCP\Share\IShare $parent) {
$children = []; $children = [];
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
@ -286,10 +287,10 @@ class DefaultShareProvider implements IShareProvider {
/** /**
* Delete a share * Delete a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws BackendError * @throws BackendError
*/ */
public function delete(IShare $share) { public function delete(\OCP\Share\IShare $share) {
// Fetch share to make sure it exists // Fetch share to make sure it exists
$share = $this->getShareById($share->getId()); $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 * Unshare a share from the recipient. If this is a group share
* this means we need a special entry in the share db. * this means we need a special entry in the share db.
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @param IUser $recipient * @param IUser $recipient
* @throws BackendError * @throws BackendError
* @throws ProviderException * @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) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
/** @var IGroup $group */ /** @var IGroup $group */
@ -341,7 +342,7 @@ class DefaultShareProvider implements IShareProvider {
if ($data === false) { if ($data === false) {
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
$type = $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder'; $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
//Insert new share //Insert new share
$qb->insert('share') $qb->insert('share')
@ -352,11 +353,11 @@ class DefaultShareProvider implements IShareProvider {
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()), 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
'parent' => $qb->createNamedParameter($share->getId()), 'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($type), 'item_type' => $qb->createNamedParameter($type),
'item_source' => $qb->createNamedParameter($share->getPath()->getId()), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
'file_source' => $qb->createNamedParameter($share->getPath()->getId()), 'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
'file_target' => $qb->createNamedParameter($share->getTarget()), 'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter(0), 'permissions' => $qb->createNamedParameter(0),
'stime' => $qb->createNamedParameter($share->getSharetime()), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
])->execute(); ])->execute();
} else if ($data['permissions'] !== 0) { } else if ($data['permissions'] !== 0) {
@ -450,7 +451,7 @@ class DefaultShareProvider implements IShareProvider {
* Get share by id * Get share by id
* *
* @param int $id * @param int $id
* @return IShare * @return \OCP\Share\IShare
* @throws ShareNotFound * @throws ShareNotFound
*/ */
public function getShareById($id) { public function getShareById($id) {
@ -649,7 +650,7 @@ class DefaultShareProvider implements IShareProvider {
* Create a share object from an database row * Create a share object from an database row
* *
* @param mixed[] $data * @param mixed[] $data
* @return Share * @return \OCP\Share\IShare
* @throws InvalidShare * @throws InvalidShare
*/ */
private function createShare($data) { private function createShare($data) {
@ -658,9 +659,12 @@ class DefaultShareProvider implements IShareProvider {
->setShareType((int)$data['share_type']) ->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions']) ->setPermissions((int)$data['permissions'])
->setTarget($data['file_target']) ->setTarget($data['file_target'])
->setShareTime((int)$data['stime'])
->setMailSend((bool)$data['mail_send']); ->setMailSend((bool)$data['mail_send']);
$shareTime = new \DateTime();
$shareTime->setTimestamp((int)$data['stime']);
$share->setShareTime($shareTime);
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $this->userManager->get($data['share_with']); $sharedWith = $this->userManager->get($data['share_with']);
if ($sharedWith === null) { if ($sharedWith === null) {
@ -701,7 +705,7 @@ class DefaultShareProvider implements IShareProvider {
} }
$path = $this->getNode($share->getShareOwner(), (int)$data['file_source']); $path = $this->getNode($share->getShareOwner(), (int)$data['file_source']);
$share->setPath($path); $share->setNode($path);
if ($data['expiration'] !== null) { if ($data['expiration'] !== null) {
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);

View File

@ -1,233 +0,0 @@
<?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();
/**
* Get the timestamp this share was created
*
* @return int
*/
public function getSharetime();
/**
* Get mailSend
*
* @return bool
*/
public function getMailSend();
}

View File

@ -18,11 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
namespace OC\Share20; namespace OC\Share20;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OC\Share20\Exception\BackendError; use OC\Share20\Exception\BackendError;
use OC\Share20\Exception\ProviderException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -40,14 +41,11 @@ use OC\HintException;
/** /**
* This class is the communication hub for all sharing related operations. * This class is the communication hub for all sharing related operations.
*/ */
class Manager { class Manager implements IManager {
/** @var IProviderFactory */ /** @var IProviderFactory */
private $factory; private $factory;
/** @var array */
private $type2provider;
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
@ -91,9 +89,6 @@ class Manager {
IL10N $l, IL10N $l,
IProviderFactory $factory IProviderFactory $factory
) { ) {
$this->providers = [];
$this->type2provider = [];
$this->logger = $logger; $this->logger = $logger;
$this->config = $config; $this->config = $config;
$this->secureRandom = $secureRandom; $this->secureRandom = $secureRandom;
@ -147,10 +142,10 @@ class Manager {
/** /**
* Check for generic requirements before creating a share * Check for generic requirements before creating a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws \Exception * @throws \Exception
*/ */
protected function generalCreateChecks(IShare $share) { protected function generalCreateChecks(\OCP\Share\IShare $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
// We expect a valid user as sharedWith for user shares // We expect a valid user as sharedWith for user shares
if (!($share->getSharedWith() instanceof \OCP\IUser)) { if (!($share->getSharedWith() instanceof \OCP\IUser)) {
@ -181,19 +176,19 @@ class Manager {
} }
// The path should be set // The path should be set
if ($share->getPath() === null) { if ($share->getNode() === null) {
throw new \InvalidArgumentException('Path should be set'); throw new \InvalidArgumentException('Path should be set');
} }
// And it should be a file or a folder // And it should be a file or a folder
if (!($share->getPath() instanceof \OCP\Files\File) && if (!($share->getNode() instanceof \OCP\Files\File) &&
!($share->getPath() instanceof \OCP\Files\Folder)) { !($share->getNode() instanceof \OCP\Files\Folder)) {
throw new \InvalidArgumentException('Path should be either a file or a folder'); throw new \InvalidArgumentException('Path should be either a file or a folder');
} }
// Check if we actually have share permissions // Check if we actually have share permissions
if (!$share->getPath()->isShareable()) { if (!$share->getNode()->isShareable()) {
$message_t = $this->l->t('You are not allowed to share %s', [$share->getPath()->getPath()]); $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
throw new HintException($message_t, $message_t, 404); throw new HintException($message_t, $message_t, 404);
} }
@ -203,8 +198,8 @@ class Manager {
} }
// Check that we do not share with more permissions than we have // Check that we do not share with more permissions than we have
if ($share->getPermissions() & ~$share->getPath()->getPermissions()) { if ($share->getPermissions() & ~$share->getNode()->getPermissions()) {
$message_t = $this->l->t('Cannot increase permissions of %s', [$share->getPath()->getPath()]); $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
throw new HintException($message_t, $message_t, 404); throw new HintException($message_t, $message_t, 404);
} }
@ -266,10 +261,10 @@ class Manager {
/** /**
* Check for pre share requirements for user shares * Check for pre share requirements for user shares
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws \Exception * @throws \Exception
*/ */
protected function userCreateChecks(IShare $share) { protected function userCreateChecks(\OCP\Share\IShare $share) {
// Check if we can share with group members only // Check if we can share with group members only
if ($this->shareWithGroupMembersOnly()) { if ($this->shareWithGroupMembersOnly()) {
// Verify we can share with this user // Verify we can share with this user
@ -288,7 +283,7 @@ class Manager {
* Also this is not what we want in the future.. then we want to squash identical shares. * Also this is not what we want in the future.. then we want to squash identical shares.
*/ */
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
$existingShares = $provider->getSharesByPath($share->getPath()); $existingShares = $provider->getSharesByPath($share->getNode());
foreach($existingShares as $existingShare) { foreach($existingShares as $existingShare) {
// Ignore if it is the same share // Ignore if it is the same share
if ($existingShare->getFullId() === $share->getFullId()) { if ($existingShare->getFullId() === $share->getFullId()) {
@ -312,10 +307,10 @@ class Manager {
/** /**
* Check for pre share requirements for group shares * Check for pre share requirements for group shares
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws \Exception * @throws \Exception
*/ */
protected function groupCreateChecks(IShare $share) { protected function groupCreateChecks(\OCP\Share\IShare $share) {
// Verify if the user can share with this group // Verify if the user can share with this group
if ($this->shareWithGroupMembersOnly()) { if ($this->shareWithGroupMembersOnly()) {
if (!$share->getSharedWith()->inGroup($share->getSharedBy())) { if (!$share->getSharedWith()->inGroup($share->getSharedBy())) {
@ -329,7 +324,7 @@ class Manager {
* Also this is not what we want in the future.. then we want to squash identical shares. * Also this is not what we want in the future.. then we want to squash identical shares.
*/ */
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
$existingShares = $provider->getSharesByPath($share->getPath()); $existingShares = $provider->getSharesByPath($share->getNode());
foreach($existingShares as $existingShare) { foreach($existingShares as $existingShare) {
if ($existingShare->getFullId() === $share->getFullId()) { if ($existingShare->getFullId() === $share->getFullId()) {
continue; continue;
@ -344,10 +339,10 @@ class Manager {
/** /**
* Check for pre share requirements for link shares * Check for pre share requirements for link shares
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws \Exception * @throws \Exception
*/ */
protected function linkCreateChecks(IShare $share) { protected function linkCreateChecks(\OCP\Share\IShare $share) {
// Are link shares allowed? // Are link shares allowed?
if (!$this->shareApiAllowLinks()) { if (!$this->shareApiAllowLinks()) {
throw new \Exception('Link sharing not allowed'); throw new \Exception('Link sharing not allowed');
@ -388,15 +383,15 @@ class Manager {
/** /**
* Check if the user that is sharing can actually share * Check if the user that is sharing can actually share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return bool * @return bool
*/ */
protected function canShare(IShare $share) { protected function canShare(\OCP\Share\IShare $share) {
if (!$this->shareApiEnabled()) { if (!$this->shareApiEnabled()) {
return false; return false;
} }
if ($this->isSharingDisabledForUser($share->getSharedBy())) { if ($this->sharingDisabledForUser($share->getSharedBy())) {
return false; return false;
} }
@ -406,13 +401,13 @@ class Manager {
/** /**
* Share a path * Share a path
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return Share The share object * @return Share The share object
* @throws \Exception * @throws \Exception
* *
* TODO: handle link share permissions or check them * TODO: handle link share permissions or check them
*/ */
public function createShare(IShare $share) { public function createShare(\OCP\Share\IShare $share) {
if (!$this->canShare($share)) { if (!$this->canShare($share)) {
throw new \Exception('The Share API is disabled'); throw new \Exception('The Share API is disabled');
} }
@ -452,10 +447,10 @@ class Manager {
} }
// Verify if there are any issues with the path // Verify if there are any issues with the path
$this->pathCreateChecks($share->getPath()); $this->pathCreateChecks($share->getNode());
// On creation of a share the owner is always the owner of the path // On creation of a share the owner is always the owner of the path
$share->setShareOwner($share->getPath()->getOwner()); $share->setShareOwner($share->getNode()->getOwner());
// Cannot share with the owner // Cannot share with the owner
if ($share->getSharedWith() === $share->getShareOwner()) { if ($share->getSharedWith() === $share->getShareOwner()) {
@ -463,7 +458,7 @@ class Manager {
} }
// Generate the target // Generate the target
$target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getPath()->getName(); $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName();
$target = \OC\Files\Filesystem::normalizePath($target); $target = \OC\Files\Filesystem::normalizePath($target);
$share->setTarget($target); $share->setTarget($target);
@ -481,12 +476,12 @@ class Manager {
$run = true; $run = true;
$error = ''; $error = '';
$preHookData = [ $preHookData = [
'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getPath()->getId(), 'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(), 'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy()->getUID(), 'uidOwner' => $share->getSharedBy()->getUID(),
'permissions' => $share->getPermissions(), 'permissions' => $share->getPermissions(),
'fileSource' => $share->getPath()->getId(), 'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(), 'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(), 'token' => $share->getToken(),
'itemTarget' => $share->getTarget(), 'itemTarget' => $share->getTarget(),
@ -502,16 +497,15 @@ class Manager {
$provider = $this->factory->getProviderForType($share->getShareType()); $provider = $this->factory->getProviderForType($share->getShareType());
$share = $provider->create($share); $share = $provider->create($share);
$share->setProviderId($provider->identifier());
// Post share hook // Post share hook
$postHookData = [ $postHookData = [
'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getPath()->getId(), 'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(), 'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy()->getUID(), 'uidOwner' => $share->getSharedBy()->getUID(),
'permissions' => $share->getPermissions(), 'permissions' => $share->getPermissions(),
'fileSource' => $share->getPath()->getId(), 'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(), 'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(), 'token' => $share->getToken(),
'id' => $share->getId(), 'id' => $share->getId(),
@ -528,10 +522,10 @@ class Manager {
/** /**
* Update a share * Update a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare The share object * @return \OCP\Share\IShare The share object
*/ */
public function updateShare(IShare $share) { public function updateShare(\OCP\Share\IShare $share) {
$expirationDateUpdated = false; $expirationDateUpdated = false;
if (!$this->canShare($share)) { if (!$this->canShare($share)) {
@ -583,7 +577,7 @@ class Manager {
} }
} }
$this->pathCreateChecks($share->getPath()); $this->pathCreateChecks($share->getNode());
// Now update the share! // Now update the share!
$provider = $this->factory->getProviderForType($share->getShareType()); $provider = $this->factory->getProviderForType($share->getShareType());
@ -591,8 +585,8 @@ class Manager {
if ($expirationDateUpdated === true) { if ($expirationDateUpdated === true) {
\OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [
'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getPath()->getId(), 'itemSource' => $share->getNode()->getId(),
'date' => $share->getExpirationDate(), 'date' => $share->getExpirationDate(),
'uidOwner' => $share->getSharedBy()->getUID(), 'uidOwner' => $share->getSharedBy()->getUID(),
]); ]);
@ -604,10 +598,10 @@ class Manager {
/** /**
* Delete all the children of this share * Delete all the children of this share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare[] List of deleted shares * @return \OCP\Share\IShare[] List of deleted shares
*/ */
protected function deleteChildren(IShare $share) { protected function deleteChildren(\OCP\Share\IShare $share) {
$deletedShares = []; $deletedShares = [];
$provider = $this->factory->getProviderForType($share->getShareType()); $provider = $this->factory->getProviderForType($share->getShareType());
@ -626,16 +620,16 @@ class Manager {
/** /**
* Delete a share * Delete a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws ShareNotFound * @throws ShareNotFound
* @throws BackendError * @throws BackendError
* @throws ShareNotFound * @throws ShareNotFound
*/ */
public function deleteShare(IShare $share) { public function deleteShare(\OCP\Share\IShare $share) {
// Just to make sure we have all the info // Just to make sure we have all the info
$share = $this->getShareById($share->getFullId()); $share = $this->getShareById($share->getFullId());
$formatHookParams = function(IShare $share) { $formatHookParams = function(\OCP\Share\IShare $share) {
// Prepare hook // Prepare hook
$shareType = $share->getShareType(); $shareType = $share->getShareType();
$sharedWith = ''; $sharedWith = '';
@ -649,13 +643,13 @@ class Manager {
$hookParams = [ $hookParams = [
'id' => $share->getId(), 'id' => $share->getId(),
'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getPath()->getId(), 'itemSource' => $share->getNode()->getId(),
'shareType' => $shareType, 'shareType' => $shareType,
'shareWith' => $sharedWith, 'shareWith' => $sharedWith,
'itemparent' => $share->getParent(), 'itemparent' => $share->getParent(),
'uidOwner' => $share->getSharedBy()->getUID(), 'uidOwner' => $share->getSharedBy()->getUID(),
'fileSource' => $share->getPath()->getId(), 'fileSource' => $share->getNode()->getId(),
'fileTarget' => $share->getTarget() 'fileTarget' => $share->getTarget()
]; ];
return $hookParams; return $hookParams;
@ -694,10 +688,10 @@ class Manager {
* the users in a groups deletes that share. But the provider should * the users in a groups deletes that share. But the provider should
* handle this. * handle this.
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @param IUser $recipient * @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()); list($providerId, $id) = $this->splitFullId($share->getId());
$provider = $this->factory->getProvider($providerId); $provider = $this->factory->getProvider($providerId);
@ -713,7 +707,7 @@ class Manager {
* @param bool $reshares * @param bool $reshares
* @param int $limit The maximum number of returned results, -1 for all results * @param int $limit The maximum number of returned results, -1 for all results
* @param int $offset * @param int $offset
* @return IShare[] * @return \OCP\Share\IShare[]
*/ */
public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
if ($path !== null && if ($path !== null &&
@ -734,7 +728,7 @@ class Manager {
* @param int $shareType * @param int $shareType
* @param int $limit The maximum number of shares returned, -1 for all * @param int $limit The maximum number of shares returned, -1 for all
* @param int $offset * @param int $offset
* @return IShare[] * @return \OCP\Share\IShare[]
*/ */
public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) { public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0) {
$provider = $this->factory->getProviderForType($shareType); $provider = $this->factory->getProviderForType($shareType);
@ -759,7 +753,6 @@ class Manager {
$provider = $this->factory->getProvider($providerId); $provider = $this->factory->getProvider($providerId);
$share = $provider->getShareById($id); $share = $provider->getShareById($id);
$share->setProviderId($provider->identifier());
return $share; return $share;
} }
@ -797,11 +790,11 @@ class Manager {
/** /**
* Verify the password of a public share * Verify the password of a public share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @param string $password * @param string $password
* @return bool * @return bool
*/ */
public function checkPassword(IShare $share, $password) { public function checkPassword(\OCP\Share\IShare $share, $password) {
if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) { if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
//TODO maybe exception? //TODO maybe exception?
return false; return false;
@ -852,7 +845,7 @@ class Manager {
/** /**
* Create a new share * Create a new share
* @return IShare; * @return \OCP\Share\IShare;
*/ */
public function newShare() { public function newShare() {
return new \OC\Share20\Share(); return new \OC\Share20\Share();
@ -938,7 +931,7 @@ class Manager {
* @param IUser $user * @param IUser $user
* @return bool * @return bool
*/ */
public function isSharingDisabledForUser($user) { public function sharingDisabledForUser(IUser $user) {
if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = json_decode($groupsList); $excludedGroups = json_decode($groupsList);

View File

@ -20,6 +20,7 @@
*/ */
namespace OC\Share20; namespace OC\Share20;
use OCP\Share\IProviderFactory;
use OC\Share20\Exception\ProviderException; use OC\Share20\Exception\ProviderException;
use OCP\IServerContainer; use OCP\IServerContainer;

View File

@ -24,7 +24,7 @@ use OCP\Files\Node;
use OCP\IUser; use OCP\IUser;
use OCP\IGroup; use OCP\IGroup;
class Share implements IShare { class Share implements \OCP\Share\IShare {
/** @var string */ /** @var string */
private $id; private $id;
@ -34,11 +34,11 @@ class Share implements IShare {
private $path; private $path;
/** @var int */ /** @var int */
private $shareType; private $shareType;
/** @var IUser|IGroup|string */ /** @var IUser|IGroup */
private $sharedWith; private $sharedWith;
/** @var IUser|string */ /** @var IUser */
private $sharedBy; private $sharedBy;
/** @var IUser|string */ /** @var IUser */
private $shareOwner; private $shareOwner;
/** @var int */ /** @var int */
private $permissions; private $permissions;
@ -52,16 +52,13 @@ class Share implements IShare {
private $parent; private $parent;
/** @var string */ /** @var string */
private $target; private $target;
/** @var int */ /** @var \DateTime */
private $shareTime; private $shareTime;
/** @var bool */ /** @var bool */
private $mailSend; private $mailSend;
/** /**
* Set the id of the share * @inheritdoc
*
* @param string $id
* @return IShare The modified object
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
@ -69,9 +66,7 @@ class Share implements IShare {
} }
/** /**
* Get the id of the share * @inheritdoc
*
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@ -93,30 +88,22 @@ class Share implements IShare {
} }
/** /**
* Set the path of this share * @inheritdoc
*
* @param Node $path
* @return IShare The modified object
*/ */
public function setPath(Node $path) { public function setNode(Node $path) {
$this->path = $path; $this->path = $path;
return $this; return $this;
} }
/** /**
* Get the path of this share for the current user * @inheritdoc
*
* @return Node
*/ */
public function getPath() { public function getNode() {
return $this->path; return $this->path;
} }
/** /**
* Set the shareType * @inheritdoc
*
* @param int $shareType
* @return IShare The modified object
*/ */
public function setShareType($shareType) { public function setShareType($shareType) {
$this->shareType = $shareType; $this->shareType = $shareType;
@ -124,19 +111,14 @@ class Share implements IShare {
} }
/** /**
* Get the shareType * @inheritdoc
*
* @return int
*/ */
public function getShareType() { public function getShareType() {
return $this->shareType; return $this->shareType;
} }
/** /**
* Set the receiver of this share * @inheritdoc
*
* @param IUser|IGroup|string
* @return IShare The modified object
*/ */
public function setSharedWith($sharedWith) { public function setSharedWith($sharedWith) {
$this->sharedWith = $sharedWith; $this->sharedWith = $sharedWith;
@ -144,19 +126,14 @@ class Share implements IShare {
} }
/** /**
* Get the receiver of this share * @inheritdoc
*
* @return IUser|IGroup|string
*/ */
public function getSharedWith() { public function getSharedWith() {
return $this->sharedWith; return $this->sharedWith;
} }
/** /**
* Set the permissions * @inheritdoc
*
* @param int $permissions
* @return IShare The modified object
*/ */
public function setPermissions($permissions) { public function setPermissions($permissions) {
//TODO checkes //TODO checkes
@ -166,19 +143,14 @@ class Share implements IShare {
} }
/** /**
* Get the share permissions * @inheritdoc
*
* @return int
*/ */
public function getPermissions() { public function getPermissions() {
return $this->permissions; return $this->permissions;
} }
/** /**
* Set the expiration date * @inheritdoc
*
* @param \DateTime $expireDate
* @return IShare The modified object
*/ */
public function setExpirationDate($expireDate) { public function setExpirationDate($expireDate) {
//TODO checks //TODO checks
@ -188,19 +160,14 @@ class Share implements IShare {
} }
/** /**
* Get the share expiration date * @inheritdoc
*
* @return \DateTime
*/ */
public function getExpirationDate() { public function getExpirationDate() {
return $this->expireDate; return $this->expireDate;
} }
/** /**
* Set the sharer of the path * @inheritdoc
*
* @param IUser|string $sharedBy
* @return IShare The modified object
*/ */
public function setSharedBy($sharedBy) { public function setSharedBy($sharedBy) {
//TODO checks //TODO checks
@ -210,9 +177,7 @@ class Share implements IShare {
} }
/** /**
* Get share sharer * @inheritdoc
*
* @return IUser|string
*/ */
public function getSharedBy() { public function getSharedBy() {
//TODO check if set //TODO check if set
@ -220,11 +185,7 @@ class Share implements IShare {
} }
/** /**
* Set the original share owner (who owns the path) * @inheritdoc
*
* @param IUser|string
*
* @return IShare The modified object
*/ */
public function setShareOwner($shareOwner) { public function setShareOwner($shareOwner) {
//TODO checks //TODO checks
@ -234,9 +195,7 @@ class Share implements IShare {
} }
/** /**
* Get the original share owner (who owns the path) * @inheritdoc
*
* @return IUser|string
*/ */
public function getShareOwner() { public function getShareOwner() {
//TODO check if set //TODO check if set
@ -244,33 +203,22 @@ class Share implements IShare {
} }
/** /**
* Set the password * @inheritdoc
*
* @param string $password
*
* @return IShare The modified object
*/ */
public function setPassword($password) { public function setPassword($password) {
//TODO verify
$this->password = $password; $this->password = $password;
return $this; return $this;
} }
/** /**
* Get the password * @inheritdoc
*
* @return string
*/ */
public function getPassword() { public function getPassword() {
return $this->password; return $this->password;
} }
/** /**
* Set the token * @inheritdoc
*
* @param string $token
* @return IShare The modified object
*/ */
public function setToken($token) { public function setToken($token) {
$this->token = $token; $this->token = $token;
@ -278,19 +226,14 @@ class Share implements IShare {
} }
/** /**
* Get the token * @inheritdoc
*
* @return string
*/ */
public function getToken() { public function getToken() {
return $this->token; return $this->token;
} }
/** /**
* Set the parent id of this share * @inheritdoc
*
* @param int $parent
* @return IShare The modified object
*/ */
public function setParent($parent) { public function setParent($parent) {
$this->parent = $parent; $this->parent = $parent;
@ -298,19 +241,14 @@ class Share implements IShare {
} }
/** /**
* Get the parent id of this share * @inheritdoc
*
* @return int
*/ */
public function getParent() { public function getParent() {
return $this->parent; return $this->parent;
} }
/** /**
* Set the target of this share * @inheritdoc
*
* @param string $target
* @return IShare The modified object
*/ */
public function setTarget($target) { public function setTarget($target) {
$this->target = $target; $this->target = $target;
@ -318,39 +256,29 @@ class Share implements IShare {
} }
/** /**
* Get the target of this share * @inheritdoc
*
* @return string
*/ */
public function getTarget() { public function getTarget() {
return $this->target; return $this->target;
} }
/** /**
* Set the time this share was created * @inheritdoc
*
* @param int $shareTime
* @return IShare The modified object
*/ */
public function setShareTime($shareTime) { public function setShareTime(\DateTime $shareTime) {
$this->shareTime = $shareTime; $this->shareTime = $shareTime;
return $this; return $this;
} }
/** /**
* Get the timestamp this share was created * @inheritdoc
*
* @return int
*/ */
public function getSharetime() { public function getShareTime() {
return $this->shareTime; return $this->shareTime;
} }
/** /**
* Set mailSend * @inheritdoc
*
* @param bool $mailSend
* @return IShare The modified object
*/ */
public function setMailSend($mailSend) { public function setMailSend($mailSend) {
$this->mailSend = $mailSend; $this->mailSend = $mailSend;
@ -358,9 +286,7 @@ class Share implements IShare {
} }
/** /**
* Get mailSend * @inheritdoc
*
* @return bool
*/ */
public function getMailSend() { public function getMailSend() {
return $this->mailSend; return $this->mailSend;

View File

@ -504,4 +504,12 @@ interface IServerContainer {
* @since 9.0.0 * @since 9.0.0
*/ */
public function getSystemTagObjectMapper(); public function getSystemTagObjectMapper();
/**
* Returns the share manager
*
* @return \OCP\Share\IManager
* @since 9.0.0
*/
public function getShareManager();
} }

View File

@ -0,0 +1,212 @@
<?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\IUser;
use OC\Share20\Exception\ShareNotFound;
/**
* Interface IManager
*
* @package OCP\Share
* @since 9.0.0
*/
interface IManager {
/**
* Create a Share
*
* @param IShare $share
* @return Share The share object
* @since 9.0.0
*/
public function createShare(IShare $share);
/**
* Update a share
*
* @param IShare $share
* @return IShare The share object
* @since 9.0.0
*/
public function updateShare(IShare $share);
/**
* Delete a share
*
* @param IShare $share
* @throws ShareNotFound
* @since 9.0.0
*/
public function deleteShare(IShare $share);
/**
* Unshare a file as the recipient.
* This can be different from a regular delete for example when one of
* the users in a groups deletes that share. But the provider should
* handle this.
*
* @param IShare $share
* @param IUser $recipient
* @since 9.0.0
*/
public function deleteFromSelf(IShare $share, IUser $recipient);
/**
* Get shares shared by (initiated) by the provided user.
*
* @param IUser $user
* @param int $shareType
* @param \OCP\Files\File|\OCP\Files\Folder $path
* @param bool $reshares
* @param int $limit The maximum number of returned results, -1 for all results
* @param int $offset
* @return IShare[]
* @since 9.0.0
*/
public function getSharesBy(IUser $user, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0);
/**
* Get shares shared with $user.
*
* @param IUser $user
* @param int $shareType
* @param int $limit The maximum number of shares returned, -1 for all
* @param int $offset
* @return IShare[]
* @since 9.0.0
*/
public function getSharedWith(IUser $user, $shareType, $limit = 50, $offset = 0);
/**
* Retrieve a share by the share id
*
* @param string $id
* @return Share
* @throws ShareNotFound
* @since 9.0.0
*/
public function getShareById($id);
/**
* Get the share by token possible with password
*
* @param string $token
* @return Share
* @throws ShareNotFound
* @since 9.0.0
*/
public function getShareByToken($token);
/**
* Verify the password of a public share
*
* @param IShare $share
* @param string $password
* @return bool
* @since 9.0.0
*/
public function checkPassword(IShare $share, $password);
/**
* Instantiates a new share object. This is to be passed to
* createShare.
*
* @return IShare
* @since 9.0.0
*/
public function newShare();
/**
* Is the share API enabled
*
* @return bool
* @since 9.0.0
*/
public function shareApiEnabled();
/**
* Is public link sharing enabled
*
* @return bool
* @since 9.0.0
*/
public function shareApiAllowLinks();
/**
* Is password on public link requires
*
* @return bool
* @since 9.0.0
*/
public function shareApiLinkEnforcePassword();
/**
* Is default expire date enabled
*
* @return bool
* @since 9.0.0
*/
public function shareApiLinkDefaultExpireDate();
/**
* Is default expire date enforced
*`
* @return bool
* @since 9.0.0
*/
public function shareApiLinkDefaultExpireDateEnforced();
/**
* Number of default expire days
*
* @return int
* @since 9.0.0
*/
public function shareApiLinkDefaultExpireDays();
/**
* Allow public upload on link shares
*
* @return bool
* @since 9.0.0
*/
public function shareApiLinkAllowPublicUpload();
/**
* check if user can only share with group members
* @return bool
* @since 9.0.0
*/
public function shareWithGroupMembersOnly();
/**
* Check if sharing is disabled for the given user
*
* @param IUser $user
* @return bool
* @since 9.0.0
*/
public function sharingDisabledForUser(IUser $user);
}

View File

@ -18,7 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
namespace OC\Share20;
namespace OCP\Share;
use OC\Share20\Exception\ProviderException; use OC\Share20\Exception\ProviderException;
use OCP\IServerContainer; use OCP\IServerContainer;
@ -34,6 +35,7 @@ interface IProviderFactory {
/** /**
* IProviderFactory constructor. * IProviderFactory constructor.
* @param IServerContainer $serverContainer * @param IServerContainer $serverContainer
* @since 9.0.0
*/ */
public function __construct(IServerContainer $serverContainer); public function __construct(IServerContainer $serverContainer);
@ -41,6 +43,7 @@ interface IProviderFactory {
* @param string $id * @param string $id
* @return IShareProvider * @return IShareProvider
* @throws ProviderException * @throws ProviderException
* @since 9.0.0
*/ */
public function getProvider($id); public function getProvider($id);
@ -48,6 +51,7 @@ interface IProviderFactory {
* @param int $shareType * @param int $shareType
* @return IShareProvider * @return IShareProvider
* @throws ProviderException * @throws ProviderException
* @since 9.0.0
*/ */
public function getProviderForType($shareType); public function getProviderForType($shareType);
} }

264
lib/public/share/ishare.php Normal file
View File

@ -0,0 +1,264 @@
<?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 internal id of the share.
*
* @return string
* @since 9.0.0
*/
public function getId();
/**
* Get the full share id. This is the <providerid>:<internalid>.
* The full id is unique in the system.
*
* @return string
* @since 9.0.0
*/
public function getFullId();
/**
* Set the node of the file/folder that is shared
*
* @param File|Folder $path
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setNode(Node $path);
/**
* Get the node of the file/folder that is shared
*
* @return File|Folder
* @since 9.0.0
*/
public function getNode();
/**
* 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
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setSharedWith($sharedWith);
/**
* Get the receiver of this share.
*
* @return IUser|IGroup
* @since 9.0.0
*/
public function getSharedWith();
/**
* Set the permissions.
* See \OCP\Constants::PERMISSION_*
*
* @param int $permissions
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setPermissions($permissions);
/**
* Get the share permissions
* See \OCP\Constants::PERMISSION_*
*
* @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 expiration date
*
* @return \DateTime
* @since 9.0.0
*/
public function getExpirationDate();
/**
* Set the sharer of the path.
*
* @param IUser $sharedBy
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setSharedBy($sharedBy);
/**
* Get share sharer
*
* @return IUser
* @since 9.0.0
*/
public function getSharedBy();
/**
* Set the original share owner (who owns the path that is shared)
*
* @param IUser
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setShareOwner($shareOwner);
/**
* Get the original share owner (who owns the path that is shared)
*
* @return IUser
* @since 9.0.0
*/
public function getShareOwner();
/**
* Set the password for this share.
* When the share is passed to the share manager to be created
* or updated the password will be hashed.
*
* @param string $password
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setPassword($password);
/**
* Get the password of this share.
* If this share is obtained via a shareprovider the password is
* hashed.
*
* @return string
* @since 9.0.0
*/
public function getPassword();
/**
* Set the public link token.
*
* @param string $token
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setToken($token);
/**
* Get the public link token.
*
* @return string
* @since 9.0.0
*/
public function getToken();
/**
* Set the target path of this share relative to the recipients user folder.
*
* @param string $target
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setTarget($target);
/**
* Get the target path of this share relative to the recipients user folder.
*
* @return string
* @since 9.0.0
*/
public function getTarget();
/**
* Set the time this share was created
*
* @param \DateTime $shareTime
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setShareTime(\DateTime $shareTime);
/**
* Get the timestamp this share was created
*
* @return \DateTime
* @since 9.0.0
*/
public function getShareTime();
/**
* Set if the recipient is informed by mail about the share.
*
* @param bool $mailSend
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setMailSend($mailSend);
/**
* Get if the recipient informed by mail about the share.
*
* @return bool
* @since 9.0.0
*/
public function getMailSend();
}

View File

@ -18,53 +18,65 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
namespace OC\Share20;
namespace OCP\Share;
use OC\Share20\Exception\ShareNotFound; use OC\Share20\Exception\ShareNotFound;
use OC\Share20\Exception\BackendError; use OC\Share20\Exception\BackendError;
use OCP\IUser; use OCP\IUser;
/**
* Interface IShareProvider
*
* @package OCP\Share
* @since 9.0.0
*/
interface IShareProvider { interface IShareProvider {
/** /**
* Return the identifier of this provider. * Return the identifier of this provider.
* *
* @return string Containing only [a-zA-Z0-9] * @return string Containing only [a-zA-Z0-9]
* @since 9.0.0
*/ */
public function identifier(); public function identifier();
/** /**
* Share a path * Create a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare The share object * @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 * Update a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @return IShare The share object * @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 * Delete a share
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @throws BackendError * @since 9.0.0
*/ */
public function delete(IShare $share); public function delete(\OCP\Share\IShare $share);
/** /**
* Unshare a file from self as recipient. * Unshare a file from self as recipient.
* This may require special handling. * This may require special handling. If a user unshares a group
* share from their self then the original group share should still exist.
* *
* @param IShare $share * @param \OCP\Share\IShare $share
* @param IUser $recipient * @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 * Get all shares by the given user
@ -75,7 +87,8 @@ interface IShareProvider {
* @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator * @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 $limit The maximum number of shares to be returned, -1 for all shares
* @param int $offset * @param int $offset
* @return Share[] * @return \OCP\Share\I Share[]
* @since 9.0.0
*/ */
public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset); public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset);
@ -83,24 +96,18 @@ interface IShareProvider {
* Get share by id * Get share by id
* *
* @param int $id * @param int $id
* @return IShare * @return \OCP\Share\IShare
* @throws ShareNotFound * @throws ShareNotFound
* @since 9.0.0
*/ */
public function getShareById($id); public function getShareById($id);
/**
* Get children
*
* @param IShare $parent
* @return IShare[]
*/
public function getChildren(IShare $parent);
/** /**
* Get shares for a given path * Get shares for a given path
* *
* @param \OCP\Files\Node $path * @param \OCP\Files\Node $path
* @return IShare[] * @return \OCP\Share\IShare[]
* @since 9.0.0
*/ */
public function getSharesByPath(\OCP\Files\Node $path); public function getSharesByPath(\OCP\Files\Node $path);
@ -111,7 +118,8 @@ interface IShareProvider {
* @param int $shareType * @param int $shareType
* @param int $limit The max number of entries returned, -1 for all * @param int $limit The max number of entries returned, -1 for all
* @param int $offset * @param int $offset
* @param Share * @return \OCP\Share\IShare[]
* @since 9.0.0
*/ */
public function getSharedWith(IUser $user, $shareType, $limit, $offset); public function getSharedWith(IUser $user, $shareType, $limit, $offset);
@ -119,8 +127,9 @@ interface IShareProvider {
* Get a share by token * Get a share by token
* *
* @param string $token * @param string $token
* @return IShare * @return \OCP\Share\IShare
* @throws ShareNotFound * @throws ShareNotFound
* @since 9.0.0
*/ */
public function getShareByToken($token); public function getShareByToken($token);
} }

View File

@ -139,6 +139,8 @@ class Server extends \Test\TestCase {
['Search', '\OCP\ISearch'], ['Search', '\OCP\ISearch'],
['SecureRandom', '\OC\Security\SecureRandom'], ['SecureRandom', '\OC\Security\SecureRandom'],
['SecureRandom', '\OCP\Security\ISecureRandom'], ['SecureRandom', '\OCP\Security\ISecureRandom'],
['ShareManager', '\OC\Share20\Manager'],
['ShareManager', '\OCP\Share\IManager'],
['SystemConfig', '\OC\SystemConfig'], ['SystemConfig', '\OC\SystemConfig'],
['URLGenerator', '\OC\URLGenerator'], ['URLGenerator', '\OC\URLGenerator'],

View File

@ -172,7 +172,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith()); $this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($ownerPath, $share->getPath()); $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals(null, $share->getExpirationDate());
@ -240,7 +240,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith()); $this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($ownerPath, $share->getPath()); $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals(null, $share->getExpirationDate());
@ -303,7 +303,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('sharedWith', $share->getPassword()); $this->assertEquals('sharedWith', $share->getPassword());
$this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($shareOwner, $share->getShareOwner());
$this->assertEquals($ownerPath, $share->getPath()); $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions()); $this->assertEquals(13, $share->getPermissions());
$this->assertEquals('token', $share->getToken()); $this->assertEquals('token', $share->getToken());
$this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate()); $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
@ -326,7 +326,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $qb->getLastInsertId(); $id = $qb->getLastInsertId();
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share->method('getId')->willReturn($id); $share->method('getId')->willReturn($id);
$provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider')
@ -361,7 +361,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
* @expectedException \OC\Share20\Exception\BackendError * @expectedException \OC\Share20\Exception\BackendError
*/ */
public function testDeleteFails() { public function testDeleteFails() {
$share = $this->getMock('OC\Share20\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share $share
->method('getId') ->method('getId')
->willReturn(42); ->willReturn(42);
@ -510,7 +510,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
['group1', $group1] ['group1', $group1]
])); ]));
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getId')->willReturn($id); $share->method('getId')->willReturn($id);
$children = $this->provider->getChildren($share); $children = $this->provider->getChildren($share);
@ -522,7 +522,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($user1, $children[0]->getSharedWith()); $this->assertEquals($user1, $children[0]->getSharedWith());
$this->assertEquals($user2, $children[0]->getSharedBy()); $this->assertEquals($user2, $children[0]->getSharedBy());
$this->assertEquals($shareOwner, $children[0]->getShareOwner()); $this->assertEquals($shareOwner, $children[0]->getShareOwner());
$this->assertEquals($ownerPath, $children[0]->getPath()); $this->assertEquals($ownerPath, $children[0]->getNode());
$this->assertEquals(2, $children[0]->getPermissions()); $this->assertEquals(2, $children[0]->getPermissions());
$this->assertEquals(null, $children[0]->getToken()); $this->assertEquals(null, $children[0]->getToken());
$this->assertEquals(null, $children[0]->getExpirationDate()); $this->assertEquals(null, $children[0]->getExpirationDate());
@ -533,7 +533,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($group1, $children[1]->getSharedWith()); $this->assertEquals($group1, $children[1]->getSharedWith());
$this->assertEquals($user3, $children[1]->getSharedBy()); $this->assertEquals($user3, $children[1]->getSharedBy());
$this->assertEquals($shareOwner, $children[1]->getShareOwner()); $this->assertEquals($shareOwner, $children[1]->getShareOwner());
$this->assertEquals($ownerPath, $children[1]->getPath()); $this->assertEquals($ownerPath, $children[1]->getNode());
$this->assertEquals(4, $children[1]->getPermissions()); $this->assertEquals(4, $children[1]->getPermissions());
$this->assertEquals(null, $children[1]->getToken()); $this->assertEquals(null, $children[1]->getToken());
$this->assertEquals(null, $children[1]->getExpirationDate()); $this->assertEquals(null, $children[1]->getExpirationDate());
@ -582,7 +582,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWith($sharedWith); $share->setSharedWith($sharedWith);
$share->setSharedBy($sharedBy); $share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner); $share->setShareOwner($shareOwner);
$share->setPath($path); $share->setNode($path);
$share->setPermissions(1); $share->setPermissions(1);
$share->setTarget('/target'); $share->setTarget('/target');
@ -596,8 +596,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame($shareOwner, $share2->getShareOwner()); $this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions()); $this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget()); $this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(time(), $share2->getSharetime()); $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getPath()); $this->assertSame($path, $share2->getNode());
} }
public function testCreateGroupShare() { public function testCreateGroupShare() {
@ -645,7 +645,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWith($sharedWith); $share->setSharedWith($sharedWith);
$share->setSharedBy($sharedBy); $share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner); $share->setShareOwner($shareOwner);
$share->setPath($path); $share->setNode($path);
$share->setPermissions(1); $share->setPermissions(1);
$share->setTarget('/target'); $share->setTarget('/target');
@ -659,8 +659,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame($shareOwner, $share2->getShareOwner()); $this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions()); $this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget()); $this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(time(), $share2->getSharetime()); $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getPath()); $this->assertSame($path, $share2->getNode());
} }
public function testCreateLinkShare() { public function testCreateLinkShare() {
@ -701,7 +701,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK); $share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$share->setSharedBy($sharedBy); $share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner); $share->setShareOwner($shareOwner);
$share->setPath($path); $share->setNode($path);
$share->setPermissions(1); $share->setPermissions(1);
$share->setPassword('password'); $share->setPassword('password');
$share->setToken('token'); $share->setToken('token');
@ -718,8 +718,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame($shareOwner, $share2->getShareOwner()); $this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions()); $this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget()); $this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(time(), $share2->getSharetime()); $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getPath()); $this->assertSame($path, $share2->getNode());
$this->assertSame('password', $share2->getPassword()); $this->assertSame('password', $share2->getPassword());
$this->assertSame('token', $share2->getToken()); $this->assertSame('token', $share2->getToken());
$this->assertEquals($expireDate, $share2->getExpirationDate()); $this->assertEquals($expireDate, $share2->getExpirationDate());
@ -1518,7 +1518,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWith($users['user3']); $share->setSharedWith($users['user3']);
$share->setSharedBy($users['user4']); $share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']); $share->setShareOwner($users['user5']);
$share->setPath($file2); $share->setNode($file2);
$share->setPermissions(1); $share->setPermissions(1);
$share2 = $this->provider->update($share); $share2 = $this->provider->update($share);
@ -1567,7 +1567,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setPassword('password'); $share->setPassword('password');
$share->setSharedBy($users['user4']); $share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']); $share->setShareOwner($users['user5']);
$share->setPath($file2); $share->setNode($file2);
$share->setPermissions(1); $share->setPermissions(1);
$share2 = $this->provider->update($share); $share2 = $this->provider->update($share);
@ -1616,7 +1616,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setPassword(null); $share->setPassword(null);
$share->setSharedBy($users['user4']); $share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']); $share->setShareOwner($users['user5']);
$share->setPath($file2); $share->setNode($file2);
$share->setPermissions(1); $share->setPermissions(1);
$share2 = $this->provider->update($share); $share2 = $this->provider->update($share);
@ -1678,7 +1678,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWith($groups['group0']); $share->setSharedWith($groups['group0']);
$share->setSharedBy($users['user4']); $share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']); $share->setShareOwner($users['user5']);
$share->setPath($file2); $share->setNode($file2);
$share->setPermissions(1); $share->setPermissions(1);
$share2 = $this->provider->update($share); $share2 = $this->provider->update($share);
@ -1747,7 +1747,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->setSharedWith($groups['group0']); $share->setSharedWith($groups['group0']);
$share->setSharedBy($users['user4']); $share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']); $share->setShareOwner($users['user5']);
$share->setPath($file2); $share->setNode($file2);
$share->setPermissions(1); $share->setPermissions(1);
$share2 = $this->provider->update($share); $share2 = $this->provider->update($share);

View File

@ -20,8 +20,8 @@
*/ */
namespace Test\Share20; namespace Test\Share20;
use OC\Share20\IProviderFactory; use OCP\Share\IProviderFactory;
use OC\Share20\IShare; use OCP\Share\IShare;
use OC\Share20\Manager; use OC\Share20\Manager;
use OC\Share20\Exception; use OC\Share20\Exception;
@ -29,7 +29,7 @@ use OC\Share20\Share;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
use OCP\IConfig; use OCP\IConfig;
use OC\Share20\IShareProvider; use OCP\Share\IShareProvider;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Security\IHasher; use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountManager;
@ -102,7 +102,9 @@ class ManagerTest extends \Test\TestCase {
$this->factory $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->defaultProvider->method('identifier')->willReturn('default');
$this->factory->setProvider($this->defaultProvider); $this->factory->setProvider($this->defaultProvider);
@ -130,7 +132,7 @@ class ManagerTest extends \Test\TestCase {
* @expectedException \OC\Share20\Exception\ShareNotFound * @expectedException \OC\Share20\Exception\ShareNotFound
*/ */
public function testDeleteNoShareId() { public function testDeleteNoShareId() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share $share
->expects($this->once()) ->expects($this->once())
@ -170,14 +172,14 @@ class ManagerTest extends \Test\TestCase {
$path = $this->getMock('\OCP\Files\File'); $path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1); $path->method('getId')->willReturn(1);
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->manager->newShare();
$share->method('getId')->willReturn(42); $share->setId(42)
$share->method('getFullId')->willReturn('prov:42'); ->setProviderId('prov')
$share->method('getShareType')->willReturn($shareType); ->setShareType($shareType)
$share->method('getSharedWith')->willReturn($sharedWith); ->setSharedWith($sharedWith)
$share->method('getSharedBy')->willReturn($sharedBy); ->setSharedBy($sharedBy)
$share->method('getPath')->willReturn($path); ->setNode($path)
$share->method('getTarget')->willReturn('myTarget'); ->setTarget('myTarget');
$manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share); $manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share);
$manager->expects($this->once())->method('deleteChildren')->with($share); $manager->expects($this->once())->method('deleteChildren')->with($share);
@ -261,33 +263,33 @@ class ManagerTest extends \Test\TestCase {
$path = $this->getMock('\OCP\Files\File'); $path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1); $path->method('getId')->willReturn(1);
$share1 = $this->getMock('\OC\Share20\IShare'); $share1 = $this->manager->newShare();
$share1->method('getId')->willReturn(42); $share1->setId(42)
$share1->method('getFullId')->willReturn('prov:42'); ->setProviderId('prov')
$share1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); ->setShareType(\OCP\Share::SHARE_TYPE_USER)
$share1->method('getSharedWith')->willReturn($sharedWith1); ->setSharedWith($sharedWith1)
$share1->method('getSharedBy')->willReturn($sharedBy1); ->setSharedBy($sharedBy1)
$share1->method('getPath')->willReturn($path); ->setNode($path)
$share1->method('getTarget')->willReturn('myTarget1'); ->setTarget('myTarget1');
$share2 = $this->getMock('\OC\Share20\IShare'); $share2 = $this->manager->newShare();
$share2->method('getId')->willReturn(43); $share2->setId(43)
$share2->method('getFullId')->willReturn('prov:43'); ->setProviderId('prov')
$share2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
$share2->method('getSharedWith')->willReturn($sharedWith2); ->setSharedWith($sharedWith2)
$share2->method('getSharedBy')->willReturn($sharedBy2); ->setSharedBy($sharedBy2)
$share2->method('getPath')->willReturn($path); ->setNode($path)
$share2->method('getTarget')->willReturn('myTarget2'); ->setTarget('myTarget2')
$share2->method('getParent')->willReturn(42); ->setParent(42);
$share3 = $this->getMock('\OC\Share20\IShare'); $share3 = $this->manager->newShare();
$share3->method('getId')->willReturn(44); $share3->setId(44)
$share3->method('getFullId')->willReturn('prov:44'); ->setProviderId('prov')
$share3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
$share3->method('getSharedBy')->willReturn($sharedBy3); ->setSharedBy($sharedBy3)
$share3->method('getPath')->willReturn($path); ->setNode($path)
$share3->method('getTarget')->willReturn('myTarget3'); ->setTarget('myTarget3')
$share3->method('getParent')->willReturn(43); ->setParent(43);
$manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share1); $manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share1);
@ -383,14 +385,14 @@ class ManagerTest extends \Test\TestCase {
->setMethods(['deleteShare']) ->setMethods(['deleteShare'])
->getMock(); ->getMock();
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $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); $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); $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); $child3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$shares = [ $shares = [
@ -419,7 +421,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testGetShareById() { public function testGetShareById() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$this->defaultProvider $this->defaultProvider
->expects($this->once()) ->expects($this->once())
@ -487,13 +489,13 @@ class ManagerTest extends \Test\TestCase {
public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner,
$permissions, $expireDate = null, $password = null) { $permissions, $expireDate = null, $password = null) {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getShareType')->willReturn($type); $share->method('getShareType')->willReturn($type);
$share->method('getSharedWith')->willReturn($sharedWith); $share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy); $share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getSharedOwner')->willReturn($shareOwner); $share->method('getSharedOwner')->willReturn($shareOwner);
$share->method('getPath')->willReturn($path); $share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions); $share->method('getPermissions')->willReturn($permissions);
$share->method('getExpirationDate')->willReturn($expireDate); $share->method('getExpirationDate')->willReturn($expireDate);
$share->method('getPassword')->willReturn($password); $share->method('getPassword')->willReturn($password);
@ -728,7 +730,7 @@ class ManagerTest extends \Test\TestCase {
$share->setSharedBy($sharedBy)->setSharedWith($sharedWith); $share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setPath($path); $share->setNode($path);
$this->groupManager $this->groupManager
->method('getUserGroupIds') ->method('getUserGroupIds')
@ -758,16 +760,16 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Path already shared with this user * @expectedExceptionMessage Path already shared with this user
*/ */
public function testUserCreateChecksIdenticalShareExists() { public function testUserCreateChecksIdenticalShareExists() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share2 = new \OC\Share20\Share(); $share2 = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith)->setPath($path) $share->setSharedWith($sharedWith)->setNode($path)
->setProviderId('foo')->setId('bar'); ->setProviderId('foo')->setId('bar');
$share2->setSharedWith($sharedWith)->setPath($path) $share2->setSharedWith($sharedWith)->setNode($path)
->setProviderId('foo')->setId('baz'); ->setProviderId('foo')->setId('baz');
$this->defaultProvider $this->defaultProvider
@ -783,14 +785,14 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Path already shared with this user * @expectedExceptionMessage Path already shared with this user
*/ */
public function testUserCreateChecksIdenticalPathSharedViaGroup() { public function testUserCreateChecksIdenticalPathSharedViaGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser'); $sharedWith = $this->getMock('\OCP\IUser');
$owner = $this->getMock('\OCP\IUser'); $owner = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith) $share->setSharedWith($sharedWith)
->setPath($path) ->setNode($path)
->setShareOwner($owner) ->setShareOwner($owner)
->setProviderId('foo') ->setProviderId('foo')
->setId('bar'); ->setId('bar');
@ -823,7 +825,7 @@ class ManagerTest extends \Test\TestCase {
$owner = $this->getMock('\OCP\IUser'); $owner = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith) $share->setSharedWith($sharedWith)
->setPath($path) ->setNode($path)
->setShareOwner($owner) ->setShareOwner($owner)
->setProviderId('foo') ->setProviderId('foo')
->setId('bar'); ->setId('bar');
@ -882,7 +884,7 @@ class ManagerTest extends \Test\TestCase {
$sharedWith->method('inGroup')->with($sharedBy)->willReturn(true); $sharedWith->method('inGroup')->with($sharedBy)->willReturn(true);
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setPath($path); $share->setNode($path);
$this->defaultProvider->method('getSharesByPath') $this->defaultProvider->method('getSharesByPath')
->with($path) ->with($path)
@ -902,12 +904,12 @@ class ManagerTest extends \Test\TestCase {
* @expectedExceptionMessage Path already shared with this group * @expectedExceptionMessage Path already shared with this group
*/ */
public function testGroupCreateChecksPathAlreadySharedWithSameGroup() { public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IGroup'); $sharedWith = $this->getMock('\OCP\IGroup');
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith) $share->setSharedWith($sharedWith)
->setPath($path) ->setNode($path)
->setProviderId('foo') ->setProviderId('foo')
->setId('bar'); ->setId('bar');
@ -930,7 +932,7 @@ class ManagerTest extends \Test\TestCase {
$share->setSharedWith($sharedWith); $share->setSharedWith($sharedWith);
$path = $this->getMock('\OCP\Files\Node'); $path = $this->getMock('\OCP\Files\Node');
$share->setPath($path); $share->setNode($path);
$share2 = new \OC\Share20\Share(); $share2 = new \OC\Share20\Share();
$sharedWith2 = $this->getMock('\OCP\IGroup'); $sharedWith2 = $this->getMock('\OCP\IGroup');
@ -1143,7 +1145,7 @@ class ManagerTest extends \Test\TestCase {
->with($user) ->with($user)
->willReturn($groupIds); ->willReturn($groupIds);
$res = $this->manager->isSharingDisabledForUser($user); $res = $this->manager->sharingDisabledForUser($user);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
@ -1176,13 +1178,13 @@ class ManagerTest extends \Test\TestCase {
])); ]));
$manager = $this->createManagerMock() $manager = $this->createManagerMock()
->setMethods(['isSharingDisabledForUser']) ->setMethods(['sharingDisabledForUser'])
->getMock(); ->getMock();
$manager->method('isSharingDisabledForUser')->willReturn($disabledForUser); $manager->method('sharingDisabledForUser')->willReturn($disabledForUser);
$user = $this->getMock('\OCP\IUser'); $user = $this->getMock('\OCP\IUser');
$share = new \OC\Share20\Share(); $share = $this->manager->newShare();
$share->setSharedBy($user); $share->setSharedBy($user);
$res = $this->invokePrivate($manager, 'canShare', [$share]); $res = $this->invokePrivate($manager, 'canShare', [$share]);
@ -1332,7 +1334,7 @@ class ManagerTest extends \Test\TestCase {
$share = new \OC\Share20\Share(); $share = new \OC\Share20\Share();
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK) $share->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPath($path) ->setNode($path)
->setSharedBy($sharedBy) ->setSharedBy($sharedBy)
->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setExpirationDate($date) ->setExpirationDate($date)
@ -1487,7 +1489,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testGetShareByToken() { public function testGetShareByToken() {
$factory = $this->getMock('\OC\Share20\IProviderFactory'); $factory = $this->getMock('\OCP\Share\IProviderFactory');
$manager = new Manager( $manager = new Manager(
$this->logger, $this->logger,
@ -1500,7 +1502,7 @@ class ManagerTest extends \Test\TestCase {
$factory $factory
); );
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$factory->expects($this->once()) $factory->expects($this->once())
->method('getProviderForType') ->method('getProviderForType')
@ -1517,13 +1519,13 @@ class ManagerTest extends \Test\TestCase {
} }
public function testCheckPasswordNoLinkShare() { public function testCheckPasswordNoLinkShare() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
$this->assertFalse($this->manager->checkPassword($share, 'password')); $this->assertFalse($this->manager->checkPassword($share, 'password'));
} }
public function testCheckPasswordNoPassword() { public function testCheckPasswordNoPassword() {
$share = $this->getMock('\OC\Share20\IShare'); $share = $this->getMock('\OCP\Share\IShare');
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$this->assertFalse($this->manager->checkPassword($share, 'password')); $this->assertFalse($this->manager->checkPassword($share, 'password'));
@ -1532,7 +1534,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testCheckPasswordInvalidPassword() { 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('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$share->method('getPassword')->willReturn('password'); $share->method('getPassword')->willReturn('password');
@ -1542,7 +1544,7 @@ class ManagerTest extends \Test\TestCase {
} }
public function testCheckPasswordValidPassword() { 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('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$share->method('getPassword')->willReturn('passwordHash'); $share->method('getPassword')->willReturn('passwordHash');
@ -1774,7 +1776,7 @@ class ManagerTest extends \Test\TestCase {
->setShareOwner($user) ->setShareOwner($user)
->setPassword('password') ->setPassword('password')
->setExpirationDate($tomorrow) ->setExpirationDate($tomorrow)
->setPath($file); ->setNode($file);
$this->defaultProvider->expects($this->once()) $this->defaultProvider->expects($this->once())
->method('update') ->method('update')