summaryrefslogtreecommitdiffstats
path: root/lib/private/share20
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/share20')
-rw-r--r--lib/private/share20/defaultshareprovider.php16
-rw-r--r--lib/private/share20/ishare.php43
-rw-r--r--lib/private/share20/ishareprovider.php7
-rw-r--r--lib/private/share20/manager.php77
-rw-r--r--lib/private/share20/share.php45
5 files changed, 127 insertions, 61 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index f961bc5202f..60c3c4390fc 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -29,6 +29,11 @@ use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\Files\Node;
+/**
+ * Class DefaultShareProvider
+ *
+ * @package OC\Share20
+ */
class DefaultShareProvider implements IShareProvider {
/** @var IDBConnection */
@@ -76,6 +81,15 @@ class DefaultShareProvider implements IShareProvider {
}
/**
+ * Return the identifier of this provider.
+ *
+ * @return string Containing only [a-zA-Z0-9]
+ */
+ public function identifier() {
+ return 'ocinternal';
+ }
+
+ /**
* Share a path
*
* @param IShare $share
@@ -355,6 +369,8 @@ class DefaultShareProvider implements IShareProvider {
$share->setExpirationDate($expiration);
}
+ $share->setProviderId($this->identifier());
+
return $share;
}
diff --git a/lib/private/share20/ishare.php b/lib/private/share20/ishare.php
index 53cfe76916d..34d1dfa4d3d 100644
--- a/lib/private/share20/ishare.php
+++ b/lib/private/share20/ishare.php
@@ -36,10 +36,33 @@ interface IShare {
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 Share The modified object
+ * @return IShare The modified object
*/
public function setPath(Node $path);
@@ -54,7 +77,7 @@ interface IShare {
* Set the shareType
*
* @param int $shareType
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setShareType($shareType);
@@ -69,7 +92,7 @@ interface IShare {
* Set the receiver of this share
*
* @param IUser|IGroup|string
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setSharedWith($sharedWith);
@@ -84,7 +107,7 @@ interface IShare {
* Set the permissions
*
* @param int $permissions
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setPermissions($permissions);
@@ -99,7 +122,7 @@ interface IShare {
* Set the expiration date
*
* @param \DateTime $expireDate
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setExpirationDate($expireDate);
@@ -114,7 +137,7 @@ interface IShare {
* Set the sharer of the path
*
* @param IUser|string $sharedBy
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setSharedBy($sharedBy);
@@ -130,7 +153,7 @@ interface IShare {
*
* @param IUser|string
*
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setShareOwner($shareOwner);
@@ -146,7 +169,7 @@ interface IShare {
*
* @param string $password
*
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setPassword($password);
@@ -161,7 +184,7 @@ interface IShare {
* Set the token
*
* @param string $token
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setToken($token);
@@ -183,7 +206,7 @@ interface IShare {
* Set the target of this share
*
* @param string $target
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setTarget($target);
diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php
index a7e9c59a972..e3a8e3c55b0 100644
--- a/lib/private/share20/ishareprovider.php
+++ b/lib/private/share20/ishareprovider.php
@@ -34,6 +34,13 @@ interface IShareProvider {
public function shareTypes();
/**
+ * Return the identifier of this provider.
+ *
+ * @return string Containing only [a-zA-Z0-9]
+ */
+ public function identifier();
+
+ /**
* Share a path
*
* @param IShare $share
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index e35b69f0031..0784a53ecc2 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -21,10 +21,12 @@
namespace OC\Share20;
+use OC\Share20\Exception\BackendError;
use OC\Share20\Exception\ProviderException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
+use OCP\Preview\IProvider;
use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
@@ -112,40 +114,45 @@ class Manager {
*/
private function addProviders(array $providers) {
foreach ($providers as $provider) {
- $name = get_class($provider);
+ $id = $provider->identifier();
+ $class = get_class($provider);
if (!($provider instanceof IShareProvider)) {
- throw new ProviderException($name . ' is not an instance of IShareProvider');
+ throw new ProviderException($class . ' is not an instance of IShareProvider');
}
- if (isset($this->providers[$name])) {
- throw new ProviderException($name . ' is already registered');
+ if (isset($this->providers[$id])) {
+ throw new ProviderException($id . ' is already registered');
}
- $this->providers[$name] = $provider;
+ $this->providers[$id] = $provider;
$types = $provider->shareTypes();
if ($types === []) {
- throw new ProviderException('Provider ' . $name . ' must supply share types it can handle');
+ throw new ProviderException('Provider ' . $id . ' must supply share types it can handle');
}
foreach ($types as $type) {
if (isset($this->type2provider[$type])) {
- throw new ProviderException($name . ' tried to register for share type ' . $type . ' but this type is already handled by ' . $this->type2provider[$type]);
+ throw new ProviderException($id . ' tried to register for share type ' . $type . ' but this type is already handled by ' . $this->type2provider[$type]);
}
- $this->type2provider[$type] = $name;
+ $this->type2provider[$type] = $id;
}
}
}
+ /**
+ * Run the factory if this is not done yet
+ *
+ * @throws ProviderException
+ */
private function runFactory() {
if (!empty($this->providers)) {
return;
}
$this->addProviders($this->factory->getProviders());
- $this->factoryDone = true;
}
/**
@@ -188,6 +195,16 @@ class Manager {
}
/**
+ * Convert from a full share id to a tuple (providerId, shareId)
+ *
+ * @param string $id
+ * @return string[]
+ */
+ private function splitFullId($id) {
+ return explode(':', $id, 2);
+ }
+
+ /**
* Verify if a password meets all requirements
*
* @param string $password
@@ -335,7 +352,6 @@ class Manager {
return $expireDate;
}
-
/**
* Check for pre share requirements for user shares
*
@@ -549,6 +565,7 @@ class Manager {
$provider = $this->getProviderForType($share->getShareType());
$share = $provider->create($share);
+ $share->setProviderId($provider->identifier());
// Post share hook
$postHookData = [
@@ -585,16 +602,14 @@ class Manager {
protected function deleteChildren(IShare $share) {
$deletedShares = [];
- $providers = $this->getProviders();
+ $provider = $this->getProviderForType($share->getShareType());
- foreach($providers as $provider) {
- foreach ($provider->getChildren($share) as $child) {
- $deletedChildren = $this->deleteChildren($child);
- $deletedShares = array_merge($deletedShares, $deletedChildren);
+ foreach ($provider->getChildren($share) as $child) {
+ $deletedChildren = $this->deleteChildren($child);
+ $deletedShares = array_merge($deletedShares, $deletedChildren);
- $provider->delete($child);
- $deletedShares[] = $child;
- }
+ $provider->delete($child);
+ $deletedShares[] = $child;
}
return $deletedShares;
@@ -605,11 +620,12 @@ class Manager {
*
* @param IShare $share
* @throws ShareNotFound
- * @throws \OC\Share20\Exception\BackendError
+ * @throws BackendError
+ * @throws ShareNotFound
*/
public function deleteShare(IShare $share) {
// Just to make sure we have all the info
- $share = $this->getShareById($share->getId());
+ $share = $this->getShareById($share->getFullId());
$formatHookParams = function(IShare $share) {
// Prepare hook
@@ -686,24 +702,11 @@ class Manager {
throw new ShareNotFound();
}
- //FIXME ids need to become proper providerid:shareid eventually
-
- $providers = $this->getProviders();
-
- $share = null;
- foreach ($providers as $provider) {
- try {
- $share = $provider->getShareById($id);
- $found = true;
- break;
- } catch (ShareNotFound $e) {
- // Ignore
- }
- }
+ list($providerId, $id) = $this->splitFullId($id);
+ $provider = $this->getProvider($providerId);
- if ($share === null) {
- throw new ShareNotFound();
- }
+ $share = $provider->getShareById($id);
+ $share->setProviderId($provider->identifier());
return $share;
}
diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php
index 2cd685b7963..ee43725d9bc 100644
--- a/lib/private/share20/share.php
+++ b/lib/private/share20/share.php
@@ -28,6 +28,8 @@ class Share implements IShare {
/** @var string */
private $id;
+ /** @var string */
+ private $providerId;
/** @var Node */
private $path;
/** @var int */
@@ -59,7 +61,7 @@ class Share implements IShare {
* Set the id of the share
*
* @param string $id
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setId($id) {
$this->id = $id;
@@ -76,10 +78,25 @@ class Share implements IShare {
}
/**
+ * @inheritdoc
+ */
+ public function getFullId() {
+ return $this->providerId . ':' . $this->id;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setProviderId($id) {
+ $this->providerId = $id;
+ return $this;
+ }
+
+ /**
* Set the path of this share
*
* @param Node $path
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setPath(Node $path) {
$this->path = $path;
@@ -99,7 +116,7 @@ class Share implements IShare {
* Set the shareType
*
* @param int $shareType
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setShareType($shareType) {
$this->shareType = $shareType;
@@ -119,7 +136,7 @@ class Share implements IShare {
* Set the receiver of this share
*
* @param IUser|IGroup|string
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setSharedWith($sharedWith) {
$this->sharedWith = $sharedWith;
@@ -139,7 +156,7 @@ class Share implements IShare {
* Set the permissions
*
* @param int $permissions
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setPermissions($permissions) {
//TODO checkes
@@ -161,7 +178,7 @@ class Share implements IShare {
* Set the expiration date
*
* @param \DateTime $expireDate
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setExpirationDate($expireDate) {
//TODO checks
@@ -183,7 +200,7 @@ class Share implements IShare {
* Set the sharer of the path
*
* @param IUser|string $sharedBy
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setSharedBy($sharedBy) {
//TODO checks
@@ -207,7 +224,7 @@ class Share implements IShare {
*
* @param IUser|string
*
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setShareOwner($shareOwner) {
//TODO checks
@@ -231,7 +248,7 @@ class Share implements IShare {
*
* @param string $password
*
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setPassword($password) {
//TODO verify
@@ -253,7 +270,7 @@ class Share implements IShare {
* Set the token
*
* @param string $token
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setToken($token) {
$this->token = $token;
@@ -273,7 +290,7 @@ class Share implements IShare {
* Set the parent id of this share
*
* @param int $parent
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setParent($parent) {
$this->parent = $parent;
@@ -293,7 +310,7 @@ class Share implements IShare {
* Set the target of this share
*
* @param string $target
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setTarget($target) {
$this->target = $target;
@@ -313,7 +330,7 @@ class Share implements IShare {
* Set the time this share was created
*
* @param int $shareTime
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setShareTime($shareTime) {
$this->shareTime = $shareTime;
@@ -333,7 +350,7 @@ class Share implements IShare {
* Set mailSend
*
* @param bool $mailSend
- * @return Share The modified object
+ * @return IShare The modified object
*/
public function setMailSend($mailSend) {
$this->mailSend = $mailSend;