mirror of https://github.com/nextcloud/calendar
use \OCP\IUserManager::getDisplayName
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
This commit is contained in:
parent
ce0420ada0
commit
732bf1aa64
|
@ -88,7 +88,7 @@ class AppointmentController extends Controller {
|
|||
'userInfo',
|
||||
[
|
||||
'uid' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
'displayName' => $this->userManager->getDisplayName($userId),
|
||||
]
|
||||
);
|
||||
$this->initialState->provideInitialState(
|
||||
|
@ -133,7 +133,7 @@ class AppointmentController extends Controller {
|
|||
'userInfo',
|
||||
[
|
||||
'uid' => $configOwner->getUID(),
|
||||
'displayName' => $configOwner->getDisplayName(),
|
||||
'displayName' => $this->userManager->getDisplayName($configOwner->getUID()),
|
||||
]
|
||||
);
|
||||
$this->initialState->provideInitialState(
|
||||
|
@ -150,7 +150,7 @@ class AppointmentController extends Controller {
|
|||
$this->initialState->provideInitialState(
|
||||
'visitorInfo',
|
||||
[
|
||||
'displayName' => $currentUser->getDisplayName(),
|
||||
'displayName' => $this->userManager->getDisplayName($this->userId),
|
||||
'email' => $currentUser->getEMailAddress(),
|
||||
]
|
||||
);
|
||||
|
|
|
@ -34,6 +34,7 @@ use OCP\IConfig;
|
|||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
use OCP\Mail\IMailer;
|
||||
|
@ -63,6 +64,9 @@ class EmailController extends Controller {
|
|||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/**
|
||||
* EmailController constructor.
|
||||
*
|
||||
|
@ -74,6 +78,7 @@ class EmailController extends Controller {
|
|||
* @param IL10N $l10N
|
||||
* @param Defaults $defaults
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param IUserManager $userManager
|
||||
*/
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
|
@ -82,7 +87,8 @@ class EmailController extends Controller {
|
|||
IMailer $mailer,
|
||||
IL10N $l10N,
|
||||
Defaults $defaults,
|
||||
IURLGenerator $urlGenerator) {
|
||||
IURLGenerator $urlGenerator,
|
||||
IUserManager $userManager) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
|
@ -90,6 +96,7 @@ class EmailController extends Controller {
|
|||
$this->l10n = $l10N;
|
||||
$this->defaults = $defaults;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +132,7 @@ class EmailController extends Controller {
|
|||
}
|
||||
|
||||
$fromAddress = $this->getFromAddress();
|
||||
$displayName = $user->getDisplayName();
|
||||
$displayName = $this->userManager->getDisplayName($user->getUID());
|
||||
$subject = $this->l10n->t('%s has published the calendar »%s«', [$displayName, $calendarName]);
|
||||
|
||||
$template = $this->createTemplate($subject, $displayName, $calendarName, $token);
|
||||
|
|
|
@ -103,8 +103,8 @@ class BookingCalendarWriter {
|
|||
if (!($calendar instanceof ICreateFromString)) {
|
||||
throw new RuntimeException('Could not find a public writable calendar for this principal');
|
||||
}
|
||||
|
||||
$organizer = $this->userManager->get($config->getUserId());
|
||||
$organizerId = $config->getUserId();
|
||||
$organizer = $this->userManager->get($organizerId);
|
||||
if ($organizer === null) {
|
||||
throw new RuntimeException('Organizer not registered user for this instance');
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class BookingCalendarWriter {
|
|||
'ORGANIZER',
|
||||
'mailto:' . $organizer->getEMailAddress(),
|
||||
[
|
||||
'CN' => $organizer->getDisplayName(),
|
||||
'CN' => $this->userManager->getDisplayName($organizerId),
|
||||
'CUTYPE' => 'INDIVIDUAL',
|
||||
'PARTSTAT' => 'ACCEPTED'
|
||||
]
|
||||
|
@ -139,7 +139,7 @@ class BookingCalendarWriter {
|
|||
'ATTENDEE',
|
||||
'mailto:' . $organizer->getEMailAddress(),
|
||||
[
|
||||
'CN' => $organizer->getDisplayName(),
|
||||
'CN' => $this->userManager->getDisplayName($organizerId),
|
||||
'CUTYPE' => 'INDIVIDUAL',
|
||||
'RSVP' => 'TRUE',
|
||||
'ROLE' => 'REQ-PARTICIPANT',
|
||||
|
|
|
@ -90,7 +90,9 @@ class MailService {
|
|||
* @throws ServiceException
|
||||
*/
|
||||
public function sendConfirmationEmail(Booking $booking, AppointmentConfig $config): void {
|
||||
$user = $this->userManager->get($config->getUserId());
|
||||
|
||||
$userId = $config->getUserId();
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
if ($user === null) {
|
||||
throw new ServiceException('Could not find organizer');
|
||||
|
@ -100,7 +102,7 @@ class MailService {
|
|||
if ($fromEmail === null) {
|
||||
throw new ServiceException('Organizer has no email set');
|
||||
}
|
||||
$fromName = $user->getDisplayName();
|
||||
$fromName = $this->userManager->getDisplayName($userId);
|
||||
|
||||
$sys = $this->getSysEmail();
|
||||
$message = $this->mailer->createMessage()
|
||||
|
@ -113,7 +115,7 @@ class MailService {
|
|||
$template->addHeader();
|
||||
|
||||
//Subject
|
||||
$subject = $this->l10n->t('Your appointment "%s" with %s needs confirmation', [$config->getName(), $user->getDisplayName()]);
|
||||
$subject = $this->l10n->t('Your appointment "%s" with %s needs confirmation', [$config->getName(), $this->userManager->getDisplayName($userId)]);
|
||||
$template->setSubject($subject);
|
||||
|
||||
// Heading
|
||||
|
@ -123,7 +125,7 @@ class MailService {
|
|||
$bookingUrl = $this->urlGenerator->linkToRouteAbsolute('calendar.booking.confirmBooking', ['token' => $booking->getToken()]);
|
||||
$template->addBodyButton($this->l10n->t('Confirm'), $bookingUrl);
|
||||
|
||||
$template->addBodyListItem($user->getDisplayName(), 'Appointment with:');
|
||||
$template->addBodyListItem($this->userManager->getDisplayName($userId), 'Appointment with:');
|
||||
if (!empty($config->getDescription())) {
|
||||
$template->addBodyListItem($config->getDescription(), 'Description:');
|
||||
}
|
||||
|
@ -163,7 +165,8 @@ class MailService {
|
|||
* @throws ServiceException
|
||||
*/
|
||||
public function sendBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar): void {
|
||||
$user = $this->userManager->get($config->getUserId());
|
||||
$userId = $config->getUserId();
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
if ($user === null) {
|
||||
throw new ServiceException('Could not find organizer');
|
||||
|
@ -173,7 +176,7 @@ class MailService {
|
|||
if ($fromEmail === null) {
|
||||
throw new ServiceException('Organizer has no email set');
|
||||
}
|
||||
$fromName = $user->getDisplayName();
|
||||
$fromName = $this->userManager->getDisplayName($userId);
|
||||
|
||||
$sys = $this->getSysEmail();
|
||||
$message = $this->mailer->createMessage()
|
||||
|
@ -186,14 +189,14 @@ class MailService {
|
|||
$template->addHeader();
|
||||
|
||||
// Subject
|
||||
$subject = $this->l10n->t('Your appointment "%s" with %s has been accepted', [$config->getName(), $user->getDisplayName()]);
|
||||
$subject = $this->l10n->t('Your appointment "%s" with %s has been accepted', [$config->getName(), $this->userManager->getDisplayName($userId)]);
|
||||
$template->setSubject($subject);
|
||||
|
||||
// Heading
|
||||
$summary = $this->l10n->t('Dear %s, your booking has been accepted.', [$booking->getDisplayName()]);
|
||||
$template->addHeading($summary);
|
||||
|
||||
$template->addBodyListItem($user->getDisplayName(), 'Appointment with:');
|
||||
$template->addBodyListItem($this->userManager->getDisplayName($userId), 'Appointment with:');
|
||||
if (!empty($config->getDescription())) {
|
||||
$template->addBodyListItem($config->getDescription(), 'Description:');
|
||||
}
|
||||
|
@ -272,8 +275,10 @@ class MailService {
|
|||
}
|
||||
|
||||
public function sendOrganizerBookingInformationEmail(Booking $booking, AppointmentConfig $config, string $calendar) {
|
||||
|
||||
$userId = $config->getUserId();
|
||||
/** @var IUser $user */
|
||||
$user = $this->userManager->get($config->getUserId());
|
||||
$user = $this->userManager->get($userId);
|
||||
|
||||
if ($user === null) {
|
||||
throw new ServiceException('Could not find organizer');
|
||||
|
@ -283,7 +288,7 @@ class MailService {
|
|||
if ($toEmail === null) {
|
||||
throw new ServiceException('Organizer has no email set');
|
||||
}
|
||||
$fromName = $user->getDisplayName();
|
||||
$fromName = $this->userManager->getDisplayName($userId);
|
||||
|
||||
$sys = $this->getSysEmail();
|
||||
$message = $this->mailer->createMessage()
|
||||
|
@ -299,7 +304,7 @@ class MailService {
|
|||
$template->setSubject($subject);
|
||||
|
||||
// Heading
|
||||
$summary = $this->l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$user->getDisplayName(), $booking->getDisplayName(), $booking->getEmail()]);
|
||||
$summary = $this->l10n->t('Dear %s, %s (%s) booked an appointment with you.', [$this->userManager->getDisplayName($userId), $booking->getDisplayName(), $booking->getEmail()]);
|
||||
$template->addHeading($summary);
|
||||
|
||||
$template->addBodyListItem($booking->getDisplayName() . ' (' . $booking->getEmail() . ')', 'Appointment with:');
|
||||
|
|
|
@ -31,6 +31,7 @@ use OCP\IL10N;
|
|||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
use OCP\Mail\IMailer;
|
||||
|
@ -65,6 +66,9 @@ class EmailControllerTest extends TestCase {
|
|||
/** @var IUser|MockObject */
|
||||
private $user;
|
||||
|
||||
/** @var IUserManager|MockObject */
|
||||
private $userManager;
|
||||
|
||||
/** @var EmailController */
|
||||
private $controller;
|
||||
|
||||
|
@ -79,9 +83,11 @@ class EmailControllerTest extends TestCase {
|
|||
$this->mailer = $this->createMock(IMailer::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
$this->user->method('getDisplayName')->willReturn('User Displayname 123');
|
||||
$this->user->method('getUID')->willReturn('123');
|
||||
$this->userManager->method('getDisplayName')->willReturn('User Displayname 123');
|
||||
|
||||
$this->l10n->expects($this->any())
|
||||
->method('t')
|
||||
|
@ -92,7 +98,8 @@ class EmailControllerTest extends TestCase {
|
|||
$this->controller = new EmailController($this->appName,
|
||||
$this->request, $this->userSession, $this->config,
|
||||
$this->mailer, $this->l10n, $this->defaults,
|
||||
$this->urlGenerator);
|
||||
$this->urlGenerator,
|
||||
$this->userManager);
|
||||
}
|
||||
|
||||
public function testSendUserSessionExpired():void {
|
||||
|
|
|
@ -120,9 +120,11 @@ class MailServiceTest extends TestCase {
|
|||
$this->userManager->expects(self::once())
|
||||
->method('get')
|
||||
->willReturn($this->createConfiguredMock(IUser::class, [
|
||||
'getEmailAddress' => 'test@test.com',
|
||||
'getDisplayName' => 'Test Test'
|
||||
'getEmailAddress' => 'test@test.com'
|
||||
]));
|
||||
$this->userManager->expects(self::exactly(3))
|
||||
->method('getDisplayName')
|
||||
->willReturn('Test Test');
|
||||
$mailMessage = $this->createMock(IMessage::class);
|
||||
$this->mailer->expects(self::once())
|
||||
->method('createMessage')
|
||||
|
@ -208,6 +210,9 @@ class MailServiceTest extends TestCase {
|
|||
'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')
|
||||
|
@ -275,9 +280,11 @@ class MailServiceTest extends TestCase {
|
|||
$this->userManager->expects(self::once())
|
||||
->method('get')
|
||||
->willReturn($this->createConfiguredMock(IUser::class, [
|
||||
'getEmailAddress' => 'test@test.com',
|
||||
'getDisplayName' => 'Test Test'
|
||||
'getEmailAddress' => 'test@test.com'
|
||||
]));
|
||||
$this->userManager->expects(self::exactly(3))
|
||||
->method('getDisplayName')
|
||||
->willReturn('Test Test');
|
||||
$mailMessage = $this->createMock(IMessage::class);
|
||||
$this->mailer->expects(self::once())
|
||||
->method('createMessage')
|
||||
|
@ -349,9 +356,11 @@ class MailServiceTest extends TestCase {
|
|||
$this->userManager->expects(self::once())
|
||||
->method('get')
|
||||
->willReturn($this->createConfiguredMock(IUser::class, [
|
||||
'getEmailAddress' => 'test@test.com',
|
||||
'getDisplayName' => 'Test Test'
|
||||
'getEmailAddress' => 'test@test.com'
|
||||
]));
|
||||
$this->userManager->expects(self::exactly(3))
|
||||
->method('getDisplayName')
|
||||
->willReturn('Test Test');
|
||||
$mailMessage = $this->createMock(IMessage::class);
|
||||
$this->mailer->expects(self::once())
|
||||
->method('createMessage')
|
||||
|
@ -422,9 +431,11 @@ class MailServiceTest extends TestCase {
|
|||
$this->userManager->expects(self::once())
|
||||
->method('get')
|
||||
->willReturn($this->createConfiguredMock(IUser::class, [
|
||||
'getEmailAddress' => 'test@test.com',
|
||||
'getDisplayName' => 'Test Test'
|
||||
'getEmailAddress' => 'test@test.com'
|
||||
]));
|
||||
$this->userManager->expects(self::exactly(3))
|
||||
->method('getDisplayName')
|
||||
->willReturn('Test Test');
|
||||
$mailMessage = $this->createMock(IMessage::class);
|
||||
$this->mailer->expects(self::once())
|
||||
->method('createMessage')
|
||||
|
|
Loading…
Reference in New Issue