From fc0bed9ec88e3d0f0a2be8b36984cd0501a1caaf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 29 Mar 2021 10:39:58 +0200 Subject: [PATCH] Extend reasons for email address Signed-off-by: Joas Schilling --- lib/Notification/Notifier.php | 25 ++++++++++++++++--------- tests/Notification/NotifierTest.php | 5 ++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index cf6a5deb9..af2230ef8 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -22,12 +22,14 @@ namespace OCA\FirstRunWizard\Notification; +use OCP\IConfig; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; +use OCP\User\Backend\ISetPasswordBackend; class Notifier implements INotifier { @@ -43,17 +45,19 @@ class Notifier implements INotifier { /** @var IURLGenerator */ protected $url; - /** - * @param IFactory $factory - * @param IUserManager $userManager - * @param INotificationManager $notificationManager - * @param IURLGenerator $urlGenerator - */ - public function __construct(IFactory $factory, IUserManager $userManager, INotificationManager $notificationManager, IURLGenerator $urlGenerator) { + /** @var IConfig */ + protected $config; + + public function __construct(IFactory $factory, + IUserManager $userManager, + INotificationManager $notificationManager, + IURLGenerator $urlGenerator, + IConfig $config) { $this->factory = $factory; $this->userManager = $userManager; $this->notificationManager = $notificationManager; $this->url = $urlGenerator; + $this->config = $config; } /** @@ -123,13 +127,16 @@ public function prepare(INotification $notification, string $languageCode): INot * @param string $languageCode * @return string */ - protected function getSubject(INotification $notification, $languageCode) { + protected function getSubject(INotification $notification, string $languageCode): string { $l = $this->factory->get('firstrunwizard', $languageCode); $user = $this->userManager->get($notification->getUser()); $email = $user->getEMailAddress(); if ($email === null || $email === '') { - return $l->t('Add your profile information! For example your email is needed to reset your password.'); + if ($this->config->getSystemValue('lost_password_link', '') || !$user->getBackend() instanceof ISetPasswordBackend) { + return $l->t('Add your profile information! For example your email is needed to receive notifications.'); + } + return $l->t('Add your profile information! For example your email is needed to receive notifications and reset your password.'); } if ($user->canChangeDisplayName() && $user->getDisplayName() === $user->getUID()) { diff --git a/tests/Notification/NotifierTest.php b/tests/Notification/NotifierTest.php index ad1d88dd2..c0397f88c 100644 --- a/tests/Notification/NotifierTest.php +++ b/tests/Notification/NotifierTest.php @@ -25,6 +25,7 @@ use InvalidArgumentException; use OCA\FirstRunWizard\Notification\Notifier; +use OCP\IConfig; use OCP\IImage; use OCP\IL10N; use OCP\IURLGenerator; @@ -56,6 +57,7 @@ protected function setUp(): void { $this->manager = $this->createMock(IManager::class); $this->userManager = $this->createMock(IUserManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->config = $this->createMock(IConfig::class); $this->l = $this->createMock(IL10N::class); $this->l->expects($this->any()) ->method('t') @@ -71,7 +73,8 @@ protected function setUp(): void { $this->factory, $this->userManager, $this->manager, - $this->urlGenerator + $this->urlGenerator, + $this->config ); }