]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix AppFramework services 21825/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Tue, 14 Jul 2020 07:18:39 +0000 (09:18 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 14 Jul 2020 14:01:14 +0000 (16:01 +0200)
* We can't just register an alias as the services need the appId to be
  injected. if we just register an alias this blows up since the main
  container doesn't have the appId.
* Moved the Authtokens over to show the PoC works

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/settings/lib/Settings/Personal/Security/Authtokens.php
apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
lib/private/AppFramework/DependencyInjection/DIContainer.php

index 22aca1660d98ecdab947015f2ce92c87e26d3304..a0758933525eb54849ef626999e246f37484f809 100644 (file)
@@ -26,6 +26,7 @@ declare(strict_types=1);
 
 namespace OCA\Settings\Settings\Personal\Security;
 
+use OCP\AppFramework\Services\IInitialState;
 use OCP\IUserSession;
 use function array_map;
 use OC\Authentication\Exceptions\InvalidTokenException;
@@ -33,7 +34,6 @@ use OC\Authentication\Token\INamedToken;
 use OC\Authentication\Token\IProvider as IAuthTokenProvider;
 use OC\Authentication\Token\IToken;
 use OCP\AppFramework\Http\TemplateResponse;
-use OCP\IInitialStateService;
 use OCP\ISession;
 use OCP\Session\Exceptions\SessionNotAvailableException;
 use OCP\Settings\ISettings;
@@ -46,8 +46,8 @@ class Authtokens implements ISettings {
        /** @var ISession */
        private $session;
 
-       /** @var IInitialStateService */
-       private $initialStateService;
+       /** @var IInitialState */
+       private $initialState;
 
        /** @var string|null */
        private $uid;
@@ -58,24 +58,22 @@ class Authtokens implements ISettings {
        public function __construct(IAuthTokenProvider $tokenProvider,
                                                                ISession $session,
                                                                IUserSession $userSession,
-                                                               IInitialStateService $initialStateService,
+                                                               IInitialState $initialState,
                                                                ?string $UserId) {
                $this->tokenProvider = $tokenProvider;
                $this->session = $session;
-               $this->initialStateService = $initialStateService;
+               $this->initialState = $initialState;
                $this->uid = $UserId;
                $this->userSession = $userSession;
        }
 
        public function getForm(): TemplateResponse {
-               $this->initialStateService->provideInitialState(
-                       'settings',
+               $this->initialState->provideInitialState(
                        'app_tokens',
                        $this->getAppTokens()
                );
 
-               $this->initialStateService->provideInitialState(
-                       'settings',
+               $this->initialState->provideInitialState(
                        'can_create_app_token',
                        $this->userSession->getImpersonatingUserID() === null
                );
index e03e05c149a2a2d84b59966cc7a3fa44e26cc3f2..f3d92051e46e08f9c879ef87bbdba4fd7037f6c6 100644 (file)
@@ -30,7 +30,7 @@ use OC\Authentication\Token\DefaultToken;
 use OC\Authentication\Token\IProvider as IAuthTokenProvider;
 use OCA\Settings\Settings\Personal\Security\Authtokens;
 use OCP\AppFramework\Http\TemplateResponse;
-use OCP\IInitialStateService;
+use OCP\AppFramework\Services\IInitialState;
 use OCP\ISession;
 use OCP\IUserSession;
 use PHPUnit\Framework\MockObject\MockObject;
@@ -47,8 +47,8 @@ class AuthtokensTest extends TestCase {
        /** @var IUserSession|MockObject */
        private $userSession;
 
-       /** @var IInitialStateService|MockObject */
-       private $initialStateService;
+       /** @var IInitialState|MockObject */
+       private $initialState;
 
        /** @var string */
        private $uid;
@@ -62,14 +62,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->initialState = $this->createMock(IInitialState::class);
                $this->uid = 'test123';
 
                $this->section = new Authtokens(
                        $this->authTokenProvider,
                        $this->session,
                        $this->userSession,
-                       $this->initialStateService,
+                       $this->initialState,
                        $this->uid
                );
        }
@@ -97,9 +97,9 @@ class AuthtokensTest extends TestCase {
                        ->method('getToken')
                        ->with('session123')
                        ->willReturn($sessionToken);
-               $this->initialStateService->expects($this->at(0))
+               $this->initialState->expects($this->at(0))
                        ->method('provideInitialState')
-                       ->with('settings', 'app_tokens', [
+                       ->with('app_tokens', [
                                [
                                        'id' => 100,
                                        'name' => null,
@@ -121,9 +121,9 @@ class AuthtokensTest extends TestCase {
                                ],
                        ]);
 
-               $this->initialStateService->expects($this->at(1))
+               $this->initialState->expects($this->at(1))
                        ->method('provideInitialState')
-                       ->with('settings', 'can_create_app_token', true);
+                       ->with('can_create_app_token', true);
 
                $form = $this->section->getForm();
 
index 82a2780eb27c3b46ab79517a156d685fdf16e224..bda014838ed046a4ba92ea6c3a9af9ee5e7425e2 100644 (file)
@@ -59,6 +59,8 @@ use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Files\Folder;
 use OCP\Files\IAppData;
 use OCP\Group\ISubAdmin;
+use OCP\IConfig;
+use OCP\IInitialStateService;
 use OCP\IL10N;
 use OCP\ILogger;
 use OCP\INavigationManager;
@@ -295,8 +297,18 @@ class DIContainer extends SimpleContainer implements IAppContainer {
                        return $dispatcher;
                });
 
-               $this->registerAlias(IAppConfig::class, OC\AppFramework\Services\AppConfig::class);
-               $this->registerAlias(IInitialState::class, OC\AppFramework\Services\InitialState::class);
+               $this->registerService(IAppConfig::class, function (SimpleContainer $c) {
+                       return new OC\AppFramework\Services\AppConfig(
+                               $c->query(IConfig::class),
+                               $c->query('AppName')
+                       );
+               });
+               $this->registerService(IInitialState::class, function (SimpleContainer $c) {
+                       return new OC\AppFramework\Services\InitialState(
+                               $c->query(IInitialStateService::class),
+                               $c->query('AppName')
+                       );
+               });
        }
 
        /**