diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-07-11 21:44:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 21:44:48 +0200 |
commit | 3036b1d03d93267ff7fdda7a1e0682173aec2b98 (patch) | |
tree | 8aeaf29d54d3f508071885b5791b2af96c04f2f0 /lib | |
parent | a89f9a238f873aab524ba985ed5f3a342ff877f6 (diff) | |
parent | 412f6a6eccd7b4b955d63922150dbe2104cd269d (diff) | |
download | nextcloud-server-3036b1d03d93267ff7fdda7a1e0682173aec2b98.tar.gz nextcloud-server-3036b1d03d93267ff7fdda7a1e0682173aec2b98.zip |
Merge pull request #9895 from nextcloud/fed-group-shares
implement federated group sharing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php | 78 | ||||
-rw-r--r-- | lib/private/Federation/CloudFederationProviderManager.php | 1 | ||||
-rw-r--r-- | lib/private/Federation/CloudFederationShare.php | 6 | ||||
-rw-r--r-- | lib/private/Server.php | 2 | ||||
-rw-r--r-- | lib/private/Share/Constants.php | 1 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 11 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 5 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 8 |
10 files changed, 111 insertions, 3 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index faf17a109b2..7113f60bc68 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -471,6 +471,7 @@ return array( 'OC\\Collaboration\\Collaborators\\GroupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/GroupPlugin.php', 'OC\\Collaboration\\Collaborators\\LookupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/LookupPlugin.php', 'OC\\Collaboration\\Collaborators\\MailPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/MailPlugin.php', + 'OC\\Collaboration\\Collaborators\\RemoteGroupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php', 'OC\\Collaboration\\Collaborators\\RemotePlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/RemotePlugin.php', 'OC\\Collaboration\\Collaborators\\Search' => $baseDir . '/lib/private/Collaboration/Collaborators/Search.php', 'OC\\Collaboration\\Collaborators\\SearchResult' => $baseDir . '/lib/private/Collaboration/Collaborators/SearchResult.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a8d748137e8..ffb50df5b09 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -501,6 +501,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Collaboration\\Collaborators\\GroupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/GroupPlugin.php', 'OC\\Collaboration\\Collaborators\\LookupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/LookupPlugin.php', 'OC\\Collaboration\\Collaborators\\MailPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/MailPlugin.php', + 'OC\\Collaboration\\Collaborators\\RemoteGroupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php', 'OC\\Collaboration\\Collaborators\\RemotePlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/RemotePlugin.php', 'OC\\Collaboration\\Collaborators\\Search' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/Search.php', 'OC\\Collaboration\\Collaborators\\SearchResult' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/SearchResult.php', diff --git a/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php b/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php new file mode 100644 index 00000000000..c48a1fbae20 --- /dev/null +++ b/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php @@ -0,0 +1,78 @@ +<?php +/** + * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Collaboration\Collaborators; + + +use OCP\Collaboration\Collaborators\ISearchPlugin; +use OCP\Collaboration\Collaborators\ISearchResult; +use OCP\Collaboration\Collaborators\SearchResultType; +use OCP\Contacts\IManager; +use OCP\Federation\ICloudFederationProviderManager; +use OCP\Federation\ICloudIdManager; +use OCP\IConfig; +use OCP\Share; + +class RemoteGroupPlugin implements ISearchPlugin { + protected $shareeEnumeration; + + /** @var ICloudIdManager */ + private $cloudIdManager; + /** @var IConfig */ + private $config; + /** @var bool */ + private $enabled = false; + + public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) { + try { + $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); + $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); + if (in_array('group', $supportedShareTypes)) { + $this->enabled = true; + } + } catch (\Exception $e) { + // do nothing, just don't enable federated group shares + } + $this->cloudIdManager = $cloudIdManager; + } + + public function search($search, $limit, $offset, ISearchResult $searchResult) { + $result = ['wide' => [], 'exact' => []]; + $resultType = new SearchResultType('remote_groups'); + + if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { + $result['exact'][] = [ + 'label' => $search, + 'value' => [ + 'shareType' => Share::SHARE_TYPE_REMOTE_GROUP, + 'shareWith' => $search, + ], + ]; + } + + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); + + return true; + } + +} diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php index 254ceb03bf8..94b2f052747 100644 --- a/lib/private/Federation/CloudFederationProviderManager.php +++ b/lib/private/Federation/CloudFederationProviderManager.php @@ -157,6 +157,7 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager // we re-throw the exception and fall back to the old behaviour. // (flat re-shares has been introduced in Nextcloud 9.1) if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { + $this->logger->debug($e->getMessage()); throw $e; } } diff --git a/lib/private/Federation/CloudFederationShare.php b/lib/private/Federation/CloudFederationShare.php index 0c2795188f0..e0360d78cb2 100644 --- a/lib/private/Federation/CloudFederationShare.php +++ b/lib/private/Federation/CloudFederationShare.php @@ -204,7 +204,11 @@ class CloudFederationShare implements ICloudFederationShare { * @since 14.0.0 */ public function setShareType($shareType) { - $this->share['shareType'] = $shareType; + if ($shareType === 'group' || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { + $this->share['shareType'] = 'group'; + } else { + $this->share['shareType'] = 'user'; + } } /** diff --git a/lib/private/Server.php b/lib/private/Server.php index 90e9e81c105..c9f8001631e 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -60,6 +60,7 @@ use OC\Authentication\LoginCredentials\Store; use OC\Authentication\Token\IProvider; use OC\Collaboration\Collaborators\GroupPlugin; use OC\Collaboration\Collaborators\MailPlugin; +use OC\Collaboration\Collaborators\RemoteGroupPlugin; use OC\Collaboration\Collaborators\RemotePlugin; use OC\Collaboration\Collaborators\UserPlugin; use OC\Command\CronBus; @@ -1066,6 +1067,7 @@ class Server extends ServerContainer implements IServerContainer { $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); return $instance; }); diff --git a/lib/private/Share/Constants.php b/lib/private/Share/Constants.php index f351f8d7fda..4eb79734c06 100644 --- a/lib/private/Share/Constants.php +++ b/lib/private/Share/Constants.php @@ -37,6 +37,7 @@ class Constants { const SHARE_TYPE_REMOTE = 6; const SHARE_TYPE_CIRCLE = 7; const SHARE_TYPE_GUEST = 8; + const SHARE_TYPE_REMOTE_GROUP = 9; const FORMAT_NONE = -1; const FORMAT_STATUSES = -2; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 5116351a6bc..76b523afd10 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -226,6 +226,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_REMOTE_GROUP) { + 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'); @@ -1582,6 +1586,13 @@ class Manager implements IManager { /** * @inheritdoc */ + public function outgoingServer2ServerGroupSharesAllowed() { + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; + } + + /** + * @inheritdoc + */ public function shareProviderExists($shareType) { try { $this->factory->getProviderForType($shareType); diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 7d866db24fa..80ef9412ffa 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -135,7 +135,8 @@ class ProviderFactory implements IProviderFactory { $this->serverContainer->getConfig(), $this->serverContainer->getUserManager(), $this->serverContainer->getCloudIdManager(), - $this->serverContainer->getGlobalScaleConfig() + $this->serverContainer->getGlobalScaleConfig(), + $this->serverContainer->getCloudFederationProviderManager() ); } @@ -250,7 +251,7 @@ class ProviderFactory implements IProviderFactory { $shareType === \OCP\Share::SHARE_TYPE_LINK ) { $provider = $this->defaultShareProvider(); - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE || \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { $provider = $this->federatedShareProvider(); } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { $provider = $this->getShareByMailProvider(); diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index d4fc3e14749..302be523327 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -370,6 +370,14 @@ interface IManager { public function outgoingServer2ServerSharesAllowed(); /** + * Check if outgoing server2server shares are allowed + * @return bool + * @since 14.0.0 + */ + public function outgoingServer2ServerGroupSharesAllowed(); + + + /** * Check if a given share provider exists * @param int $shareType * @return bool |