Skip to content

Commit 5585953

Browse files
Merge pull request #504 from nextcloud/backport/502/stable20
[stable20] Extend reasons for email address
2 parents f66a67f + 7a8ec3a commit 5585953

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/Notification/Notifier.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
namespace OCA\FirstRunWizard\Notification;
2323

2424

25+
use OCP\IConfig;
2526
use OCP\IURLGenerator;
2627
use OCP\IUserManager;
2728
use OCP\L10N\IFactory;
2829
use OCP\Notification\IManager as INotificationManager;
2930
use OCP\Notification\INotification;
3031
use OCP\Notification\INotifier;
32+
use OCP\User\Backend\ISetPasswordBackend;
3133

3234
class Notifier implements INotifier {
3335

@@ -43,17 +45,19 @@ class Notifier implements INotifier {
4345
/** @var IURLGenerator */
4446
protected $url;
4547

46-
/**
47-
* @param IFactory $factory
48-
* @param IUserManager $userManager
49-
* @param INotificationManager $notificationManager
50-
* @param IURLGenerator $urlGenerator
51-
*/
52-
public function __construct(IFactory $factory, IUserManager $userManager, INotificationManager $notificationManager, IURLGenerator $urlGenerator) {
48+
/** @var IConfig */
49+
protected $config;
50+
51+
public function __construct(IFactory $factory,
52+
IUserManager $userManager,
53+
INotificationManager $notificationManager,
54+
IURLGenerator $urlGenerator,
55+
IConfig $config) {
5356
$this->factory = $factory;
5457
$this->userManager = $userManager;
5558
$this->notificationManager = $notificationManager;
5659
$this->url = $urlGenerator;
60+
$this->config = $config;
5761
}
5862

5963
/**
@@ -123,13 +127,16 @@ public function prepare(INotification $notification, string $languageCode): INot
123127
* @param string $languageCode
124128
* @return string
125129
*/
126-
protected function getSubject(INotification $notification, $languageCode) {
130+
protected function getSubject(INotification $notification, string $languageCode): string {
127131
$l = $this->factory->get('firstrunwizard', $languageCode);
128132
$user = $this->userManager->get($notification->getUser());
129133

130134
$email = $user->getEMailAddress();
131135
if ($email === null || $email === '') {
132-
return $l->t('Add your profile information! For example your email is needed to reset your password.');
136+
if ($this->config->getSystemValue('lost_password_link', '') || !$user->getBackend() instanceof ISetPasswordBackend) {
137+
return $l->t('Add your profile information! For example your email is needed to receive notifications.');
138+
}
139+
return $l->t('Add your profile information! For example your email is needed to receive notifications and reset your password.');
133140
}
134141

135142
if ($user->canChangeDisplayName() && $user->getDisplayName() === $user->getUID()) {

tests/Notification/NotifierTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use InvalidArgumentException;
2727
use OCA\FirstRunWizard\Notification\Notifier;
28+
use OCP\IConfig;
2829
use OCP\IImage;
2930
use OCP\IL10N;
3031
use OCP\IURLGenerator;
@@ -56,6 +57,7 @@ protected function setUp(): void {
5657
$this->manager = $this->createMock(IManager::class);
5758
$this->userManager = $this->createMock(IUserManager::class);
5859
$this->urlGenerator = $this->createMock(IURLGenerator::class);
60+
$this->config = $this->createMock(IConfig::class);
5961
$this->l = $this->createMock(IL10N::class);
6062
$this->l->expects($this->any())
6163
->method('t')
@@ -71,7 +73,8 @@ protected function setUp(): void {
7173
$this->factory,
7274
$this->userManager,
7375
$this->manager,
74-
$this->urlGenerator
76+
$this->urlGenerator,
77+
$this->config
7578
);
7679
}
7780

0 commit comments

Comments
 (0)