diff options
Diffstat (limited to 'apps')
5 files changed, 78 insertions, 14 deletions
diff --git a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php index 4f16c369a2f..319380ec3c3 100644 --- a/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php +++ b/apps/cloud_federation_api/lib/Controller/RequestHandlerController.php @@ -27,6 +27,7 @@ use OCA\CloudFederationAPI\Config; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; +use OCP\Federation\Exceptions\ActionNotSupportedException; use OCP\Federation\Exceptions\ProviderCouldNotAddShareException; use OCP\Federation\Exceptions\ShareNotFoundException; use OCP\Federation\ICloudFederationFactory; @@ -190,13 +191,12 @@ class RequestHandlerController extends Controller { /** * receive notification about existing share * - * @param $resourceType ('file', 'calendar',...) - * @param string $name resource name (e.g "file", "calendar",...) - * @param string $id unique id of the corresponding item on the receiving site - * @param array $notification contain the actual notification, content is defined by cloud federation provider + * @param string $notificationType (notification type, e.g. SHARE_ACCEPTED) + * @param string $resourceType (calendar, file, contact,...) + * @param array $message contain the actual notification, content is defined by cloud federation provider * @return JSONResponse */ - public function receiveNotification($resourceType, $name, $id, $notification) { + public function receiveNotification($notificationType, $resourceType, $message) { if (!$this->config->incomingRequestsEnabled()) { return new JSONResponse( ['message' => 'This server doesn\'t support outgoing federated shares'], @@ -205,9 +205,9 @@ class RequestHandlerController extends Controller { } // check if all required parameters are set - if ($name === null || - $id === null || - !is_array($notification) + if ($notificationType === null || + $resourceType === null || + !is_array($message) ) { return new JSONResponse( ['message' => 'Missing arguments'], @@ -217,7 +217,7 @@ class RequestHandlerController extends Controller { try { $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); - $provider->notificationReceived($id, $notification); + $provider->notificationReceived($notificationType, $message); } catch (ProviderDoesNotExistsException $e) { return new JSONResponse( ['message' => $e->getMessage()], @@ -228,6 +228,11 @@ class RequestHandlerController extends Controller { ['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST ); + } catch (ActionNotSupportedException $e) { + return new JSONResponse( + ['message' => $e->getMessage()], + Http::STATUS_NOT_IMPLEMENTED + ); } catch (\Exception $e) { return new JSONResponse( ['message' => 'Internal error at ' . $this->urlGenerator->getBaseUrl()], diff --git a/apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php index dea4c3f5fc1..6c5b63b1cd2 100644 --- a/apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php @@ -27,7 +27,9 @@ use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\FederatedShareProvider; use OCP\Activity\IManager as IActivityManager; use OCP\App\IAppManager; +use OCP\Federation\Exceptions\ActionNotSupportedException; use OCP\Federation\Exceptions\ProviderCouldNotAddShareException; +use OCP\Federation\Exceptions\ShareNotFoundException; use OCP\Federation\ICloudFederationProvider; use OCP\Federation\ICloudFederationShare; use OCP\Federation\ICloudIdManager; @@ -178,6 +180,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { \OC::$server->getNotificationManager(), \OC::$server->query(\OCP\OCS\IDiscoveryService::class), \OC::$server->getCloudFederationProviderManager(), + \OC::$server->getCloudFederationFactory(), $shareWith ); @@ -230,15 +233,22 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { /** * notification received from another server * - * @param string $id unique ID of a already existing share - * @param array $notification provider specific notification + * @param string $notificationType (e.g. SHARE_ACCEPTED) + * @param array $message * - * @throws \OCP\Federation\Exceptions\ShareNotFoundException + * @throws ShareNotFoundException + * @throws ActionNotSupportedException * * @since 14.0.0 */ - public function notificationReceived($id, $notification) { - // TODO: Implement notificationReceived() method. + public function notificationReceived($notificationType, array $message) { + switch ($notificationType) { + case 'SHARE_ACCEPTED' : + return; + } + + + throw new ActionNotSupportedException($notificationType); } /** diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index e0c40730b31..e6ab4eb2cf1 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -103,6 +103,8 @@ class Application extends App { $server->getHTTPClientService(), $server->getNotificationManager(), $server->query(\OCP\OCS\IDiscoveryService::class), + $server->getCloudFederationProviderManager(), + $server->getCloudFederationFactory(), $uid ); }); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index c9303ac224c..cb1e947f603 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -33,6 +33,8 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; use OCA\Files_Sharing\Helper; +use OCP\Federation\ICloudFederationFactory; +use OCP\Federation\ICloudFederationProviderManager; use OCP\Files; use OCP\Files\Storage\IStorageFactory; use OCP\Http\Client\IClientService; @@ -79,6 +81,12 @@ class Manager { */ private $discoveryService; + /** @var ICloudFederationProviderManager */ + private $cloudFederationProviderManager; + + /** @var ICloudFederationFactory */ + private $cloudFederationFactory; + /** * @param IDBConnection $connection * @param \OC\Files\Mount\Manager $mountManager @@ -86,6 +94,8 @@ class Manager { * @param IClientService $clientService * @param IManager $notificationManager * @param IDiscoveryService $discoveryService + * @param ICloudFederationProviderManager $cloudFederationProviderManager + * @param ICloudFederationFactory $cloudFederationFactory * @param string $uid */ public function __construct(IDBConnection $connection, @@ -94,6 +104,8 @@ class Manager { IClientService $clientService, IManager $notificationManager, IDiscoveryService $discoveryService, + ICloudFederationProviderManager $cloudFederationProviderManager, + ICloudFederationFactory $cloudFederationFactory, $uid) { $this->connection = $connection; $this->mountManager = $mountManager; @@ -102,6 +114,8 @@ class Manager { $this->uid = $uid; $this->notificationManager = $notificationManager; $this->discoveryService = $discoveryService; + $this->cloudFederationProviderManager = $cloudFederationProviderManager; + $this->cloudFederationFactory = $cloudFederationFactory; } /** @@ -274,6 +288,12 @@ class Manager { */ private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); + + if($result === true) { + return true; + } + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; @@ -300,6 +320,31 @@ class Manager { } /** + * try send accept message to ocm end-point + * + * @param string $remoteDomain + * @param string $token + * @param $remoteId + * @param string $feedback + * @return mixed + */ + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { + switch ($feedback) { + case 'accept': + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); + $notification->setMessage('SHARE_ACCEPTED', 'file', + [ + 'id' => $remoteId, + 'access_token' => $token + ] + ); + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); + } + + } + + + /** * remove '/user/files' from the path and trailing slashes * * @param string $path diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 51511ca6b64..cd66fd7702e 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -40,6 +40,8 @@ class Hooks { \OC::$server->getHTTPClientService(), \OC::$server->getNotificationManager(), \OC::$server->query(\OCP\OCS\IDiscoveryService::class), + \OC::$server->getCloudFederationProviderManager(), + \OC::$server->getCloudFederationFactory(), $params['uid']); $manager->removeUserShares($params['uid']); |