From 0b32626fadaadaadb9fe3b55b7c09e90c602b7c9 Mon Sep 17 00:00:00 2001 From: Vladimir Babin Date: Sun, 13 Sep 2026 17:44:25 +0300 Subject: [PATCH] fix(events): serialize nested entities in webhook payloads Webhook filters on nested relations (e.g. event.card.labels.title) failed because getWebhookSerializable() returned Label/Assignment objects inside the card array, which PHPMongoQuery cannot traverse. Serialize the card and acl through json_encode/json_decode so the payload is plain arrays. Resolves: #8245 Signed-off-by: Vladimir Babin --- lib/Event/AAclEvent.php | 2 +- lib/Event/ACardEvent.php | 2 +- .../Event/WebhookCompatibleEventsTest.php | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Event/AAclEvent.php b/lib/Event/AAclEvent.php index c649463f87..af35e89a73 100644 --- a/lib/Event/AAclEvent.php +++ b/lib/Event/AAclEvent.php @@ -32,7 +32,7 @@ public function getBoardId(): int { public function getWebhookSerializable(): array { return [ - 'acl' => $this->acl->jsonSerialize(), + 'acl' => json_decode(json_encode($this->acl), true), ]; } } diff --git a/lib/Event/ACardEvent.php b/lib/Event/ACardEvent.php index 475560fbfb..da95f16858 100644 --- a/lib/Event/ACardEvent.php +++ b/lib/Event/ACardEvent.php @@ -28,7 +28,7 @@ public function getCard(): Card { public function getWebhookSerializable(): array { return [ - 'card' => $this->card->jsonSerialize(), + 'card' => json_decode(json_encode($this->card), true), ]; } } diff --git a/tests/unit/Event/WebhookCompatibleEventsTest.php b/tests/unit/Event/WebhookCompatibleEventsTest.php index ab856e5ec2..46958990d4 100644 --- a/tests/unit/Event/WebhookCompatibleEventsTest.php +++ b/tests/unit/Event/WebhookCompatibleEventsTest.php @@ -11,6 +11,7 @@ use OCA\Deck\Db\Acl; use OCA\Deck\Db\Card; +use OCA\Deck\Db\Label; use OCP\EventDispatcher\IWebhookCompatibleEvent; use Test\TestCase; @@ -30,6 +31,25 @@ public function testCardEventIsWebhookCompatible(): void { $this->assertSame('Test card', $payload['card']['title']); } + public function testCardEventSerializesNestedEntitiesAsArrays(): void { + $label = new Label(); + $label->setId(5); + $label->setTitle('foo'); + $label->setColor('ff0000'); + + $card = new Card(); + $card->setId(42); + $card->setTitle('Test card'); + $card->setStackId(1); + $card->setLabels([$label]); + + $payload = (new CardUpdatedEvent($card))->getWebhookSerializable(); + + $this->assertIsArray($payload['card']['labels'][0]); + $this->assertSame(5, $payload['card']['labels'][0]['id']); + $this->assertSame('foo', $payload['card']['labels'][0]['title']); + } + public function testAclEventIsWebhookCompatible(): void { $acl = new Acl(); $acl->setId(7);