Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable20] Extend reasons for email address #504

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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