Sfoglia il codice sorgente

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
tags/v16.0.0alpha1
Roeland Jago Douma 5 anni fa
parent
commit
e3c787682d
Nessun account collegato all'indirizzo email del committer

+ 8
- 1
apps/twofactor_backupcodes/lib/Notifications/Notifier.php Vedi File

@@ -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:

+ 18
- 3
apps/twofactor_backupcodes/tests/Unit/Notification/NotifierTest.php Vedi File

@@ -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);
}

Loading…
Annulla
Salva