Skip to content

Commit

Permalink
Merge pull request #85 from pdsinterop/feature/notifications
Browse files Browse the repository at this point in the history
Implementiation for webhooks and notification registration endpoints
  • Loading branch information
ylebre authored Sep 30, 2022
2 parents c2f713e + c717b0f commit 9809f47
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
solid/bin
solid/vendor
2 changes: 1 addition & 1 deletion run-solid-test-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ startPubSub
startSolidNextcloud server
startSolidNextcloud thirdparty
runTests webid-provider
runTests solid-crud
runTests web-access-control
runTests solid-crud
teardown
19 changes: 19 additions & 0 deletions solid/TODO.Notifications
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TODO:
- [ ] advertise the notifications channel in well-known
- [ ] advertise the notifications channel in HTTP headers

Backlog / later:
- [ ] add actor to notifications
- [ ] add UUID to notifications
- [ ] Add support for the rate limit feature.
- [ ] create a solid-notifications-lastsent database table - columns are subscription_id and lastsent;
- [ ] how can we stop sending notifications when read access was revoked?
- [ ] use a background process to send notifications so they are out of bound with requests

Done:
- [v] create a solid-notifications-subscription database table - columns should have: id, webid, path, url, expiry
- [v] add notifications controller
- [v] handle register requests - this must validate that the requestor has read access to the resource;
- [v] handle unregister requests - only the webid that subscribed should be able to unsubscribe
- [v] reinstate the updates-via header in HEAD requests, which was removed from solid-crud
- [v] implement function to get subscription in SolidWebhook
6 changes: 6 additions & 0 deletions solid/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
['name' => 'contacts#handlePatch', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleHead', 'url' => '/@{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],

['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'],
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'],

['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'],

['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'],
]
];
2 changes: 1 addition & 1 deletion solid/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"pdsinterop/flysystem-nextcloud": "^0.2",
"pdsinterop/flysystem-rdf": "^0.5",
"pdsinterop/solid-auth": "v0.10.1",
"pdsinterop/solid-crud": "^0.6",
"pdsinterop/solid-crud": "^0.7.0",
"psr/log": "^1.1"
},
"require-dev": {
Expand Down
20 changes: 12 additions & 8 deletions solid/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions solid/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCA\Solid\Service\UserService;
use OCA\Solid\WellKnown\OpenIdConfigurationHandler;
use OCA\Solid\WellKnown\SolidHandler;
use OCA\Solid\Middleware\SolidCorsMiddleware;

use OCP\AppFramework\App;
Expand Down Expand Up @@ -42,10 +43,23 @@ public function __construct(array $urlParams = []) {

// executed in the order that it is registered
$container->registerMiddleware(SolidCorsMiddleware::class);

$container->registerService(SolidWebhookService::class, function($c): SolidWebhookService {
return new SolidWebhookService(
$c->query(SolidWebhookMapper::class)
);
});

$container->registerService(SolidWebhookMapper::class, function($c): SolidWebhookMapper {
return new SolidWebhookMapper(
$c->get(IDBConnection::class)
);
});
}

public function register(IRegistrationContext $context): void {
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\OpenIdConfigurationHandler::class);
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\SolidHandler::class);

/**
* Core class wrappers
Expand Down
7 changes: 4 additions & 3 deletions solid/lib/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use OCA\Solid\DpopFactoryTrait;
use OCA\Solid\PlainResponse;
use OCA\Solid\Notifications\SolidNotifications;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -129,14 +130,14 @@ public function handleRequest($userId, $path) {
$this->filesystem = $this->getFileSystem($userId);

$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
$this->WAC = new WAC($this->filesystem);
$this->WAC = new WAC($this->filesystem);

$request = $this->rawRequest;
$baseUrl = $this->getCalendarUrl($userId);
$this->resourceServer->setBaseUrl($baseUrl);
$this->WAC->setBaseUrl($baseUrl);
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
$this->resourceServer->setPubSubUrl($pubsub);
$notifications = new SolidNotifications();
$this->resourceServer->setNotifications($notifications);

$dpop = $this->getDpop();

Expand Down
7 changes: 4 additions & 3 deletions solid/lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use OCA\Solid\DpopFactoryTrait;
use OCA\Solid\PlainResponse;
use OCA\Solid\Notifications\SolidNotifications;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -130,14 +131,14 @@ public function handleRequest($userId, $path) {
$this->filesystem = $this->getFileSystem($userId);

$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
$this->WAC = new WAC($this->filesystem);
$this->WAC = new WAC($this->filesystem);

$request = $this->rawRequest;
$baseUrl = $this->getContactsUrl($userId);
$this->resourceServer->setBaseUrl($baseUrl);
$this->WAC->setBaseUrl($baseUrl);
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
$this->resourceServer->setPubSubUrl($pubsub);
$notifications = new SolidNotifications();
$this->resourceServer->setNotifications($notifications);

$dpop = $this->getDpop();

Expand Down
7 changes: 4 additions & 3 deletions solid/lib/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use OCA\Solid\DpopFactoryTrait;
use OCA\Solid\PlainResponse;
use OCA\Solid\Notifications\SolidNotifications;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -146,14 +147,14 @@ public function handleRequest($userId, $path) {
$this->filesystem = $this->getFileSystem($userId);

$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
$this->WAC = new WAC($this->filesystem);
$this->WAC = new WAC($this->filesystem);

$request = $this->rawRequest;
$baseUrl = $this->getProfileUrl($userId);
$this->resourceServer->setBaseUrl($baseUrl);
$this->WAC->setBaseUrl($baseUrl);
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
$this->resourceServer->setPubSubUrl($pubsub);
$notifications = new SolidNotifications();
$this->resourceServer->setNotifications($notifications);

$dpop = $this->getDpop();

Expand Down
Loading

0 comments on commit 9809f47

Please sign in to comment.