diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php index 63de8ff605ea5..90e7f53da80a2 100644 --- a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php +++ b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php @@ -39,9 +39,6 @@ #[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)] class RequestHandlerController extends OCSController { - /** @var string */ - private $shareTable = 'share'; - public function __construct( string $appName, IRequest $request, diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 139c873b0d6e4..2c836dfc090ab 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -909,99 +909,90 @@ public function userDeletedFromGroup($uid, $gid) { } /** - * check if users from other Nextcloud instances are allowed to mount public links share by this instance - * - * @return bool + * Check if users from other Nextcloud instances are allowed to mount public links share by this instance */ - public function isOutgoingServer2serverShareEnabled() { + public function isOutgoingServer2serverShareEnabled(): bool { if ($this->gsConfig->onlyInternalFederation()) { return false; } $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); - return ($result === 'yes'); + return $result === 'yes'; } /** - * check if users are allowed to mount public links from other Nextclouds - * - * @return bool + * Check if users are allowed to mount public links from other Nextclouds */ - public function isIncomingServer2serverShareEnabled() { + public function isIncomingServer2serverShareEnabled(): bool { if ($this->gsConfig->onlyInternalFederation()) { return false; } $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); - return ($result === 'yes'); + return $result === 'yes'; } /** - * check if users from other Nextcloud instances are allowed to send federated group shares - * - * @return bool + * Check if users from other Nextcloud instances are allowed to send federated group shares */ - public function isOutgoingServer2serverGroupShareEnabled() { + public function isOutgoingServer2serverGroupShareEnabled(): bool { if ($this->gsConfig->onlyInternalFederation()) { return false; } $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no'); - return ($result === 'yes'); + return $result === 'yes'; } /** - * check if users are allowed to receive federated group shares - * - * @return bool + * Check if users are allowed to receive federated group shares */ - public function isIncomingServer2serverGroupShareEnabled() { + public function isIncomingServer2serverGroupShareEnabled(): bool { if ($this->gsConfig->onlyInternalFederation()) { return false; } $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no'); - return ($result === 'yes'); + return $result === 'yes'; } /** - * check if federated group sharing is supported, therefore the OCM API need to be enabled - * - * @return bool + * Check if federated group sharing is supported, therefore the OCM API need to be enabled */ - public function isFederatedGroupSharingSupported() { + public function isFederatedGroupSharingSupported(): bool { return $this->cloudFederationProviderManager->isReady(); } /** * Check if querying sharees on the lookup server is enabled - * - * @return bool */ - public function isLookupServerQueriesEnabled() { + public function isLookupServerQueriesEnabled(): bool { // in a global scale setup we should always query the lookup server if ($this->gsConfig->isGlobalScaleEnabled()) { return true; } $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes'); - return ($result === 'yes'); + return $result === 'yes'; } /** * Check if it is allowed to publish user specific data to the lookup server - * - * @return bool */ - public function isLookupServerUploadEnabled() { + public function isLookupServerUploadEnabled(): bool { // in a global scale setup the admin is responsible to keep the lookup server up-to-date if ($this->gsConfig->isGlobalScaleEnabled()) { return false; } $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); - return ($result === 'yes'); + return $result === 'yes'; } /** - * @inheritdoc + * Check if auto accepting incoming shares from trusted servers is enabled */ + public function isFederatedTrustedShareAutoAccept(): bool { + $result = $this->config->getAppValue('files_sharing', 'federatedTrustedShareAutoAccept', 'yes'); + return $result === 'yes'; + } + public function getAccessList($nodes, $currentAccess) { $ids = []; foreach ($nodes as $node) { diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 5c633c0fbbfdb..d5082eafc567b 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -10,6 +10,7 @@ use OC\Files\Filesystem; use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\FederatedShareProvider; +use OCA\Federation\TrustedServers; use OCA\Files_Sharing\Activity\Providers\RemoteShares; use OCA\Files_Sharing\External\Manager; use OCA\GlobalSiteSelector\Service\SlaveService; @@ -66,6 +67,7 @@ public function __construct( private LoggerInterface $logger, private IFilenameValidator $filenameValidator, private readonly IProviderFactory $shareProviderFactory, + private TrustedServers $trustedServers, ) { } @@ -163,6 +165,11 @@ public function shareReceived(ICloudFederationShare $share) { ->setObject('remote_share', $shareId, $name); \OC::$server->getActivityManager()->publish($event); $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); + + // If auto-accept is enabled, accept the share + if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) { + $this->externalShareManager->acceptShare($shareId, $shareWith); + } } else { $groupMembers = $this->groupManager->get($shareWith)->getUsers(); foreach ($groupMembers as $user) { @@ -174,8 +181,14 @@ public function shareReceived(ICloudFederationShare $share) { ->setObject('remote_share', $shareId, $name); \OC::$server->getActivityManager()->publish($event); $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); + + // If auto-accept is enabled, accept the share + if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) { + $this->externalShareManager->acceptShare($shareId, $user->getUID()); + } } } + return $shareId; } catch (\Exception $e) { $this->logger->error('Server can not add remote share.', [ diff --git a/apps/federatedfilesharing/lib/Settings/Admin.php b/apps/federatedfilesharing/lib/Settings/Admin.php index 1343513e65ae1..e21c34638adaf 100644 --- a/apps/federatedfilesharing/lib/Settings/Admin.php +++ b/apps/federatedfilesharing/lib/Settings/Admin.php @@ -40,6 +40,7 @@ public function getForm() { $this->initialState->provideInitialState('incomingServer2serverGroupShareEnabled', $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled()); $this->initialState->provideInitialState('lookupServerEnabled', $this->fedShareProvider->isLookupServerQueriesEnabled()); $this->initialState->provideInitialState('lookupServerUploadEnabled', $this->fedShareProvider->isLookupServerUploadEnabled()); + $this->initialState->provideInitialState('federatedTrustedShareAutoAccept', $this->fedShareProvider->isFederatedTrustedShareAutoAccept()); return new TemplateResponse('federatedfilesharing', 'settings-admin', [], ''); } @@ -76,6 +77,7 @@ public function getAuthorizedAppConfig(): array { 'incomingServer2serverGroupShareEnabled', 'lookupServerEnabled', 'lookupServerUploadEnabled', + 'federatedTrustedShareAutoAccept', ], ]; } diff --git a/apps/federatedfilesharing/src/components/AdminSettings.vue b/apps/federatedfilesharing/src/components/AdminSettings.vue index dfafe64c0622b..edf7dc15d0967 100644 --- a/apps/federatedfilesharing/src/components/AdminSettings.vue +++ b/apps/federatedfilesharing/src/components/AdminSettings.vue @@ -43,6 +43,18 @@ @update:checked="update('lookupServerUploadEnabled', lookupServerUploadEnabled)"> {{ t('federatedfilesharing', 'Allow people to publish their data to a global and public address book') }} + + +
t('Federation allows you to connect with other trusted servers to exchange the account directory. For example this will be used to auto-complete external accounts for federated sharing. It is not necessary to add a server as trusted server in order to create a federated share.')); ?>
+t('Each server must validate the other. This process may require a few cron cycles.')); ?>
- + +
\n\t\t\t\t{{ subtitle }}\n\t\t\t
\n\t\t\n\t\t\t\t\t{{ subtitle }}\n\t\t\t\t
\n\t\t\t\t\n\t\t\t\t{{ subtitle }}\n\t\t\t
\n\t\t\n\t\t\t\t\t{{ subtitle }}\n\t\t\t\t
\n\t\t\t\t