]> source.dussan.org Git - nextcloud-server.git/commitdiff
Provide proper user context from initMountPoints
authorJulius Härtl <jus@bitgrid.net>
Thu, 25 Jul 2019 07:31:39 +0000 (09:31 +0200)
committerJulius Härtl <jus@bitgrid.net>
Fri, 2 Aug 2019 06:39:24 +0000 (08:39 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/files_external/lib/Config/ConfigAdapter.php
apps/files_external/lib/Config/UserContext.php
apps/files_external/lib/config.php

index 8d9c7ea8d1bb51bfe99274c02a6fa9b86e794894..c9586635baf06f2adcef0482594a982ee836ba1d 100644 (file)
@@ -76,7 +76,7 @@ class ConfigAdapter implements IMountProvider {
         */
        private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
                foreach ($storage->getBackendOptions() as $option => $value) {
-                       $storage->setBackendOption($option, \OC_Mount_Config::substitutePlaceholdersInConfig($value));
+                       $storage->setBackendOption($option, \OC_Mount_Config::substitutePlaceholdersInConfig($value, $user->getUID()));
                }
 
                $objectStore = $storage->getBackendOption('objectstore');
index 8fdca68f9b4b3bd2731e9b949a7e9ee1a8f0e2eb..bec762358f2d42b84971361696dbc27cf529413f 100644 (file)
@@ -39,6 +39,8 @@ class UserContext {
        /** @var IRequest */
        private $request;
 
+       private $user;
+
        public function __construct(IUserSession $session, ShareManager $manager, IRequest $request) {
                $this->session = $session;
                $this->shareManager = $manager;
@@ -49,8 +51,14 @@ class UserContext {
                return $this->session;
        }
 
+       public function setUser($user): void {
+               $this->user = $user;
+       }
 
        protected function getUserId(): ?string {
+               if ($this->user !== null) {
+                       return $this->user;
+               }
                if($this->session && $this->session->getUser() !== null) {
                        return $this->session->getUser()->getUID();
                }
index cc417a837facabe96fd810c26f2db722adc2eb5b..75ed59418d032e72b7386258d0bfe13a8ee5a6f1 100644 (file)
@@ -50,6 +50,7 @@ use OCA\Files_External\Service\UserGlobalStoragesService;
 use OCP\IUserManager;
 use OCA\Files_External\Service\GlobalStoragesService;
 use OCA\Files_External\Service\UserStoragesService;
+use OCA\Files_External\Config\UserContext;
 
 /**
  * Class to configure mount.json globally and for users
@@ -107,7 +108,7 @@ class OC_Mount_Config {
                        $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
                        $mountEntry = self::prepareMountPointEntry($storage, false);
                        foreach ($mountEntry['options'] as &$option) {
-                               $option = self::substitutePlaceholdersInConfig($option);
+                               $option = self::substitutePlaceholdersInConfig($option, $uid);
                        }
                        $mountPoints[$mountPoint] = $mountEntry;
                }
@@ -116,7 +117,7 @@ class OC_Mount_Config {
                        $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
                        $mountEntry = self::prepareMountPointEntry($storage, true);
                        foreach ($mountEntry['options'] as &$option) {
-                               $option = self::substitutePlaceholdersInConfig($uid, $option);
+                               $option = self::substitutePlaceholdersInConfig($option, $uid);
                        }
                        $mountPoints[$mountPoint] = $mountEntry;
                }
@@ -215,12 +216,15 @@ class OC_Mount_Config {
         * @throws \OCP\AppFramework\QueryException
         * @since 16.0.0
         */
-       public static function substitutePlaceholdersInConfig($input) {
+       public static function substitutePlaceholdersInConfig($input, $user = null) {
                /** @var BackendService $backendService */
                $backendService = self::$app->getContainer()->query(BackendService::class);
                /** @var IConfigHandler[] $handlers */
                $handlers = $backendService->getConfigHandlers();
                foreach ($handlers as $handler) {
+                       if ($handler instanceof UserContext) {
+                               $handler->setUser($user);
+                       }
                        $input = $handler->handle($input);
                }
                return $input;