From 69694012ab0eca1ec1f3dc0d2b10a3b1728b0927 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 17 Mar 2017 18:48:33 -0100 Subject: shares-circles Signed-off-by: Maxence Lange --- lib/private/Share/Constants.php | 1 + lib/private/Share20/Manager.php | 7 ++++- lib/private/Share20/ProviderFactory.php | 54 ++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/private/Share/Constants.php b/lib/private/Share/Constants.php index f13f83f8ba9..1eb5b1e078b 100644 --- a/lib/private/Share/Constants.php +++ b/lib/private/Share/Constants.php @@ -32,6 +32,7 @@ class Constants { 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; + const SHARE_TYPE_CIRCLE = 7; const FORMAT_NONE = -1; const FORMAT_STATUSES = -2; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index acc142f62be..3b565d1ba8c 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -190,9 +190,14 @@ class Manager implements IManager { if ($share->getSharedWith() === null) { throw new \InvalidArgumentException('SharedWith should not be empty'); } + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { + $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); + if ($circle === null) { + throw new \InvalidArgumentException('SharedWith is not a valid circle'); + } } else { // We can't handle other types yet - throw new \InvalidArgumentException('unkown share type'); + throw new \InvalidArgumentException('unknown share type'); } // Verify the initiator of the share is set diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index bbc6f4ffbd3..1a39cfbf337 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -48,9 +48,13 @@ class ProviderFactory implements IProviderFactory { private $federatedProvider = null; /** @var ShareByMailProvider */ private $shareByMailProvider; + /** @var \OCA\Circles\ShareByCircleProvider; + * ShareByCircleProvider */ + private $shareByCircleProvider; /** * IProviderFactory constructor. + * * @param IServerContainer $serverContainer */ public function __construct(IServerContainer $serverContainer) { @@ -164,6 +168,36 @@ class ProviderFactory implements IProviderFactory { } + /** + * Create the circle share provider + * + * @return FederatedShareProvider + */ + protected function getShareByCircleProvider() { + + $appManager = $this->serverContainer->getAppManager(); + if (!$appManager->isEnabledForUser('circles')) { + return null; + } + + + if ($this->shareByCircleProvider === null) { + + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( + $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->getSecureRandom(), + $this->serverContainer->getUserManager(), + $this->serverContainer->getLazyRootFolder(), + $this->serverContainer->getL10N('circles'), + $this->serverContainer->getLogger(), + $this->serverContainer->getURLGenerator() + ); + } + + return $this->shareByCircleProvider; + } + + /** * @inheritdoc */ @@ -175,6 +209,8 @@ class ProviderFactory implements IProviderFactory { $provider = $this->federatedShareProvider(); } else if ($id === 'ocMailShare') { $provider = $this->getShareByMailProvider(); + } else if ($id === 'ocCircleShare') { + $provider = $this->getShareByCircleProvider(); } if ($provider === null) { @@ -190,16 +226,20 @@ class ProviderFactory implements IProviderFactory { public function getProviderForType($shareType) { $provider = null; - if ($shareType === \OCP\Share::SHARE_TYPE_USER || + if ($shareType === \OCP\Share::SHARE_TYPE_USER || $shareType === \OCP\Share::SHARE_TYPE_GROUP || - $shareType === \OCP\Share::SHARE_TYPE_LINK) { + $shareType === \OCP\Share::SHARE_TYPE_LINK + ) { $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(); + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { + $provider = $this->getShareByCircleProvider(); } + if ($provider === null) { throw new ProviderException('No share provider for share type ' . $shareType); } @@ -208,10 +248,16 @@ class ProviderFactory implements IProviderFactory { } public function getAllProviders() { + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; $shareByMail = $this->getShareByMailProvider(); if ($shareByMail !== null) { - return [$this->defaultShareProvider(), $this->federatedShareProvider(), $shareByMail]; + $shares[] = $shareByMail; + } + $shareByCircle = $this->getShareByCircleProvider(); + if ($shareByCircle !== null) { + $shares[] = $shareByCircle; } - return [$this->defaultShareProvider(), $this->federatedShareProvider()]; + + return $shares; } } -- cgit v1.2.3