summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2018-05-09 17:06:35 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2018-07-02 11:29:27 +0200
commitdb428ea5471a5be5517911b3bf2f3a6d3f86e297 (patch)
tree3921525a302150e75d968a47dff14be79f9ffa3b /lib/private
parenta3948e8a126d6f84629841c8886fe0819ab04ad5 (diff)
downloadnextcloud-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')
-rw-r--r--lib/private/Federation/CloudFederationNotification.php19
-rw-r--r--lib/private/Federation/CloudFederationProviderManager.php50
-rw-r--r--lib/private/Server.php2
3 files changed, 56 insertions, 15 deletions
diff --git a/lib/private/Federation/CloudFederationNotification.php b/lib/private/Federation/CloudFederationNotification.php
index ed87b9b0e5d..356c47968f5 100644
--- a/lib/private/Federation/CloudFederationNotification.php
+++ b/lib/private/Federation/CloudFederationNotification.php
@@ -30,23 +30,28 @@ class CloudFederationNotification implements ICloudFederationNotification {
/**
* add a message to the notification
*
- * @param string $identifier
- * @param string $message
+ * @param string $notificationType (e.g. SHARE_ACCEPTED)
+ * @param string $resourceType (e.g. file, calendar, contact,...)
+ * @param array $message
*
* @since 14.0.0
*/
- public function setMessage($identifier, $message) {
- $this->message[$identifier] = $message;
+ public function setMessage($notificationType, $resourceType, array $message) {
+ $this->message = [
+ 'notificationType' => $notificationType,
+ 'resourceType' => $resourceType,
+ 'message' => $message,
+ ];
}
/**
- * get JSON encoded Message, ready to send out
+ * get message, ready to send out
*
- * @return string
+ * @return array
*
* @since 14.0.0
*/
public function getMessage() {
- return json_encode($this->message);
+ return $this->message;
}
}
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;
}
/**
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 8f1b24eb11d..90e9e81c105 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1117,7 +1117,7 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
- return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager());
+ return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
});
$this->registerService(ICloudFederationFactory::class, function (Server $c) {