fixes terminology and allows to request an IUser instance

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2019-07-25 17:57:22 +02:00 committed by Backportbot
parent f852c82bf9
commit bb9f14115c
2 changed files with 23 additions and 7 deletions

View File

@ -24,6 +24,8 @@
namespace OCA\Files_External\Config; namespace OCA\Files_External\Config;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager; use OCP\Share\IManager as ShareManager;
@ -39,25 +41,30 @@ class UserContext {
/** @var IRequest */ /** @var IRequest */
private $request; private $request;
private $user; /** @var string */
private $userId;
public function __construct(IUserSession $session, ShareManager $manager, IRequest $request) { /** @var IUserManager */
private $userManager;
public function __construct(IUserSession $session, ShareManager $manager, IRequest $request, IUserManager $userManager) {
$this->session = $session; $this->session = $session;
$this->shareManager = $manager; $this->shareManager = $manager;
$this->request = $request; $this->request = $request;
$this->userManager = $userManager;
} }
public function getSession(): IUserSession { public function getSession(): IUserSession {
return $this->session; return $this->session;
} }
public function setUser($user): void { public function setUserId(string $userId): void {
$this->user = $user; $this->userId = $userId;
} }
protected function getUserId(): ?string { protected function getUserId(): ?string {
if ($this->user !== null) { if ($this->userId !== null) {
return $this->user; return $this->userId;
} }
if($this->session && $this->session->getUser() !== null) { if($this->session && $this->session->getUser() !== null) {
return $this->session->getUser()->getUID(); return $this->session->getUser()->getUID();
@ -71,4 +78,12 @@ class UserContext {
return null; return null;
} }
protected function getUser(): ?IUser {
$userId = $this->getUserId();
if($userId !== null) {
return $this->userManager->get($userId);
}
return null;
}
} }

View File

@ -212,11 +212,12 @@ class OC_Mount_Config {
/** /**
* @param mixed $input * @param mixed $input
* @param string|null $userId
* @return mixed * @return mixed
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
* @since 16.0.0 * @since 16.0.0
*/ */
public static function substitutePlaceholdersInConfig($input, $user = null) { public static function substitutePlaceholdersInConfig($input, string $userId = 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 */