From f6ec17eb7ebf1959b9f69d0e5a67c7d0480d6c73 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 24 Nov 2023 17:56:50 -0100 Subject: [PATCH] gs.federation.auto_accept_shares Signed-off-by: Maxence Lange --- .../lib/OCM/CloudFederationProviderFiles.php | 14 ++++++++++++-- apps/files_sharing/lib/External/Manager.php | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 923214f0f2d53..f8e97de390e11 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -33,7 +33,7 @@ use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Activity\Providers\RemoteShares; -use OCA\Files_Sharing\External\Manager; +use OCA\Files_Sharing\External\Manager as ExternalManager; use OCP\Activity\IManager as IActivityManager; use OCP\App\IAppManager; use OCP\Constants; @@ -62,6 +62,8 @@ use Psr\Log\LoggerInterface; class CloudFederationProviderFiles implements ICloudFederationProvider { + const AUTO_ACCEPT_SHARES = 'gs.federation.auto_accept_shares'; + /** * CloudFederationProvider constructor. */ @@ -80,7 +82,7 @@ public function __construct( private IDBConnection $connection, private IGroupManager $groupManager, private IConfig $config, - private Manager $externalShareManager, + private ExternalManager $externalShareManager, private LoggerInterface $logger, ) { } @@ -166,6 +168,10 @@ public function shareReceived(ICloudFederationShare $share) { try { $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId); $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); + if ($this->config->getSystemValueBool(self::AUTO_ACCEPT_SHARES)) { + $this->externalShareManager->initUserId($shareWith); + $this->externalShareManager->acceptShare($shareId); + } // get DisplayName about the owner of the share $ownerDisplayName = $this->getUserDisplayName($ownerFederatedId); @@ -255,6 +261,10 @@ private function mapShareTypeToNextcloud($shareType) { } private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $displayName): void { + if ($this->config->getSystemValueBool(self::AUTO_ACCEPT_SHARES)) { + return; + } + $notification = $this->notificationManager->createNotification(); $notification->setApp('files_sharing') ->setUser($shareWith) diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index f18d8346dc44d..ca8bf3a04465c 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -301,6 +301,10 @@ private function updateAccepted(int $shareId, bool $accepted) : void { $updateResult->closeCursor(); } + public function initUserId(string $userId): void { + $this->uid = $userId; + } + /** * accept server-to-server share *