Provide proper user context from initMountPoints
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
40cf574df9
commit
f852c82bf9
|
@ -76,7 +76,7 @@ class ConfigAdapter implements IMountProvider {
|
||||||
*/
|
*/
|
||||||
private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
|
private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
|
||||||
foreach ($storage->getBackendOptions() as $option => $value) {
|
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');
|
$objectStore = $storage->getBackendOption('objectstore');
|
||||||
|
|
|
@ -39,6 +39,8 @@ class UserContext {
|
||||||
/** @var IRequest */
|
/** @var IRequest */
|
||||||
private $request;
|
private $request;
|
||||||
|
|
||||||
|
private $user;
|
||||||
|
|
||||||
public function __construct(IUserSession $session, ShareManager $manager, IRequest $request) {
|
public function __construct(IUserSession $session, ShareManager $manager, IRequest $request) {
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->shareManager = $manager;
|
$this->shareManager = $manager;
|
||||||
|
@ -49,8 +51,14 @@ class UserContext {
|
||||||
return $this->session;
|
return $this->session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUser($user): void {
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getUserId(): ?string {
|
protected function getUserId(): ?string {
|
||||||
|
if ($this->user !== null) {
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
if($this->session && $this->session->getUser() !== null) {
|
if($this->session && $this->session->getUser() !== null) {
|
||||||
return $this->session->getUser()->getUID();
|
return $this->session->getUser()->getUID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCA\Files_External\Service\GlobalStoragesService;
|
use OCA\Files_External\Service\GlobalStoragesService;
|
||||||
use OCA\Files_External\Service\UserStoragesService;
|
use OCA\Files_External\Service\UserStoragesService;
|
||||||
|
use OCA\Files_External\Config\UserContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to configure mount.json globally and for users
|
* Class to configure mount.json globally and for users
|
||||||
|
@ -107,7 +108,7 @@ class OC_Mount_Config {
|
||||||
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
|
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
|
||||||
$mountEntry = self::prepareMountPointEntry($storage, false);
|
$mountEntry = self::prepareMountPointEntry($storage, false);
|
||||||
foreach ($mountEntry['options'] as &$option) {
|
foreach ($mountEntry['options'] as &$option) {
|
||||||
$option = self::substitutePlaceholdersInConfig($option);
|
$option = self::substitutePlaceholdersInConfig($option, $uid);
|
||||||
}
|
}
|
||||||
$mountPoints[$mountPoint] = $mountEntry;
|
$mountPoints[$mountPoint] = $mountEntry;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,7 @@ class OC_Mount_Config {
|
||||||
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
|
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
|
||||||
$mountEntry = self::prepareMountPointEntry($storage, true);
|
$mountEntry = self::prepareMountPointEntry($storage, true);
|
||||||
foreach ($mountEntry['options'] as &$option) {
|
foreach ($mountEntry['options'] as &$option) {
|
||||||
$option = self::substitutePlaceholdersInConfig($uid, $option);
|
$option = self::substitutePlaceholdersInConfig($option, $uid);
|
||||||
}
|
}
|
||||||
$mountPoints[$mountPoint] = $mountEntry;
|
$mountPoints[$mountPoint] = $mountEntry;
|
||||||
}
|
}
|
||||||
|
@ -215,12 +216,15 @@ class OC_Mount_Config {
|
||||||
* @throws \OCP\AppFramework\QueryException
|
* @throws \OCP\AppFramework\QueryException
|
||||||
* @since 16.0.0
|
* @since 16.0.0
|
||||||
*/
|
*/
|
||||||
public static function substitutePlaceholdersInConfig($input) {
|
public static function substitutePlaceholdersInConfig($input, $user = null) {
|
||||||
/** @var BackendService $backendService */
|
/** @var BackendService $backendService */
|
||||||
$backendService = self::$app->getContainer()->query(BackendService::class);
|
$backendService = self::$app->getContainer()->query(BackendService::class);
|
||||||
/** @var IConfigHandler[] $handlers */
|
/** @var IConfigHandler[] $handlers */
|
||||||
$handlers = $backendService->getConfigHandlers();
|
$handlers = $backendService->getConfigHandlers();
|
||||||
foreach ($handlers as $handler) {
|
foreach ($handlers as $handler) {
|
||||||
|
if ($handler instanceof UserContext) {
|
||||||
|
$handler->setUser($user);
|
||||||
|
}
|
||||||
$input = $handler->handle($input);
|
$input = $handler->handle($input);
|
||||||
}
|
}
|
||||||
return $input;
|
return $input;
|
||||||
|
|
Loading…
Reference in New Issue