summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-02-11 19:19:05 +0100
committerGitHub <noreply@github.com>2019-02-11 19:19:05 +0100
commite3c787682dfebec2c8e4071aa570a7ee9f77ea52 (patch)
tree2dcd1e85a20c57fc1b4229bd24645eabdc7d41e3
parent66c805311feaabce0f2205b266342bc6cdc81b17 (diff)
parent01f4506dadec86373ee629771677f837cc2a4036 (diff)
downloadnextcloud-server-e3c787682dfebec2c8e4071aa570a7ee9f77ea52.tar.gz
nextcloud-server-e3c787682dfebec2c8e4071aa570a7ee9f77ea52.zip
Merge pull request #14143 from nextcloud/bugfix/noid/add-link-to-settings-on-notification
Add a link to the notification to create the backup codes
-rw-r--r--apps/twofactor_backupcodes/lib/Notifications/Notifier.php9
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php21
2 files changed, 26 insertions, 4 deletions
diff --git a/apps/twofactor_backupcodes/lib/Notifications/Notifier.php b/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
index 3d5fedd93ea..df92c7a9e01 100644
--- a/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
+++ b/apps/twofactor_backupcodes/lib/Notifications/Notifier.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace OCA\TwoFactorBackupCodes\Notifications;
+use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
@@ -33,8 +34,12 @@ class Notifier implements INotifier {
/** @var IFactory */
private $factory;
- public function __construct(IFactory $factory) {
+ /** @var IURLGenerator */
+ private $url;
+
+ public function __construct(IFactory $factory, IURLGenerator $url) {
$this->factory = $factory;
+ $this->url = $url;
}
public function prepare(INotification $notification, $languageCode) {
@@ -53,6 +58,8 @@ class Notifier implements INotifier {
)->setParsedMessage(
$l->t('You have enabled two-factor authentication but have not yet generated backup codes. Be sure to do this in case you lose access to your second factor.')
);
+
+ $notification->setLink($this->url->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'security']));
return $notification;
default:
diff --git a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
index 508fa453e16..9a641eb9f85 100644
--- a/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php
@@ -26,17 +26,21 @@ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Notification;
use OCA\TwoFactorBackupCodes\Notifications\Notifier;
use OCP\IL10N;
+use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NotifierTest extends TestCase {
/** @var Notifier */
protected $notifier;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IFactory|MockObject */
protected $factory;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
+ protected $url;
+ /** @var IL10N|MockObject */
protected $l;
protected function setUp() {
@@ -49,12 +53,14 @@ class NotifierTest extends TestCase {
return vsprintf($string, $args);
});
$this->factory = $this->createMock(IFactory::class);
+ $this->url = $this->createMock(IURLGenerator::class);
$this->factory->expects($this->any())
->method('get')
->willReturn($this->l);
$this->notifier = new Notifier(
- $this->factory
+ $this->factory,
+ $this->url
);
}
@@ -114,6 +120,15 @@ class NotifierTest extends TestCase {
->with('You have enabled two-factor authentication but have not yet generated backup codes. Be sure to do this in case you lose access to your second factor.')
->willReturnSelf();
+ $this->url->expects($this->once())
+ ->method('linkToRouteAbsolute')
+ ->with('settings.PersonalSettings.index', ['section' => 'security'])
+ ->willReturn('linkToRouteAbsolute');
+ $notification->expects($this->once())
+ ->method('setLink')
+ ->with('linkToRouteAbsolute')
+ ->willReturnSelf();
+
$return = $this->notifier->prepare($notification, 'nl');
$this->assertEquals($notification, $return);
}