diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2018-05-09 17:06:35 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2018-07-02 11:29:27 +0200 |
commit | db428ea5471a5be5517911b3bf2f3a6d3f86e297 (patch) | |
tree | 3921525a302150e75d968a47dff14be79f9ffa3b /lib/private/Federation/CloudFederationProviderManager.php | |
parent | a3948e8a126d6f84629841c8886fe0819ab04ad5 (diff) | |
download | nextcloud-server-db428ea5471a5be5517911b3bf2f3a6d3f86e297.tar.gz nextcloud-server-db428ea5471a5be5517911b3bf2f3a6d3f86e297.zip |
send accept share notification (WIP)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib/private/Federation/CloudFederationProviderManager.php')
-rw-r--r-- | lib/private/Federation/CloudFederationProviderManager.php | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/lib/private/Federation/CloudFederationProviderManager.php b/lib/private/Federation/CloudFederationProviderManager.php index dcf666ca266..c302659fb69 100644 --- a/lib/private/Federation/CloudFederationProviderManager.php +++ b/lib/private/Federation/CloudFederationProviderManager.php @@ -22,8 +22,8 @@ namespace OC\Federation; +use OC\AppFramework\Http; use OCP\App\IAppManager; -use OCP\Federation\Exceptions\ProviderAlreadyExistsException; use OCP\Federation\Exceptions\ProviderDoesNotExistsException; use OCP\Federation\ICloudFederationNotification; use OCP\Federation\ICloudFederationProvider; @@ -31,6 +31,7 @@ use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudFederationShare; use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; +use OCP\ILogger; /** * Class Manager @@ -53,20 +54,26 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager /** @var ICloudIdManager */ private $cloudIdManager; + /** @var ILogger */ + private $logger; + /** * CloudFederationProviderManager constructor. * * @param IAppManager $appManager * @param IClientService $httpClientService * @param ICloudIdManager $cloudIdManager + * @param ILogger $logger */ public function __construct(IAppManager $appManager, IClientService $httpClientService, - ICloudIdManager $cloudIdManager) { + ICloudIdManager $cloudIdManager, + ILogger $logger) { $this->cloudFederationProvider= []; $this->appManager = $appManager; $this->httpClientService = $httpClientService; $this->cloudIdManager = $cloudIdManager; + $this->logger = $logger; } @@ -135,8 +142,11 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager 'timeout' => 10, 'connect_timeout' => 10, ]); - $result['result'] = $response->getBody(); - $result['success'] = true; + + if ($response->getStatusCode() === Http::STATUS_OK) { + return true; + } + } catch (\Exception $e) { // if flat re-sharing is not supported by the remote server // we re-throw the exception and fall back to the old behaviour. @@ -146,12 +156,38 @@ class CloudFederationProviderManager implements ICloudFederationProviderManager } } - return true; + return false; } - public function sendNotification(ICloudFederationNotification $notification) { - // TODO: Implement sendNotification() method. + /** + * @param string $url + * @param ICloudFederationNotification $notification + * @return bool + */ + public function sendNotification($url, ICloudFederationNotification $notification) { + $ocmEndPoint = $this->getOCMEndPoint($url); + + if (empty($ocmEndPoint)) { + return false; + } + + $client = $this->httpClientService->newClient(); + try { + $response = $client->post($ocmEndPoint . '/notifications', [ + 'body' => $notification->getMessage(), + 'timeout' => 10, + 'connect_timeout' => 10, + ]); + if ($response->getStatusCode() === Http::STATUS_OK) { + return true; + } + } catch (\Exception $e) { + // log the error and return false + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); + } + + return false; } /** |