Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable4.7] fix(appointments): Set organiser email to correct langauge #6158

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/Service/Appointments/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\Calendar\Db\Booking;
use OCA\Calendar\Exception\ServiceException;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -72,7 +73,8 @@ public function __construct(IMailer $mailer,
IURLGenerator $urlGenerator,
IDateTimeFormatter $dateFormatter,
IFactory $lFactory,
IManager $notificationManager) {
IManager $notificationManager,
private IConfig $userConfig) {
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->l10n = $l10n;
Expand Down Expand Up @@ -230,7 +232,7 @@ public function sendBookingInformationEmail(Booking $booking, AppointmentConfig
private function addBulletList(IEMailTemplate $template,
IL10N $l10n,
Booking $booking,
AppointmentConfig $config):void {
AppointmentConfig $config): void {
$template->addBodyListItem($booking->getDisplayName(), $l10n->t('Appointment for:'));

$l = $this->lFactory->findGenericLanguage();
Expand Down Expand Up @@ -272,10 +274,9 @@ private function getSysEmail(): string {
return \OCP\Util::getDefaultEmailAddress('appointments-noreply');
}

public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar) {
public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar): void {
/** @var IUser $user */
$user = $this->userManager->get($config->getUserId());

if ($user === null) {
throw new ServiceException('Could not find organizer');
}
Expand All @@ -295,12 +296,14 @@ public function sendOrganizerBookingInformationEmail(Booking $booking, Appointme
$template = $this->mailer->createEMailTemplate('calendar.confirmOrganizer');
$template->addHeader();

$lang = $this->userConfig->getUserValue($user->getUID(), 'core', 'lang', null);
$l10n = $this->lFactory->get('calendar', $lang);
// Subject
$subject = $this->l10n->t('You have a new appointment booking "%s" from %s', [$config->getName(), $booking->getDisplayName()]);
$subject = $l10n->t('You have a new appointment booking "%s" from %s', [$config->getName(), $booking->getDisplayName()]);
$template->setSubject($subject);

// Heading
$summary = $this->l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$user->getDisplayName(), $booking->getDisplayName(), $booking->getEmail()]);
$summary = $l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$user->getDisplayName(), $booking->getDisplayName(), $booking->getEmail()]);
$template->addHeading($summary);

$template->addBodyListItem($booking->getDisplayName() . ' (' . $booking->getEmail() . ')', 'Appointment with:');
Expand All @@ -309,7 +312,7 @@ public function sendOrganizerBookingInformationEmail(Booking $booking, Appointme
}

// Create Booking overview
$this->addBulletList($template, $this->l10n, $booking, $config);
$this->addBulletList($template, $l10n, $booking, $config);
$template->addFooter();

$attachment = $this->mailer->createAttachment($calendar, 'appointment.ics', 'text/calendar');
Expand Down
20 changes: 16 additions & 4 deletions tests/php/unit/Service/Appointments/MailServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\Calendar\Service\Appointments\MailService;
use OCP\Calendar\ICalendarQuery;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IUser;
Expand Down Expand Up @@ -77,6 +78,7 @@ class MailServiceTest extends TestCase {

/** @var MailService */
private $mailService;
private IConfig|MockObject $userConfig;

protected function setUp(): void {
parent::setUp();
Expand All @@ -94,6 +96,7 @@ protected function setUp(): void {
$this->dateFormatter = $this->createMock(IDateTimeFormatter::class);
$this->lFactory = $this->createMock(IFactory::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->userConfig = $this->createMock(IConfig::class);
$this->mailService = new MailService(
$this->mailer,
$this->userManager,
Expand All @@ -104,6 +107,7 @@ protected function setUp(): void {
$this->dateFormatter,
$this->lFactory,
$this->notificationManager,
$this->userConfig
);
}

Expand Down Expand Up @@ -528,6 +532,9 @@ public function testSendOrganizerBookingInformationEmail(): void {
$this->mailer->expects(self::once())
->method('createEmailTemplate')
->willReturn($emailTemplate);
$this->userConfig->expects(self::once())
->method('getUserValue')
->willReturn('en');
$emailTemplate->expects(self::once())
->method('addHeader');
$emailTemplate->expects(self::once())
Expand All @@ -547,8 +554,9 @@ public function testSendOrganizerBookingInformationEmail(): void {
$this->lFactory->expects(self::once())
->method('findGenericLanguage')
->willReturn('en');
$this->lFactory->expects(self::once())
->method('get');
$this->lFactory->expects(self::exactly(2))
->method('get')
->willReturn($this->l10n);
$this->dateFormatter->expects(self::once())
->method('formatDateTimeRelativeDay')
->willReturn('Test');
Expand Down Expand Up @@ -583,6 +591,9 @@ public function testSendOrganizerBookingInformationEmailFailed(): void {
$this->mailer->expects(self::once())
->method('createMessage')
->willReturn($mailMessage);
$this->userConfig->expects(self::once())
->method('getUserValue')
->willReturn('en');
$mailMessage->expects(self::once())
->method('setFrom')
->willReturn($mailMessage);
Expand Down Expand Up @@ -615,8 +626,9 @@ public function testSendOrganizerBookingInformationEmailFailed(): void {
$this->lFactory->expects(self::once())
->method('findGenericLanguage')
->willReturn('en');
$this->lFactory->expects(self::once())
->method('get');
$this->lFactory->expects(self::exactly(2))
->method('get')
->willReturn($this->l10n);
$this->dateFormatter->expects(self::once())
->method('formatDateTimeRelativeDay')
->willReturn('Test');
Expand Down
Loading