diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2018-06-13 14:19:59 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2018-07-11 10:11:44 +0200 |
commit | b23032e4c569f7ba54197171cbb02ed8119b6811 (patch) | |
tree | 882cc64ab6398f33962428d79aa270055a20f6e0 /apps/cloud_federation_api | |
parent | c8631d607ef827f0eb29312faf7b2b808e1a8e7d (diff) | |
download | nextcloud-server-b23032e4c569f7ba54197171cbb02ed8119b6811.tar.gz nextcloud-server-b23032e4c569f7ba54197171cbb02ed8119b6811.zip |
implement federated group shares
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/cloud_federation_api')
-rw-r--r-- | apps/cloud_federation_api/lib/Config.php | 9 | ||||
-rw-r--r-- | apps/cloud_federation_api/lib/Controller/RequestHandlerController.php | 45 |
2 files changed, 41 insertions, 13 deletions
diff --git a/apps/cloud_federation_api/lib/Config.php b/apps/cloud_federation_api/lib/Config.php index 7d42960deaf..2fb842697d4 100644 --- a/apps/cloud_federation_api/lib/Config.php +++ b/apps/cloud_federation_api/lib/Config.php @@ -47,11 +47,14 @@ class Config { * * @param string $resourceType * @return array - * @throws \OCP\Federation\Exceptions\ProviderDoesNotExistsException */ public function getSupportedShareTypes($resourceType) { - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); - return $provider->getSupportedShareTypes(); + try { + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); + return $provider->getSupportedShareTypes(); + } catch (\Exception $e) { + return []; + } } } diff --git a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php index 27dd89f2abe..e7c6c415d3c 100644 --- a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php +++ b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php @@ -35,6 +35,7 @@ use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\Exceptions\ProviderDoesNotExistsException; use OCP\Federation\ICloudIdManager; +use OCP\IGroupManager; use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; @@ -57,6 +58,9 @@ class RequestHandlerController extends Controller { /** @var IUserManager */ private $userManager; + /** @var IGroupManager */ + private $groupManager; + /** @var IURLGenerator */ private $urlGenerator; @@ -76,6 +80,7 @@ class RequestHandlerController extends Controller { IRequest $request, ILogger $logger, IUserManager $userManager, + IGroupManager $groupManager, IURLGenerator $urlGenerator, ICloudFederationProviderManager $cloudFederationProviderManager, Config $config, @@ -86,6 +91,7 @@ class RequestHandlerController extends Controller { $this->logger = $logger; $this->userManager = $userManager; + $this->groupManager = $groupManager; $this->urlGenerator = $urlGenerator; $this->cloudFederationProviderManager = $cloudFederationProviderManager; $this->config = $config; @@ -136,17 +142,37 @@ class RequestHandlerController extends Controller { ); } - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); - $shareWithLocalId = $cloudId->getUser(); - $shareWith = $this->mapUid($shareWithLocalId); - - if (!$this->userManager->userExists($shareWith)) { + $supportedShareTypes = $this->config->getSupportedShareTypes($resourceType); + if (!in_array($shareType, $supportedShareTypes)) { return new JSONResponse( - ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], - Http::STATUS_BAD_REQUEST + ['message' => 'Share type "' . $shareType . '" not implemented'], + Http::STATUS_NOT_IMPLEMENTED ); } + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); + $shareWith = $cloudId->getUser(); + + if ($shareType === 'user') { + $shareWith = $this->mapUid($shareWith); + + if (!$this->userManager->userExists($shareWith)) { + return new JSONResponse( + ['message' => 'User "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], + Http::STATUS_BAD_REQUEST + ); + } + } + + if ($shareType === 'group') { + if(!$this->groupManager->groupExists($shareWith)) { + return new JSONResponse( + ['message' => 'Group "' . $shareWith . '" does not exists at ' . $this->urlGenerator->getBaseUrl()], + Http::STATUS_BAD_REQUEST + ); + } + } + // if no explicit display name is given, we use the uid as display name $ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; $sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; @@ -161,7 +187,7 @@ class RequestHandlerController extends Controller { $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); $share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); $share->setProtocol($protocol); - $id = $provider->shareReceived($share); + $provider->shareReceived($share); } catch (ProviderDoesNotExistsException $e) { return new JSONResponse( ['message' => $e->getMessage()], @@ -179,7 +205,7 @@ class RequestHandlerController extends Controller { ); } - $user = $this->userManager->get($shareWithLocalId); + $user = $this->userManager->get($shareWith); $recipientDisplayName = ''; if($user) { $recipientDisplayName = $user->getDisplayName(); @@ -259,7 +285,6 @@ class RequestHandlerController extends Controller { * @return string mixed */ private function mapUid($uid) { - \OC::$server->getURLGenerator()->linkToDocs('key'); // FIXME this should be a method in the user management instead $this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]); \OCP\Util::emitHook( |