Skip to content

Commit a5ea525

Browse files
committed
fix(notifications): Use the target id in guest conversion notifications
The rich object describing the converted-to account fell back to the guest id when the target account could not be resolved, so a failed conversion reported the guest twice instead of naming the account it was supposed to become. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent 2e92437 commit a5ea525

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

lib/Notifications/Notifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function getRichMessageParams(string $source, string $target): array {
4949
],
5050
'user' => [
5151
'type' => $targetUser ? 'user' : 'highlight',
52-
'id' => $targetUser?->getUID() ?? $source,
52+
'id' => $targetUser?->getUID() ?? $target,
5353
'name' => $targetUser?->getDisplayName() ?? $target,
5454
],
5555
];
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Guests\Test\Unit\Notifications;
10+
11+
use OCA\Guests\Notifications\Notifier;
12+
use OCP\IL10N;
13+
use OCP\IURLGenerator;
14+
use OCP\IUserManager;
15+
use OCP\L10N\IFactory;
16+
use OCP\Notification\INotification;
17+
use Test\TestCase;
18+
19+
class NotifierTest extends TestCase {
20+
private ?Notifier $notifier = null;
21+
22+
protected function setUp(): void {
23+
parent::setUp();
24+
25+
$l10n = $this->createMock(IL10N::class);
26+
$l10n->method('t')
27+
->willReturnArgument(0);
28+
$l10nFactory = $this->createMock(IFactory::class);
29+
$l10nFactory->method('get')
30+
->willReturn($l10n);
31+
32+
// Both accounts are gone by the time the notification is rendered.
33+
$userManager = $this->createMock(IUserManager::class);
34+
$userManager->method('get')
35+
->willReturn(null);
36+
37+
$this->notifier = new Notifier(
38+
$l10nFactory,
39+
$this->createMock(IURLGenerator::class),
40+
$userManager
41+
);
42+
}
43+
44+
public function testTransferDoneFallsBackToTheNotifiedIds(): void {
45+
$parameters = $this->prepareTransferNotification('guest-transfer-done');
46+
47+
$this->assertSame('guest@example.tld', $parameters['guest']['id']);
48+
$this->assertSame('new_account', $parameters['user']['id']);
49+
}
50+
51+
public function testTransferFailFallsBackToTheNotifiedIds(): void {
52+
$parameters = $this->prepareTransferNotification('guest-transfer-fail');
53+
54+
$this->assertSame('guest@example.tld', $parameters['guest']['id']);
55+
$this->assertSame('new_account', $parameters['user']['id']);
56+
}
57+
58+
/**
59+
* @return array<string, array<string, mixed>>
60+
*/
61+
private function prepareTransferNotification(string $subject): array {
62+
$notification = $this->createMock(INotification::class);
63+
$notification->method('getApp')
64+
->willReturn('guests');
65+
$notification->method('getSubject')
66+
->willReturn($subject);
67+
$notification->method('getSubjectParameters')
68+
->willReturn([
69+
'source' => 'guest@example.tld',
70+
'target' => 'new_account',
71+
]);
72+
$notification->method('setRichSubject')
73+
->willReturnSelf();
74+
75+
$parameters = [];
76+
$notification->expects($this->once())
77+
->method('setRichMessage')
78+
->willReturnCallback(function (string $message, array $messageParameters) use (&$parameters, $notification): INotification {
79+
$parameters = $messageParameters;
80+
return $notification;
81+
});
82+
83+
$this->notifier->prepare($notification, 'en');
84+
85+
return $parameters;
86+
}
87+
}

0 commit comments

Comments
 (0)