Skip to content

Commit 3202a3f

Browse files
authored
Merge pull request #7910 from cbcoutinho/feat/webhook-compatible-events
feat(events): make card, ACL and board events webhook-compatible
2 parents 2e28dcf + d85e1c8 commit 3202a3f

4 files changed

Lines changed: 81 additions & 3 deletions

File tree

lib/Event/AAclEvent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
use OCA\Deck\Db\Acl;
1414
use OCP\EventDispatcher\Event;
15+
use OCP\EventDispatcher\IWebhookCompatibleEvent;
1516

16-
abstract class AAclEvent extends Event {
17+
abstract class AAclEvent extends Event implements IWebhookCompatibleEvent {
1718
private $acl;
1819

1920
public function __construct(Acl $acl) {
@@ -29,4 +30,10 @@ public function getAcl(): Acl {
2930
public function getBoardId(): int {
3031
return $this->acl->getBoardId();
3132
}
33+
34+
public function getWebhookSerializable(): array {
35+
return [
36+
'acl' => $this->acl->jsonSerialize(),
37+
];
38+
}
3239
}

lib/Event/ACardEvent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
use OCA\Deck\Db\Card;
1414
use OCP\EventDispatcher\Event;
15+
use OCP\EventDispatcher\IWebhookCompatibleEvent;
1516

16-
abstract class ACardEvent extends Event {
17+
abstract class ACardEvent extends Event implements IWebhookCompatibleEvent {
1718
private $card;
1819

1920
public function __construct(Card $card) {
@@ -25,4 +26,10 @@ public function __construct(Card $card) {
2526
public function getCard(): Card {
2627
return $this->card;
2728
}
29+
30+
public function getWebhookSerializable(): array {
31+
return [
32+
'card' => $this->card->jsonSerialize(),
33+
];
34+
}
2835
}

lib/Event/BoardUpdatedEvent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
namespace OCA\Deck\Event;
1212

1313
use OCP\EventDispatcher\Event;
14+
use OCP\EventDispatcher\IWebhookCompatibleEvent;
1415

15-
class BoardUpdatedEvent extends Event {
16+
class BoardUpdatedEvent extends Event implements IWebhookCompatibleEvent {
1617
private $boardId;
1718

1819
public function __construct(int $boardId) {
@@ -24,4 +25,10 @@ public function __construct(int $boardId) {
2425
public function getBoardId(): int {
2526
return $this->boardId;
2627
}
28+
29+
public function getWebhookSerializable(): array {
30+
return [
31+
'boardId' => $this->boardId,
32+
];
33+
}
2734
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OCA\Deck\Event;
11+
12+
use OCA\Deck\Db\Acl;
13+
use OCA\Deck\Db\Card;
14+
use OCP\EventDispatcher\IWebhookCompatibleEvent;
15+
use Test\TestCase;
16+
17+
class WebhookCompatibleEventsTest extends TestCase {
18+
public function testCardEventIsWebhookCompatible(): void {
19+
$card = new Card();
20+
$card->setId(42);
21+
$card->setTitle('Test card');
22+
$card->setStackId(1);
23+
24+
$event = new CardCreatedEvent($card);
25+
26+
$this->assertInstanceOf(IWebhookCompatibleEvent::class, $event);
27+
$payload = $event->getWebhookSerializable();
28+
$this->assertArrayHasKey('card', $payload);
29+
$this->assertSame(42, $payload['card']['id']);
30+
$this->assertSame('Test card', $payload['card']['title']);
31+
}
32+
33+
public function testAclEventIsWebhookCompatible(): void {
34+
$acl = new Acl();
35+
$acl->setId(7);
36+
$acl->setBoardId(3);
37+
$acl->setType(Acl::PERMISSION_TYPE_USER);
38+
$acl->setParticipant('alice');
39+
$acl->setPermissionEdit(true);
40+
41+
$event = new AclCreatedEvent($acl);
42+
43+
$this->assertInstanceOf(IWebhookCompatibleEvent::class, $event);
44+
$payload = $event->getWebhookSerializable();
45+
$this->assertArrayHasKey('acl', $payload);
46+
$this->assertSame(7, $payload['acl']['id']);
47+
$this->assertSame(3, $payload['acl']['boardId']);
48+
$this->assertArrayNotHasKey('token', $payload['acl'], 'token must be stripped from serialized ACL');
49+
}
50+
51+
public function testBoardUpdatedEventIsWebhookCompatible(): void {
52+
$event = new BoardUpdatedEvent(99);
53+
54+
$this->assertInstanceOf(IWebhookCompatibleEvent::class, $event);
55+
$this->assertSame(['boardId' => 99], $event->getWebhookSerializable());
56+
}
57+
}

0 commit comments

Comments
 (0)