diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-01-29 20:13:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 20:13:23 +0100 |
commit | 53817f5fc20533d2b9da2ecff6bd96acf21b4e17 (patch) | |
tree | 6e91fedd594cdd5d475d72403f52e8997c1e59de | |
parent | ca964cfe9fa0c0e5b097e61933d67a45a5fa3b2d (diff) | |
parent | 34426a481faa5ff76317295305d7c6fad2c8534f (diff) | |
download | nextcloud-server-53817f5fc20533d2b9da2ecff6bd96acf21b4e17.tar.gz nextcloud-server-53817f5fc20533d2b9da2ecff6bd96acf21b4e17.zip |
Merge pull request #19185 from nextcloud/enh/move_token_logic_to_token_settings
Move can create token logic
-rw-r--r-- | apps/settings/lib/Settings/Personal/Security.php | 13 | ||||
-rw-r--r-- | apps/settings/lib/Settings/Personal/Security/Authtokens.php | 12 | ||||
-rw-r--r-- | apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php (renamed from apps/settings/tests/Personal/Security/AuthtokensTest.php) | 14 | ||||
-rw-r--r-- | apps/settings/tests/Settings/Personal/SecurityTest.php | 6 |
4 files changed, 25 insertions, 20 deletions
diff --git a/apps/settings/lib/Settings/Personal/Security.php b/apps/settings/lib/Settings/Personal/Security.php index 5734eaa5ca3..192b082d6b1 100644 --- a/apps/settings/lib/Settings/Personal/Security.php +++ b/apps/settings/lib/Settings/Personal/Security.php @@ -50,9 +50,6 @@ use OCP\Settings\ISettings; class Security implements ISettings { - /** @var IInitialStateService */ - private $initialStateService; - /** @var IUserManager */ private $userManager; @@ -68,13 +65,11 @@ class Security implements ISettings { /** @var IConfig */ private $config; - public function __construct(IInitialStateService $initialStateService, - IUserManager $userManager, + public function __construct(IUserManager $userManager, ProviderLoader $providerLoader, IUserSession $userSession, IConfig $config, ?string $UserId) { - $this->initialStateService = $initialStateService; $this->userManager = $userManager; $this->providerLoader = $providerLoader; $this->userSession = $userSession; @@ -89,12 +84,6 @@ class Security implements ISettings { $passwordChangeSupported = $user->canChangePassword(); } - $this->initialStateService->provideInitialState( - 'settings', - 'can_create_app_token', - $this->userSession->getImpersonatingUserID() === null - ); - return new TemplateResponse('settings', 'settings/personal/security', [ 'passwordChangeSupported' => $passwordChangeSupported, 'twoFactorProviderData' => $this->getTwoFactorProviderData(), diff --git a/apps/settings/lib/Settings/Personal/Security/Authtokens.php b/apps/settings/lib/Settings/Personal/Security/Authtokens.php index 04825069920..1944670b2ea 100644 --- a/apps/settings/lib/Settings/Personal/Security/Authtokens.php +++ b/apps/settings/lib/Settings/Personal/Security/Authtokens.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCA\Settings\Personal\Security; +use OCP\IUserSession; use function array_map; use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\INamedToken; @@ -52,14 +53,19 @@ class Authtokens implements ISettings { /** @var string|null */ private $uid; + /** @var IUserSession */ + private $userSession; + public function __construct(IAuthTokenProvider $tokenProvider, ISession $session, + IUserSession $userSession, IInitialStateService $initialStateService, ?string $UserId) { $this->tokenProvider = $tokenProvider; $this->session = $session; $this->initialStateService = $initialStateService; $this->uid = $UserId; + $this->userSession = $userSession; } public function getForm(): TemplateResponse { @@ -69,6 +75,12 @@ class Authtokens implements ISettings { $this->getAppTokens() ); + $this->initialStateService->provideInitialState( + 'settings', + 'can_create_app_token', + $this->userSession->getImpersonatingUserID() === null + ); + return new TemplateResponse('settings', 'settings/personal/security/authtokens'); } diff --git a/apps/settings/tests/Personal/Security/AuthtokensTest.php b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php index e8eadd38aba..6837fc101c4 100644 --- a/apps/settings/tests/Personal/Security/AuthtokensTest.php +++ b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php @@ -25,7 +25,7 @@ declare(strict_types=1); * */ -namespace Test\Settings\Personal\Security; +namespace OCA\Settings\Tests\Settings\Personal\Security; use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\IProvider as IAuthTokenProvider; @@ -34,6 +34,7 @@ use OCA\Settings\Personal\Security\Authtokens; use OCP\AppFramework\Http\TemplateResponse; use OCP\IInitialStateService; use OCP\ISession; +use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -45,6 +46,9 @@ class AuthtokensTest extends TestCase { /** @var ISession|MockObject */ private $session; + /** @var IUserSession|MockObject */ + private $userSession; + /** @var IInitialStateService|MockObject */ private $initialStateService; @@ -59,12 +63,14 @@ class AuthtokensTest extends TestCase { $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class); $this->session = $this->createMock(ISession::class); + $this->userSession = $this->createMock(IUserSession::class); $this->initialStateService = $this->createMock(IInitialStateService::class); $this->uid = 'test123'; $this->section = new Authtokens( $this->authTokenProvider, $this->session, + $this->userSession, $this->initialStateService, $this->uid ); @@ -93,7 +99,7 @@ class AuthtokensTest extends TestCase { ->method('getToken') ->with('session123') ->willReturn($sessionToken); - $this->initialStateService->expects($this->once()) + $this->initialStateService->expects($this->at(0)) ->method('provideInitialState') ->with('settings', 'app_tokens', [ [ @@ -117,6 +123,10 @@ class AuthtokensTest extends TestCase { ], ]); + $this->initialStateService->expects($this->at(1)) + ->method('provideInitialState') + ->with('settings', 'can_create_app_token', true); + $form = $this->section->getForm(); $expected = new TemplateResponse('settings', 'settings/personal/security/authtokens'); diff --git a/apps/settings/tests/Settings/Personal/SecurityTest.php b/apps/settings/tests/Settings/Personal/SecurityTest.php index 5dfb911716f..bd087afa466 100644 --- a/apps/settings/tests/Settings/Personal/SecurityTest.php +++ b/apps/settings/tests/Settings/Personal/SecurityTest.php @@ -32,7 +32,6 @@ use OC\Authentication\TwoFactorAuth\ProviderLoader; use OCA\Settings\Personal\Security; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; -use OCP\IInitialStateService; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -41,9 +40,6 @@ use Test\TestCase; class SecurityTest extends TestCase { - /** @var IInitialStateService|MockObject */ - private $initialStateService; - /** @var IUserManager|MockObject */ private $userManager; @@ -65,7 +61,6 @@ class SecurityTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->initialStateService = $this->createMock(IInitialStateService::class); $this->userManager = $this->createMock(IUserManager::class); $this->providerLoader = $this->createMock(ProviderLoader::class); $this->userSession = $this->createMock(IUserSession::class); @@ -73,7 +68,6 @@ class SecurityTest extends TestCase { $this->uid = 'test123'; $this->section = new Security( - $this->initialStateService, $this->userManager, $this->providerLoader, $this->userSession, |