From c8631d607ef827f0eb29312faf7b2b808e1a8e7d Mon Sep 17 00:00:00 2001
From: Bjoern Schiessle
Date: Mon, 25 Jun 2018 11:40:16 +0200
Subject: [PATCH] add setting to enable/disable federated group sharing
Signed-off-by: Bjoern Schiessle
---
.../lib/FederatedShareProvider.php | 45 ++++++++++++++++++-
.../lib/Settings/Admin.php | 3 ++
.../templates/settings-admin.php | 17 ++++++-
3 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index f81b826f12..d32560c4ff 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -30,6 +30,7 @@
namespace OCA\FederatedFileSharing;
use OC\Share20\Share;
+use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Folder;
@@ -92,6 +93,9 @@ class FederatedShareProvider implements IShareProvider {
/** @var \OCP\GlobalScale\IConfig */
private $gsConfig;
+ /** @var ICloudFederationProviderManager */
+ private $cloudFederationProviderManager;
+
/**
* DefaultShareProvider constructor.
*
@@ -106,6 +110,7 @@ class FederatedShareProvider implements IShareProvider {
* @param IUserManager $userManager
* @param ICloudIdManager $cloudIdManager
* @param \OCP\GlobalScale\IConfig $globalScaleConfig
+ * @param ICloudFederationProviderManager $cloudFederationProviderManager
*/
public function __construct(
IDBConnection $connection,
@@ -118,7 +123,8 @@ class FederatedShareProvider implements IShareProvider {
IConfig $config,
IUserManager $userManager,
ICloudIdManager $cloudIdManager,
- \OCP\GlobalScale\IConfig $globalScaleConfig
+ \OCP\GlobalScale\IConfig $globalScaleConfig,
+ ICloudFederationProviderManager $cloudFederationProviderManager
) {
$this->dbConnection = $connection;
$this->addressHandler = $addressHandler;
@@ -131,6 +137,7 @@ class FederatedShareProvider implements IShareProvider {
$this->userManager = $userManager;
$this->cloudIdManager = $cloudIdManager;
$this->gsConfig = $globalScaleConfig;
+ $this->cloudFederationProviderManager = $cloudFederationProviderManager;
}
/**
@@ -967,6 +974,42 @@ class FederatedShareProvider implements IShareProvider {
return ($result === 'yes');
}
+
+ /**
+ * check if users from other Nextcloud instances are allowed to send federated group shares
+ *
+ * @return bool
+ */
+ public function isOutgoingServer2serverGroupShareEnabled() {
+ if ($this->gsConfig->onlyInternalFederation()) {
+ return false;
+ }
+ $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no');
+ return ($result === 'yes');
+ }
+
+ /**
+ * check if users are allowed to receive federated group shares
+ *
+ * @return bool
+ */
+ public function isIncomingServer2serverGroupShareEnabled() {
+ if ($this->gsConfig->onlyInternalFederation()) {
+ return false;
+ }
+ $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no');
+ return ($result === 'yes');
+ }
+
+ /**
+ * check if federated group sharing is supported, therefore the OCM API need to be enabled
+ *
+ * @return bool
+ */
+ public function isFederatedGroupSharingSupported() {
+ return $this->cloudFederationProviderManager->isReady();
+ }
+
/**
* Check if querying sharees on the lookup server is enabled
*
diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php
index cbeaa167ff..aea7957a49 100644
--- a/apps/federatedfilesharing/lib/Settings/Admin.php
+++ b/apps/federatedfilesharing/lib/Settings/Admin.php
@@ -58,6 +58,9 @@ class Admin implements ISettings {
'internalOnly' => $this->gsConfig->onlyInternalFederation(),
'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
+ 'federatedGroupSharingSupported' => $this->fedShareProvider->isFederatedGroupSharingSupported(),
+ 'outgoingServer2serverGroupShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverGroupShareEnabled(),
+ 'incomingServer2serverGroupShareEnabled' => $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled(),
'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(),
];
diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php
index 187d75f21a..1b9b88dc03 100644
--- a/apps/federatedfilesharing/templates/settings-admin.php
+++ b/apps/federatedfilesharing/templates/settings-admin.php
@@ -23,7 +23,6 @@ script('federatedfilesharing', 'settings-admin');
t('Allow users on this server to send shares to other servers'));?>
-
/>
@@ -31,6 +30,22 @@ script('federatedfilesharing', 'settings-admin');
t('Allow users on this server to receive shares from other servers'));?>
+
+
+ />
+
+
+
+ />
+
+
+
/>