Skip to content

Commit

Permalink
revert unecessary refactoring of getDisplayName()
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Oct 6, 2023
1 parent b7423aa commit 8bbf4d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
7 changes: 3 additions & 4 deletions lib/Service/Appointments/BookingCalendarWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public function write(AppointmentConfig $config,
if (!($calendar instanceof ICreateFromString)) {
throw new RuntimeException('Could not find a public writable calendar for this principal');
}
$organizerId = $config->getUserId();
$organizer = $this->userManager->get($organizerId);
$organizer = $this->userManager->get($config->getUserId());
if ($organizer === null) {
throw new RuntimeException('Organizer not registered user for this instance');
}
Expand All @@ -129,7 +128,7 @@ public function write(AppointmentConfig $config,
'ORGANIZER',
'mailto:' . $organizer->getEMailAddress(),
[
'CN' => $this->userManager->getDisplayName($organizerId),
'CN' => $organizer->getDisplayName(),
'CUTYPE' => 'INDIVIDUAL',
'PARTSTAT' => 'ACCEPTED'
]
Expand All @@ -139,7 +138,7 @@ public function write(AppointmentConfig $config,
'ATTENDEE',
'mailto:' . $organizer->getEMailAddress(),
[
'CN' => $this->userManager->getDisplayName($organizerId),
'CN' => $organizer->getDisplayName(),
'CUTYPE' => 'INDIVIDUAL',
'RSVP' => 'TRUE',
'ROLE' => 'REQ-PARTICIPANT',
Expand Down
26 changes: 11 additions & 15 deletions lib/Service/Appointments/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public function __construct(IMailer $mailer,
*/
public function sendConfirmationEmail(Booking $booking, AppointmentConfig $config): void {

$userId = $config->getUserId();
$user = $this->userManager->get($userId);
$user = $this->userManager->get($config->getUserId());

if ($user === null) {
throw new ServiceException('Could not find organizer');
Expand All @@ -102,7 +101,7 @@ public function sendConfirmationEmail(Booking $booking, AppointmentConfig $confi
if ($fromEmail === null) {
throw new ServiceException('Organizer has no email set');
}
$fromName = $this->userManager->getDisplayName($userId);
$fromName = $user->getDisplayName();

$sys = $this->getSysEmail();
$message = $this->mailer->createMessage()
Expand All @@ -115,7 +114,7 @@ public function sendConfirmationEmail(Booking $booking, AppointmentConfig $confi
$template->addHeader();

//Subject
$subject = $this->l10n->t('Your appointment "%s" with %s needs confirmation', [$config->getName(), $this->userManager->getDisplayName($userId)]);
$subject = $this->l10n->t('Your appointment "%s" with %s needs confirmation', [$config->getName(), $user->getDisplayName()]);
$template->setSubject($subject);

// Heading
Expand All @@ -125,7 +124,7 @@ public function sendConfirmationEmail(Booking $booking, AppointmentConfig $confi
$bookingUrl = $this->urlGenerator->linkToRouteAbsolute('calendar.booking.confirmBooking', ['token' => $booking->getToken()]);
$template->addBodyButton($this->l10n->t('Confirm'), $bookingUrl);

$template->addBodyListItem($this->userManager->getDisplayName($userId), 'Appointment with:');
$template->addBodyListItem($user->getDisplayName(), 'Appointment with:');
if (!empty($config->getDescription())) {
$template->addBodyListItem($config->getDescription(), 'Description:');
}
Expand Down Expand Up @@ -165,8 +164,7 @@ public function sendConfirmationEmail(Booking $booking, AppointmentConfig $confi
* @throws ServiceException
*/
public function sendBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar): void {
$userId = $config->getUserId();
$user = $this->userManager->get($userId);
$user = $this->userManager->get($config->getUserId());

if ($user === null) {
throw new ServiceException('Could not find organizer');
Expand All @@ -176,7 +174,7 @@ public function sendBookingInformationEmail(Booking $booking, AppointmentConfig
if ($fromEmail === null) {
throw new ServiceException('Organizer has no email set');
}
$fromName = $this->userManager->getDisplayName($userId);
$fromName = $user->getDisplayName();

$sys = $this->getSysEmail();
$message = $this->mailer->createMessage()
Expand All @@ -189,14 +187,14 @@ public function sendBookingInformationEmail(Booking $booking, AppointmentConfig
$template->addHeader();

// Subject
$subject = $this->l10n->t('Your appointment "%s" with %s has been accepted', [$config->getName(), $this->userManager->getDisplayName($userId)]);
$subject = $this->l10n->t('Your appointment "%s" with %s has been accepted', [$config->getName(), $user->getDisplayName()]);
$template->setSubject($subject);

// Heading
$summary = $this->l10n->t('Dear %s, your booking has been accepted.', [$booking->getDisplayName()]);
$template->addHeading($summary);

$template->addBodyListItem($this->userManager->getDisplayName($userId), 'Appointment with:');
$template->addBodyListItem($user->getDisplayName(), 'Appointment with:');
if (!empty($config->getDescription())) {
$template->addBodyListItem($config->getDescription(), 'Description:');
}
Expand Down Expand Up @@ -275,10 +273,8 @@ private function getSysEmail(): string {
}

public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar) {

$userId = $config->getUserId();
/** @var IUser $user */
$user = $this->userManager->get($userId);
$user = $this->userManager->get($config->getUserId());

if ($user === null) {
throw new ServiceException('Could not find organizer');
Expand All @@ -288,7 +284,7 @@ public function sendOrganizerBookingInformationEmail(Booking $booking, Appointme
if ($toEmail === null) {
throw new ServiceException('Organizer has no email set');
}
$fromName = $this->userManager->getDisplayName($userId);
$fromName = $user->getDisplayName();

$sys = $this->getSysEmail();
$message = $this->mailer->createMessage()
Expand All @@ -304,7 +300,7 @@ public function sendOrganizerBookingInformationEmail(Booking $booking, Appointme
$template->setSubject($subject);

// Heading
$summary = $this->l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$this->userManager->getDisplayName($userId), $booking->getDisplayName(), $booking->getEmail()]);
$summary = $this->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 Down
27 changes: 8 additions & 19 deletions tests/php/unit/Service/Appointments/MailServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ public function testSendConfirmationEmail(): void {
$this->userManager->expects(self::once())
->method('get')
->willReturn($this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'test@test.com'
'getEmailAddress' => 'test@test.com',
'getDisplayName' => 'Test Test'
]));
$this->userManager->expects(self::exactly(3))
->method('getDisplayName')
->willReturn('Test Test');
$mailMessage = $this->createMock(IMessage::class);
$this->mailer->expects(self::once())
->method('createMessage')
Expand Down Expand Up @@ -210,9 +208,6 @@ public function testSendConfirmationEmailMailerException(): void {
'getEmailAddress' => 'test@test.com',
'getDisplayName' => 'Test Test'
]));
$this->userManager->expects(self::exactly(3))
->method('getDisplayName')
->willReturn('Test Test');
$mailMessage = $this->createMock(IMessage::class);
$this->mailer->expects(self::once())
->method('createMessage')
Expand Down Expand Up @@ -280,11 +275,9 @@ public function testSendConfirmationEmailMailerFailed(): void {
$this->userManager->expects(self::once())
->method('get')
->willReturn($this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'test@test.com'
'getEmailAddress' => 'test@test.com',
'getDisplayName' => 'Test Test'
]));
$this->userManager->expects(self::exactly(3))
->method('getDisplayName')
->willReturn('Test Test');
$mailMessage = $this->createMock(IMessage::class);
$this->mailer->expects(self::once())
->method('createMessage')
Expand Down Expand Up @@ -356,11 +349,9 @@ public function testSendBookingInformationEmail(): void {
$this->userManager->expects(self::once())
->method('get')
->willReturn($this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'test@test.com'
'getEmailAddress' => 'test@test.com',
'getDisplayName' => 'Test Test'
]));
$this->userManager->expects(self::exactly(3))
->method('getDisplayName')
->willReturn('Test Test');
$mailMessage = $this->createMock(IMessage::class);
$this->mailer->expects(self::once())
->method('createMessage')
Expand Down Expand Up @@ -431,11 +422,9 @@ public function testSendBookingInformationEmailFailed(): void {
$this->userManager->expects(self::once())
->method('get')
->willReturn($this->createConfiguredMock(IUser::class, [
'getEmailAddress' => 'test@test.com'
'getEmailAddress' => 'test@test.com',
'getDisplayName' => 'Test Test'
]));
$this->userManager->expects(self::exactly(3))
->method('getDisplayName')
->willReturn('Test Test');
$mailMessage = $this->createMock(IMessage::class);
$this->mailer->expects(self::once())
->method('createMessage')
Expand Down

0 comments on commit 8bbf4d2

Please sign in to comment.