Skip to content

Commit

Permalink
Merge pull request #504 from nextcloud/backport/502/stable20
Browse files Browse the repository at this point in the history
[stable20] Extend reasons for email address
  • Loading branch information
nickvergessen authored Mar 29, 2021
2 parents f66a67f + 7a8ec3a commit 5585953
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
25 changes: 16 additions & 9 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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()) {
Expand Down
5 changes: 4 additions & 1 deletion tests/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use InvalidArgumentException;
use OCA\FirstRunWizard\Notification\Notifier;
use OCP\IConfig;
use OCP\IImage;
use OCP\IL10N;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -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')
Expand All @@ -71,7 +73,8 @@ protected function setUp(): void {
$this->factory,
$this->userManager,
$this->manager,
$this->urlGenerator
$this->urlGenerator,
$this->config
);
}

Expand Down

0 comments on commit 5585953

Please sign in to comment.