2015-10-30 15:09:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, 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\IAppConfig;
|
|
|
|
use OCP\ILogger;
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
use OC\Share20\Exception\ShareNotFound;
|
2015-10-30 15:09:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is the communication hub for all sharing related operations.
|
|
|
|
*/
|
|
|
|
class Manager {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IShareProvider[]
|
|
|
|
*/
|
2015-10-30 15:10:08 +03:00
|
|
|
private $defaultProvider;
|
2015-10-30 15:09:07 +03:00
|
|
|
|
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
|
|
|
/** @var IAppConfig */
|
|
|
|
private $appConfig;
|
|
|
|
|
2015-11-24 11:58:37 +03:00
|
|
|
/**
|
|
|
|
* Manager constructor.
|
|
|
|
*
|
|
|
|
* @param ILogger $logger
|
|
|
|
* @param IAppConfig $appConfig
|
|
|
|
* @param IShareProvider $defaultProvider
|
|
|
|
*/
|
2015-11-23 16:06:25 +03:00
|
|
|
public function __construct(
|
|
|
|
ILogger $logger,
|
|
|
|
IAppConfig $appConfig,
|
|
|
|
IShareProvider $defaultProvider
|
|
|
|
) {
|
2015-10-30 15:09:07 +03:00
|
|
|
$this->logger = $logger;
|
|
|
|
$this->appConfig = $appConfig;
|
|
|
|
|
|
|
|
// TEMP SOLUTION JUST TO GET STARTED
|
2015-10-30 15:10:08 +03:00
|
|
|
$this->defaultProvider = $defaultProvider;
|
2015-10-30 15:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Share a path
|
2015-11-24 11:58:37 +03:00
|
|
|
*
|
2015-10-30 15:09:07 +03:00
|
|
|
* @param Share $share
|
|
|
|
* @return Share The share object
|
|
|
|
*/
|
|
|
|
public function createShare(Share $share) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a share
|
|
|
|
*
|
|
|
|
* @param Share $share
|
|
|
|
* @return Share The share object
|
|
|
|
*/
|
|
|
|
public function updateShare(Share $share) {
|
|
|
|
}
|
|
|
|
|
2015-11-10 16:14:49 +03:00
|
|
|
/**
|
|
|
|
* Delete all the children of this share
|
|
|
|
*
|
|
|
|
* @param IShare $share
|
|
|
|
* @return IShare[] List of deleted shares
|
|
|
|
*/
|
|
|
|
protected function deleteChildren(IShare $share) {
|
|
|
|
$deletedShares = [];
|
|
|
|
foreach($this->defaultProvider->getChildren($share) as $child) {
|
|
|
|
$deletedChildren = $this->deleteChildren($child);
|
|
|
|
$deletedShares = array_merge($deletedShares, $deletedChildren);
|
|
|
|
|
|
|
|
$this->defaultProvider->delete($child);
|
|
|
|
$deletedShares[] = $child;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $deletedShares;
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:09:07 +03:00
|
|
|
/**
|
|
|
|
* Delete a share
|
|
|
|
*
|
2015-11-23 16:06:25 +03:00
|
|
|
* @param IShare $share
|
2015-10-30 15:10:08 +03:00
|
|
|
* @throws ShareNotFound
|
|
|
|
* @throws \OC\Share20\Exception\BackendError
|
2015-10-30 15:09:07 +03:00
|
|
|
*/
|
2015-10-30 15:10:08 +03:00
|
|
|
public function deleteShare(IShare $share) {
|
2015-11-10 16:14:49 +03:00
|
|
|
// Just to make sure we have all the info
|
|
|
|
$share = $this->getShareById($share->getId());
|
|
|
|
|
2015-11-23 16:06:25 +03:00
|
|
|
$formatHookParams = function(IShare $share) {
|
2015-11-10 16:14:49 +03:00
|
|
|
// Prepare hook
|
|
|
|
$shareType = $share->getShareType();
|
|
|
|
$sharedWith = '';
|
|
|
|
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
|
|
|
$sharedWith = $share->getSharedWith()->getUID();
|
|
|
|
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
|
|
|
$sharedWith = $share->getSharedWith()->getGID();
|
|
|
|
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
|
|
|
|
$sharedWith = $share->getSharedWith();
|
|
|
|
}
|
|
|
|
|
|
|
|
$hookParams = [
|
|
|
|
'id' => $share->getId(),
|
|
|
|
'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
|
|
|
|
'itemSource' => $share->getPath()->getId(),
|
|
|
|
'shareType' => $shareType,
|
|
|
|
'shareWith' => $sharedWith,
|
|
|
|
'itemparent' => $share->getParent(),
|
|
|
|
'uidOwner' => $share->getSharedBy()->getUID(),
|
|
|
|
'fileSource' => $share->getPath()->getId(),
|
|
|
|
'fileTarget' => $share->getTarget()
|
|
|
|
];
|
|
|
|
return $hookParams;
|
|
|
|
};
|
|
|
|
|
|
|
|
$hookParams = $formatHookParams($share);
|
|
|
|
|
|
|
|
// Emit pre-hook
|
|
|
|
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);
|
|
|
|
|
|
|
|
// Get all children and delete them as well
|
|
|
|
$deletedShares = $this->deleteChildren($share);
|
|
|
|
|
|
|
|
// Do the actual delete
|
2015-10-30 15:10:08 +03:00
|
|
|
$this->defaultProvider->delete($share);
|
2015-11-10 16:14:49 +03:00
|
|
|
|
|
|
|
// All the deleted shares caused by this delete
|
|
|
|
$deletedShares[] = $share;
|
|
|
|
|
|
|
|
//Format hook info
|
|
|
|
$formattedDeletedShares = array_map(function($share) use ($formatHookParams) {
|
|
|
|
return $formatHookParams($share);
|
|
|
|
}, $deletedShares);
|
|
|
|
|
|
|
|
$hookParams['deletedShares'] = $formattedDeletedShares;
|
|
|
|
|
|
|
|
// Emit post hook
|
|
|
|
\OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams);
|
2015-10-30 15:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve all shares by the current user
|
|
|
|
*
|
|
|
|
* @param int $page
|
|
|
|
* @param int $perPage
|
|
|
|
* @return Share[]
|
|
|
|
*/
|
|
|
|
public function getShares($page=0, $perPage=50) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a share by the share id
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return Share
|
|
|
|
*
|
2015-10-30 15:10:08 +03:00
|
|
|
* @throws ShareNotFound
|
2015-10-30 15:09:07 +03:00
|
|
|
*/
|
|
|
|
public function getShareById($id) {
|
2015-11-10 16:14:49 +03:00
|
|
|
if ($id === null) {
|
|
|
|
throw new ShareNotFound();
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:10:08 +03:00
|
|
|
$share = $this->defaultProvider->getShareById($id);
|
|
|
|
|
|
|
|
return $share;
|
2015-10-30 15:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the shares for a given path
|
|
|
|
*
|
|
|
|
* @param \OCP\Files\Node $path
|
|
|
|
* @param int $page
|
|
|
|
* @param int $perPage
|
|
|
|
*
|
|
|
|
* @return Share[]
|
|
|
|
*/
|
|
|
|
public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all shares that are shared with the current user
|
|
|
|
*
|
|
|
|
* @param int $shareType
|
|
|
|
* @param int $page
|
|
|
|
* @param int $perPage
|
|
|
|
*
|
|
|
|
* @return Share[]
|
|
|
|
*/
|
|
|
|
public function getSharedWithMe($shareType = null, $page=0, $perPage=50) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the share by token possible with password
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @param string $password
|
|
|
|
*
|
|
|
|
* @return Share
|
|
|
|
*
|
2015-11-23 16:06:25 +03:00
|
|
|
* @throws ShareNotFound
|
2015-10-30 15:09:07 +03:00
|
|
|
*/
|
|
|
|
public function getShareByToken($token, $password=null) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get access list to a path. This means
|
|
|
|
* all the users and groups that can access a given path.
|
|
|
|
*
|
|
|
|
* Consider:
|
|
|
|
* -root
|
|
|
|
* |-folder1
|
|
|
|
* |-folder2
|
|
|
|
* |-fileA
|
|
|
|
*
|
|
|
|
* fileA is shared with user1
|
|
|
|
* folder2 is shared with group2
|
|
|
|
* folder1 is shared with user2
|
|
|
|
*
|
|
|
|
* Then the access list will to '/folder1/folder2/fileA' is:
|
|
|
|
* [
|
|
|
|
* 'users' => ['user1', 'user2'],
|
|
|
|
* 'groups' => ['group2']
|
|
|
|
* ]
|
|
|
|
*
|
|
|
|
* This is required for encryption
|
|
|
|
*
|
|
|
|
* @param \OCP\Files\Node $path
|
|
|
|
*/
|
|
|
|
public function getAccessList(\OCP\Files\Node $path) {
|
|
|
|
}
|
|
|
|
}
|