Skip to content

Commit 9809f47

Browse files
authored
Merge pull request #85 from pdsinterop/feature/notifications
Implementiation for webhooks and notification registration endpoints
2 parents c2f713e + c717b0f commit 9809f47

24 files changed

Lines changed: 714 additions & 21 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
solid/bin
2+
solid/vendor

run-solid-test-suite.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ startPubSub
5757
startSolidNextcloud server
5858
startSolidNextcloud thirdparty
5959
runTests webid-provider
60-
runTests solid-crud
6160
runTests web-access-control
61+
runTests solid-crud
6262
teardown

solid/TODO.Notifications

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TODO:
2+
- [ ] advertise the notifications channel in well-known
3+
- [ ] advertise the notifications channel in HTTP headers
4+
5+
Backlog / later:
6+
- [ ] add actor to notifications
7+
- [ ] add UUID to notifications
8+
- [ ] Add support for the rate limit feature.
9+
- [ ] create a solid-notifications-lastsent database table - columns are subscription_id and lastsent;
10+
- [ ] how can we stop sending notifications when read access was revoked?
11+
- [ ] use a background process to send notifications so they are out of bound with requests
12+
13+
Done:
14+
- [v] create a solid-notifications-subscription database table - columns should have: id, webid, path, url, expiry
15+
- [v] add notifications controller
16+
- [v] handle register requests - this must validate that the requestor has read access to the resource;
17+
- [v] handle unregister requests - only the webid that subscribed should be able to unsubscribe
18+
- [v] reinstate the updates-via header in HEAD requests, which was removed from solid-crud
19+
- [v] implement function to get subscription in SolidWebhook

solid/appinfo/routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
['name' => 'contacts#handlePatch', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
5252
['name' => 'contacts#handleHead', 'url' => '/@{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],
5353

54+
['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'],
55+
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
56+
['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'],
57+
58+
['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'],
59+
5460
['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'],
5561
]
5662
];

solid/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"pdsinterop/flysystem-nextcloud": "^0.2",
3333
"pdsinterop/flysystem-rdf": "^0.5",
3434
"pdsinterop/solid-auth": "v0.10.1",
35-
"pdsinterop/solid-crud": "^0.6",
35+
"pdsinterop/solid-crud": "^0.7.0",
3636
"psr/log": "^1.1"
3737
},
3838
"require-dev": {

solid/composer.lock

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solid/lib/AppInfo/Application.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCA\Solid\Service\UserService;
1313
use OCA\Solid\WellKnown\OpenIdConfigurationHandler;
14+
use OCA\Solid\WellKnown\SolidHandler;
1415
use OCA\Solid\Middleware\SolidCorsMiddleware;
1516

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

4344
// executed in the order that it is registered
4445
$container->registerMiddleware(SolidCorsMiddleware::class);
46+
47+
$container->registerService(SolidWebhookService::class, function($c): SolidWebhookService {
48+
return new SolidWebhookService(
49+
$c->query(SolidWebhookMapper::class)
50+
);
51+
});
52+
53+
$container->registerService(SolidWebhookMapper::class, function($c): SolidWebhookMapper {
54+
return new SolidWebhookMapper(
55+
$c->get(IDBConnection::class)
56+
);
57+
});
4558
}
4659

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

5064
/**
5165
* Core class wrappers

solid/lib/Controller/CalendarController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use OCA\Solid\DpopFactoryTrait;
55
use OCA\Solid\PlainResponse;
6+
use OCA\Solid\Notifications\SolidNotifications;
67

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

131132
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
132-
$this->WAC = new WAC($this->filesystem);
133+
$this->WAC = new WAC($this->filesystem);
133134

134135
$request = $this->rawRequest;
135136
$baseUrl = $this->getCalendarUrl($userId);
136137
$this->resourceServer->setBaseUrl($baseUrl);
137138
$this->WAC->setBaseUrl($baseUrl);
138-
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
139-
$this->resourceServer->setPubSubUrl($pubsub);
139+
$notifications = new SolidNotifications();
140+
$this->resourceServer->setNotifications($notifications);
140141

141142
$dpop = $this->getDpop();
142143

solid/lib/Controller/ContactsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use OCA\Solid\DpopFactoryTrait;
55
use OCA\Solid\PlainResponse;
6+
use OCA\Solid\Notifications\SolidNotifications;
67

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

132133
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
133-
$this->WAC = new WAC($this->filesystem);
134+
$this->WAC = new WAC($this->filesystem);
134135

135136
$request = $this->rawRequest;
136137
$baseUrl = $this->getContactsUrl($userId);
137138
$this->resourceServer->setBaseUrl($baseUrl);
138139
$this->WAC->setBaseUrl($baseUrl);
139-
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
140-
$this->resourceServer->setPubSubUrl($pubsub);
140+
$notifications = new SolidNotifications();
141+
$this->resourceServer->setNotifications($notifications);
141142

142143
$dpop = $this->getDpop();
143144

solid/lib/Controller/ProfileController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use OCA\Solid\DpopFactoryTrait;
55
use OCA\Solid\PlainResponse;
6+
use OCA\Solid\Notifications\SolidNotifications;
67

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

148149
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
149-
$this->WAC = new WAC($this->filesystem);
150+
$this->WAC = new WAC($this->filesystem);
150151

151152
$request = $this->rawRequest;
152153
$baseUrl = $this->getProfileUrl($userId);
153154
$this->resourceServer->setBaseUrl($baseUrl);
154155
$this->WAC->setBaseUrl($baseUrl);
155-
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
156-
$this->resourceServer->setPubSubUrl($pubsub);
156+
$notifications = new SolidNotifications();
157+
$this->resourceServer->setNotifications($notifications);
157158

158159
$dpop = $this->getDpop();
159160

0 commit comments

Comments
 (0)