Browse Source
Initial setup of shareing 2.0 sharemanager and share
Initial setup of shareing 2.0 sharemanager and share
* Added sharemanager class This is the central class where all API calls talk to (OCS/Activity). This in turn talks to the share providers to get the actual sharing done. It uses all ShareObjects * Added share class Simple class to hold all the share properties that is passed around * Added IShareProvider interface Interface that providers os a share have to implement.remotes/origin/exclude_directories_III
3 changed files with 623 additions and 0 deletions
-
94lib/private/share20/ishareprovider.php
-
244lib/private/share20/manager.php
-
285lib/private/share20/share.php
@ -0,0 +1,94 @@ |
|||
<?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\IUser; |
|||
|
|||
interface IShareProvider { |
|||
|
|||
/** |
|||
* Share a path |
|||
* |
|||
* @param Share $share |
|||
* @return Share The share object |
|||
*/ |
|||
public function create(Share $share); |
|||
|
|||
/** |
|||
* Update a share |
|||
* |
|||
* @param Share $share |
|||
* @return Share The share object |
|||
*/ |
|||
public function update(Share $share); |
|||
|
|||
/** |
|||
* Delete a share |
|||
* |
|||
* @param Share $share |
|||
*/ |
|||
public function delete(Share $share); |
|||
|
|||
/** |
|||
* Get all shares by the given user |
|||
* |
|||
* @param IUser $user |
|||
* @param int $shareType |
|||
* @param int $offset |
|||
* @param int $limit |
|||
* @return Share[] |
|||
*/ |
|||
public function getShares(IUser $user, $shareType, $offset, $limit); |
|||
|
|||
/** |
|||
* Get share by id |
|||
* |
|||
* @param int $id |
|||
* @return Share |
|||
*/ |
|||
public function getShareById($id); |
|||
|
|||
/** |
|||
* Get shares for a given path |
|||
* |
|||
* @param \OCP\Files\Node $path |
|||
* @param Share[] |
|||
*/ |
|||
public function getSharesByPath(\OCP\IUser $user, \OCP\Files\Node $path); |
|||
|
|||
/** |
|||
* Get shared with the given user |
|||
* |
|||
* @param IUser $user |
|||
* @param int $shareType |
|||
* @param Share |
|||
*/ |
|||
public function getSharedWithMe(IUser $user, $shareType = null); |
|||
|
|||
/** |
|||
* Get a share by token and if present verify the password |
|||
* |
|||
* @param string $token |
|||
* @param string $password |
|||
* @param Share |
|||
*/ |
|||
public function getShareByToken($token, $password = null); |
|||
} |
|||
@ -0,0 +1,244 @@ |
|||
<?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\IUserManager; |
|||
use OCP\IGroupManager; |
|||
use OCP\IUser; |
|||
use OCP\ILogger; |
|||
use OCP\Files\Folder; |
|||
|
|||
use OC\Share20\Exceptions\ShareNotFoundException; |
|||
use OC\Share20\Exception\PreconditionFailed; |
|||
|
|||
/** |
|||
* This class is the communication hub for all sharing related operations. |
|||
*/ |
|||
class Manager { |
|||
|
|||
/** |
|||
* @var IShareProvider[] |
|||
*/ |
|||
private $shareProviders; |
|||
|
|||
/** |
|||
* @var string[] |
|||
*/ |
|||
private $shareTypeToProviderId; |
|||
|
|||
/** @var IUser */ |
|||
private $currentUser; |
|||
|
|||
/** @var IUserManager */ |
|||
private $userManager; |
|||
|
|||
/** @var IGroupManager */ |
|||
private $groupManager; |
|||
|
|||
/** @var ILogger */ |
|||
private $logger; |
|||
|
|||
/** @var IAppConfig */ |
|||
private $appConfig; |
|||
|
|||
/** @var IFolder */ |
|||
private $userFolder; |
|||
|
|||
public function __construct(IUser $user, |
|||
IUserManager $userManager, |
|||
IGroupManager $groupManager, |
|||
ILogger $logger, |
|||
IAppConfig $appConfig, |
|||
Folder $userFolder, |
|||
IShareProvider $defaultProvider) { |
|||
$this->currentUser = $user; |
|||
$this->userManager = $userManager; |
|||
$this->groupManager = $groupManager; |
|||
$this->logger = $logger; |
|||
$this->appConfig = $appConfig; |
|||
$this->userFolder = $userFolder; |
|||
|
|||
// TEMP SOLUTION JUST TO GET STARTED
|
|||
$this->shareProviders['ocdef'] = $defaultProvider; |
|||
$this->shareTypeToProviderId = [ |
|||
\OCP\Share::SHARE_TYPE_USER => 'ocdef', |
|||
\OCP\Share::SHARE_TYPE_GROUP => 'ocdef', |
|||
\OCP\Share::SHARE_TYPE_LINK => 'ocdef', |
|||
]; |
|||
|
|||
// TODO: Get storage share provider from primary storage
|
|||
} |
|||
|
|||
/** |
|||
* Get a ShareProvider |
|||
* |
|||
* @param string $id |
|||
* @return IShareProvider |
|||
*/ |
|||
private function getShareProvider($id) { |
|||
if (!isset($this->shareProviders[$id])) { |
|||
//Throw exception;
|
|||
} |
|||
|
|||
// Check if we have instanciated this provider yet
|
|||
if (!($this->shareProviders[$id] instanceOf \OC\Share20\IShareProvider)) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
return $this->shareProviders[$id]; |
|||
} |
|||
|
|||
/** |
|||
* Get shareProvider based on shareType |
|||
* |
|||
* @param int $shareType |
|||
* @return IShareProvider |
|||
*/ |
|||
private function getShareProviderByType($shareType) { |
|||
if (!isset($this->shareTypeToProviderId[$shareType])) { |
|||
//Throw exception
|
|||
} |
|||
|
|||
return $this->getShareProvider($this->shareTypeToProviderId[$shareType]); |
|||
} |
|||
|
|||
/** |
|||
* Share a path |
|||
* |
|||
* @param Share $share |
|||
* @return Share The share object |
|||
*/ |
|||
public function createShare(Share $share) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* Update a share |
|||
* |
|||
* @param Share $share |
|||
* @return Share The share object |
|||
*/ |
|||
public function updateShare(Share $share) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* Delete a share |
|||
* |
|||
* @param Share $share |
|||
*/ |
|||
public function deleteShare(Share $share) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* Retrieve all shares by the current user |
|||
* |
|||
* @param int $page |
|||
* @param int $perPage |
|||
* @return Share[] |
|||
*/ |
|||
public function getShares($page=0, $perPage=50) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* Retrieve a share by the share id |
|||
* |
|||
* @param string $id |
|||
* @return Share |
|||
* |
|||
* @throws ShareNotFoundException |
|||
*/ |
|||
public function getShareById($id) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* 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) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* 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) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* Get the share by token possible with password |
|||
* |
|||
* @param string $token |
|||
* @param string $password |
|||
* |
|||
* @return Share |
|||
* |
|||
* @throws ShareNotFoundException |
|||
*/ |
|||
public function getShareByToken($token, $password=null) { |
|||
throw new \Exception(); |
|||
} |
|||
|
|||
/** |
|||
* 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) { |
|||
throw new \Exception(); |
|||
} |
|||
} |
|||
@ -0,0 +1,285 @@ |
|||
<?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\Files\Node; |
|||
use OCP\IUser; |
|||
use OCP\IGroup; |
|||
|
|||
class Share { |
|||
|
|||
/** @var string */ |
|||
private $internalId; |
|||
|
|||
/** @var string */ |
|||
private $providerId; |
|||
|
|||
/** @var Node */ |
|||
private $path; |
|||
|
|||
/** @var int */ |
|||
private $shareType; |
|||
|
|||
/** @var IUser|IGroup|string */ |
|||
private $shareWith; |
|||
|
|||
/** @var IUser|string */ |
|||
private $sharedBy; |
|||
|
|||
/** @var IUser|string */ |
|||
private $shareOwner; |
|||
|
|||
/** @var int */ |
|||
private $permissions; |
|||
|
|||
/** @var \DateTime */ |
|||
private $expireDate; |
|||
|
|||
/** @var string */ |
|||
private $password; |
|||
|
|||
/** |
|||
* Set the id of the ShareProvider |
|||
* Should only be used by the share manager |
|||
* |
|||
* @param string $providerId |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setProviderId($providerId) { |
|||
$this->providerId = $providerId; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the id of the ShareProvider |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getProviderId() { |
|||
return $this->providerId; |
|||
} |
|||
|
|||
/** |
|||
* Set the internal (to the provider) share id |
|||
* Should only be used by the share provider |
|||
* |
|||
* @param string $id |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setInternalId($id) { |
|||
$this->internalId = $id; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the internal (to the provider) share id |
|||
* Should only be used by the share provider |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getInternalId() { |
|||
return $this->internalId; |
|||
} |
|||
|
|||
/** |
|||
* Get the id of the share |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getId() { |
|||
//TODO $id should be set as well as $providerId
|
|||
return $this->providerId . ':' . $this->internalId; |
|||
} |
|||
|
|||
/** |
|||
* Set the path of this share |
|||
* |
|||
* @param Node $path |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setPath(Node $path) { |
|||
$this->path = $path; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the path of this share for the current user |
|||
* |
|||
* @return Node |
|||
*/ |
|||
public function getPath() { |
|||
return $this->path; |
|||
} |
|||
|
|||
/** |
|||
* Set the shareType |
|||
* |
|||
* @param int $shareType |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setShareType($shareType) { |
|||
$this->shareType = $shareType; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the shareType |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function getShareType() { |
|||
return $this->shareType; |
|||
} |
|||
|
|||
/** |
|||
* Set the shareWith |
|||
* |
|||
* @param IUser|IGroup|string |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setShareWith($shareWith) { |
|||
$this->shareWith = $shareWith; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the shareWith |
|||
* |
|||
* @return IUser|IGroup|string |
|||
*/ |
|||
public function getShareWith() { |
|||
return $this->shareWith; |
|||
} |
|||
|
|||
/** |
|||
* Set the permissions |
|||
* |
|||
* @param int $permissions |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setPermissions($permissions) { |
|||
//TODO checkes
|
|||
|
|||
$this->permissions = $permissions; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the share permissions |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function getPermissions() { |
|||
return $this->permissions; |
|||
} |
|||
|
|||
/** |
|||
* Set the expiration date |
|||
* |
|||
* @param \DateTime $expireDate |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setExpirationDate(\DateTime $expireDate) { |
|||
//TODO checks
|
|||
|
|||
$this->expireDate = $expireDate; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the share expiration date |
|||
* |
|||
* @return \DateTime |
|||
*/ |
|||
public function getExpirationDate() { |
|||
return $this->expireDate; |
|||
} |
|||
|
|||
/** |
|||
* Set the sharer of the path |
|||
* |
|||
* @param IUser|string $sharedBy |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setSharedBy($sharedBy) { |
|||
//TODO checks
|
|||
$this->sharedBy = $sharedBy; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get share sharer |
|||
* |
|||
* @return IUser|string |
|||
*/ |
|||
public function getSharedBy() { |
|||
//TODO check if set
|
|||
return $this->sharedBy; |
|||
} |
|||
|
|||
/** |
|||
* Set the original share owner (who owns the path) |
|||
* |
|||
* @param IUser|string |
|||
* |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setShareOwner($shareOwner) { |
|||
//TODO checks
|
|||
|
|||
$this->shareOwner = $shareOwner; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the original share owner (who owns the path) |
|||
* |
|||
* @return IUser|string |
|||
*/ |
|||
public function getShareOwner() { |
|||
//TODO check if set
|
|||
return $this->shareOwner; |
|||
} |
|||
|
|||
/** |
|||
* Set the password |
|||
* |
|||
* @param string $password |
|||
* |
|||
* @return Share The modified object |
|||
*/ |
|||
public function setPassword($password) { |
|||
//TODO verify
|
|||
|
|||
$this->password = $password; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the password |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getPassword($password) { |
|||
return $this->password; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue