summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-11-02 11:04:33 +0100
committerGitHub <noreply@github.com>2016-11-02 11:04:33 +0100
commit7da3ba3f91f561da664fc601b29cd7948f876f3f (patch)
tree8e320070d69622432fdf8ab641b36b160a901533 /lib
parent42b0a0d2afe95b974545436e112a1d97edaeeb1a (diff)
parentf2b2b8d8940b2487d7f9f3a3a304a6a95d145fd2 (diff)
downloadnextcloud-server-7da3ba3f91f561da664fc601b29cd7948f876f3f.tar.gz
nextcloud-server-7da3ba3f91f561da664fc601b29cd7948f876f3f.zip
Merge pull request #657 from nextcloud/share-by-mail
New share provider: Share by mail
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share/Constants.php4
-rw-r--r--lib/private/Share20/Manager.php38
-rw-r--r--lib/private/Share20/ProviderFactory.php40
-rw-r--r--lib/public/Share/IManager.php8
4 files changed, 88 insertions, 2 deletions
diff --git a/lib/private/Share/Constants.php b/lib/private/Share/Constants.php
index 13a5a044e8a..f13f83f8ba9 100644
--- a/lib/private/Share/Constants.php
+++ b/lib/private/Share/Constants.php
@@ -29,9 +29,9 @@ class Constants {
const SHARE_TYPE_USER = 0;
const SHARE_TYPE_GROUP = 1;
const SHARE_TYPE_LINK = 3;
- const SHARE_TYPE_EMAIL = 4; // ToDo Check if it is still in use otherwise remove it
+ const SHARE_TYPE_EMAIL = 4;
const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it
- const SHARE_TYPE_REMOTE = 6; // ToDo Check if it is still in use otherwise remove it
+ const SHARE_TYPE_REMOTE = 6;
const FORMAT_NONE = -1;
const FORMAT_STATUSES = -2;
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 838650ada15..0c49d0b6490 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -30,6 +30,7 @@ namespace OC\Share20;
use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\MoveableMount;
use OC\HintException;
+use OC\Share20\Exception\ProviderException;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -185,6 +186,10 @@ class Manager implements IManager {
if ($share->getSharedWith() === null) {
throw new \InvalidArgumentException('SharedWith should not be empty');
}
+ } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
+ if ($share->getSharedWith() === null) {
+ throw new \InvalidArgumentException('SharedWith should not be empty');
+ }
} else {
// We can't handle other types yet
throw new \InvalidArgumentException('unkown share type');
@@ -580,6 +585,16 @@ class Manager implements IManager {
if ($share->getPassword() !== null) {
$share->setPassword($this->hasher->hash($share->getPassword()));
}
+ } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
+ $this->linkCreateChecks($share);
+ $share->setToken(
+ $this->secureRandom->generate(
+ \OC\Share\Constants::TOKEN_LENGTH,
+ \OCP\Security\ISecureRandom::CHAR_LOWER.
+ \OCP\Security\ISecureRandom::CHAR_UPPER.
+ \OCP\Security\ISecureRandom::CHAR_DIGITS
+ )
+ );
}
// Cannot share with the owner
@@ -1034,6 +1049,16 @@ class Manager implements IManager {
// If it is not a link share try to fetch a federated share by token
if ($share === null) {
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE);
+ try {
+ $share = $provider->getShareByToken($token);
+ } catch (ShareNotFound $e) {
+ $share = null;
+ }
+ }
+
+ // If it is not a link share try to fetch a federated share by token
+ if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
+ $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL);
$share = $provider->getShareByToken($token);
}
@@ -1277,4 +1302,17 @@ class Manager implements IManager {
return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
}
+ /**
+ * @inheritdoc
+ */
+ public function shareProviderExists($shareType) {
+ try {
+ $this->factory->getProviderForType($shareType);
+ } catch (ProviderException $e) {
+ return false;
+ }
+
+ return true;
+ }
+
}
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index 5cdc9a51a22..457cf117c69 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -28,6 +28,7 @@ use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
+use OCA\ShareByMail\ShareByMailProvider;
use OCP\Share\IProviderFactory;
use OC\Share20\Exception\ProviderException;
use OCP\IServerContainer;
@@ -45,6 +46,8 @@ class ProviderFactory implements IProviderFactory {
private $defaultProvider = null;
/** @var FederatedShareProvider */
private $federatedProvider = null;
+ /** @var ShareByMailProvider */
+ private $shareByMailProvider;
/**
* IProviderFactory constructor.
@@ -126,6 +129,39 @@ class ProviderFactory implements IProviderFactory {
}
/**
+ * Create the federated share provider
+ *
+ * @return FederatedShareProvider
+ */
+ protected function getShareByMailProvider() {
+ if ($this->shareByMailProvider === null) {
+ /*
+ * Check if the app is enabled
+ */
+ $appManager = $this->serverContainer->getAppManager();
+ if (!$appManager->isEnabledForUser('sharebymail')) {
+ return null;
+ }
+
+ $l = $this->serverContainer->getL10N('sharebymail');
+
+ $this->shareByMailProvider = new ShareByMailProvider(
+ $this->serverContainer->getDatabaseConnection(),
+ $this->serverContainer->getSecureRandom(),
+ $this->serverContainer->getUserManager(),
+ $this->serverContainer->getLazyRootFolder(),
+ $l,
+ $this->serverContainer->getLogger(),
+ $this->serverContainer->getMailer(),
+ $this->serverContainer->getURLGenerator()
+ );
+ }
+
+ return $this->shareByMailProvider;
+ }
+
+
+ /**
* @inheritdoc
*/
public function getProvider($id) {
@@ -134,6 +170,8 @@ class ProviderFactory implements IProviderFactory {
$provider = $this->defaultShareProvider();
} else if ($id === 'ocFederatedSharing') {
$provider = $this->federatedShareProvider();
+ } else if ($id = 'ocMailShare') {
+ $provider = $this->getShareByMailProvider();
}
if ($provider === null) {
@@ -155,6 +193,8 @@ class ProviderFactory implements IProviderFactory {
$provider = $this->defaultShareProvider();
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
$provider = $this->federatedShareProvider();
+ } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
+ $provider = $this->getShareByMailProvider();
}
if ($provider === null) {
diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php
index a74ab5fe796..137dc309280 100644
--- a/lib/public/Share/IManager.php
+++ b/lib/public/Share/IManager.php
@@ -286,4 +286,12 @@ interface IManager {
*/
public function outgoingServer2ServerSharesAllowed();
+ /**
+ * Check if a given share provider exists
+ * @param int $shareType
+ * @return bool
+ * @since 9.2.0
+ */
+ public function shareProviderExists($shareType);
+
}