Skip to content

Commit 5806dfb

Browse files
Merge pull request #55473 from nextcloud/fix/imip-set-language-by-user
fix(CalDAV): imip set language per user
2 parents 045dc79 + 345140a commit 5806dfb

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function schedule(Message $iTipMessage) {
167167
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
168168
return;
169169
}
170-
$this->imipService->setL10n($attendee);
170+
$this->imipService->setL10nFromAttendee($attendee);
171171

172172
// Build the sender name.
173173
// Due to a bug in sabre, the senderName property for an iTIP message can actually also be a VObject Property

apps/dav/lib/CalDAV/Schedule/IMipService.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\IConfig;
1515
use OCP\IDBConnection;
1616
use OCP\IL10N;
17+
use OCP\IUserManager;
1718
use OCP\L10N\IFactory as L10NFactory;
1819
use OCP\Mail\IEMailTemplate;
1920
use OCP\Security\ISecureRandom;
@@ -44,6 +45,7 @@ public function __construct(
4445
private ISecureRandom $random,
4546
private L10NFactory $l10nFactory,
4647
private ITimeFactory $timeFactory,
48+
private readonly IUserManager $userManager,
4749
) {
4850
$language = $this->l10nFactory->findGenericLanguage();
4951
$locale = $this->l10nFactory->findLocale($language);
@@ -870,18 +872,35 @@ public function getLastOccurrence(VCalendar $vObject) {
870872
}
871873

872874
/**
873-
* @param Property|null $attendee
875+
* @param Property $attendee
874876
*/
875-
public function setL10n(?Property $attendee = null) {
876-
if ($attendee === null) {
877-
return;
877+
public function setL10nFromAttendee(Property $attendee) {
878+
$language = null;
879+
$locale = null;
880+
// check if the attendee is a system user
881+
$userAddress = $attendee->getValue();
882+
if (str_starts_with($userAddress, 'mailto:')) {
883+
$userAddress = substr($userAddress, 7);
878884
}
879-
880-
$lang = $attendee->offsetGet('LANGUAGE');
881-
if ($lang instanceof Parameter) {
882-
$lang = $lang->getValue();
883-
$this->l10n = $this->l10nFactory->get('dav', $lang);
885+
$users = $this->userManager->getByEmail($userAddress);
886+
if ($users !== []) {
887+
$user = array_shift($users);
888+
$language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
889+
$locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
884890
}
891+
// fallback to attendee LANGUAGE parameter if language not set
892+
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
893+
$language = $attendee['LANGUAGE']->getValue();
894+
}
895+
// fallback to system language if language not set
896+
if ($language === null) {
897+
$language = $this->l10nFactory->findGenericLanguage();
898+
}
899+
// fallback to system locale if locale not set
900+
if ($locale === null) {
901+
$locale = $this->l10nFactory->findLocale($language);
902+
}
903+
$this->l10n = $this->l10nFactory->get('dav', $language, $locale);
885904
}
886905

887906
/**

apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCP\IDBConnection;
2121
use OCP\IURLGenerator;
2222
use OCP\IUser;
23+
use OCP\IUserManager;
2324
use OCP\IUserSession;
2425
use OCP\L10N\IFactory;
2526
use OCP\Mail\IMailer;
@@ -55,6 +56,7 @@ class IMipPluginCharsetTest extends TestCase {
5556
private IUrlGenerator&MockObject $urlGenerator;
5657
private IUserSession&MockObject $userSession;
5758
private LoggerInterface $logger;
59+
private IUserManager&MockObject $userManager;
5860

5961
// Services
6062
private EventComparisonService $eventComparisonService;
@@ -86,13 +88,16 @@ protected function setUp(): void {
8688
->willReturn('en_US');
8789
$this->l10nFactory->method('get')
8890
->willReturn($l10n);
91+
$this->userManager = $this->createMock(IUserManager::class);
92+
$this->userManager->method('getByEmail')->willReturn([]);
8993
$this->imipService = new IMipService(
9094
$this->urlGenerator,
9195
$this->config,
9296
$this->db,
9397
$this->random,
9498
$this->l10nFactory,
9599
$this->timeFactory,
100+
$this->userManager
96101
);
97102

98103
// EventComparisonService

apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\IConfig;
1717
use OCP\IDBConnection;
1818
use OCP\IL10N;
19+
use OCP\IUserManager;
1920
use OCP\L10N\IFactory;
2021
use OCP\Security\ISecureRandom;
2122
use PHPUnit\Framework\MockObject\MockObject;
@@ -32,6 +33,7 @@ class IMipServiceTest extends TestCase {
3233
private IL10N&MockObject $l10n;
3334
private ITimeFactory&MockObject $timeFactory;
3435
private IMipService $service;
36+
private IUserManager&MockObject $userManager;
3537

3638

3739
private VCalendar $vCalendar1a;
@@ -51,6 +53,7 @@ protected function setUp(): void {
5153
$this->l10nFactory = $this->createMock(IFactory::class);
5254
$this->l10n = $this->createMock(IL10N::class);
5355
$this->timeFactory = $this->createMock(ITimeFactory::class);
56+
$this->userManager = $this->createMock(IUserManager::class);
5457
$this->l10nFactory->expects(self::once())
5558
->method('findGenericLanguage')
5659
->willReturn('en');
@@ -64,7 +67,8 @@ protected function setUp(): void {
6467
$this->db,
6568
$this->random,
6669
$this->l10nFactory,
67-
$this->timeFactory
70+
$this->timeFactory,
71+
$this->userManager
6872
);
6973

7074
// construct calendar with a 1 hour event and same start/end time zones

0 commit comments

Comments
 (0)