From 0ffde47432c99f1fbb28cd77ca877089841ed848 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 Nov 2026 12:51:36 +0100 Subject: [PATCH] fix(notification): Clone actions when cloning notification Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Joas Schilling --- lib/private/Notification/Notification.php | 5 +++++ tests/lib/Notification/NotificationTest.php | 23 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index f8f1e2478547c..8613a8a30b13b 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -55,6 +55,11 @@ public function __construct( $this->dateTime->setTimestamp(0); } + public function __clone() { + $this->actions = array_map(static fn (IAction $action): IAction => clone $action, $this->actions); + $this->actionsParsed = array_map(static fn (IAction $action): IAction => clone $action, $this->actionsParsed); + } + /** * {@inheritDoc} */ diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php index 957d74233be01..b123d57babad0 100644 --- a/tests/lib/Notification/NotificationTest.php +++ b/tests/lib/Notification/NotificationTest.php @@ -9,6 +9,7 @@ namespace Test\Notification; +use OC\Notification\Action; use OC\Notification\Notification; use OCP\Notification\IAction; use OCP\Notification\INotification; @@ -642,4 +643,26 @@ public function testIsValidCommon($app, $user, $timestamp, $objectType, $objectI $this->assertEquals($expected, $this->invokePrivate($notification, 'isValidCommon')); } + + public function testCloneDoesNotShareActions(): void { + $action = new Action(); + $action->setLabel('accept') + ->setLink('https://example.tld/accept', 'POST'); + $this->notification->addAction($action); + + $parsedAction = new Action(); + $parsedAction->setLabel('decline') + ->setParsedLabel('Decline') + ->setLink('https://example.tld/decline', 'POST'); + $this->notification->addParsedAction($parsedAction); + + $clone = clone $this->notification; + $clone->getActions()[0]->setParsedLabel('Accept'); + $clone->getParsedActions()[0]->setParsedLabel('Ablehnen'); + + $this->assertSame('', $action->getParsedLabel()); + $this->assertSame('Decline', $parsedAction->getParsedLabel()); + $this->assertSame('Accept', $clone->getActions()[0]->getParsedLabel()); + $this->assertSame('Ablehnen', $clone->getParsedActions()[0]->getParsedLabel()); + } }