From 0a3ef8b74bffc9b1cb6ef21695037d52aabd3ee1 Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Wed, 28 Dec 2022 19:08:54 +0100 Subject: Fixing tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/files/lib/Controller/ApiController.php | 2 +- apps/files/lib/Controller/ViewController.php | 14 +++++++------- apps/files/lib/Service/UserConfig.php | 11 +++++------ 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'apps/files/lib') diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 76597b7a018..f2329fc384b 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -289,7 +289,7 @@ class ApiController extends Controller { * @param string|bool $value * @return JSONResponse */ - public function setConfig(string $key, string|bool $value): JSONResponse { + public function setConfig(string $key, $value): JSONResponse { try { $this->userConfig->setConfig($key, (string)$value); } catch (\InvalidArgumentException $e) { diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 4e81b630bab..ea589807767 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -175,13 +175,13 @@ class ViewController extends Controller { */ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { - // if ($fileid !== null && $dir === '') { - // try { - // return $this->redirectToFile($fileid); - // } catch (NotFoundException $e) { - // return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); - // } - // } + if ($fileid !== null && $dir === '') { + try { + return $this->redirectToFile($fileid); + } catch (NotFoundException $e) { + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); + } + } $nav = new \OCP\Template('files', 'appnavigation', ''); diff --git a/apps/files/lib/Service/UserConfig.php b/apps/files/lib/Service/UserConfig.php index 7ccf7008512..3a498805910 100644 --- a/apps/files/lib/Service/UserConfig.php +++ b/apps/files/lib/Service/UserConfig.php @@ -42,8 +42,7 @@ class UserConfig { ]; protected IConfig $config; - /** @var \OCP\IUser|null */ - protected mixed $user = null; + protected ?IUser $user = null; public function __construct(IConfig $config, IUserSession $userSession) { $this->config = $config; @@ -81,7 +80,7 @@ class UserConfig { * @param string $key a valid config key * @return string|bool */ - private function getDefaultConfigValue(string $key): string|bool { + private function getDefaultConfigValue(string $key) { foreach (self::ALLOWED_CONFIGS as $config) { if ($config['key'] === $key) { return $config['default']; @@ -94,11 +93,11 @@ class UserConfig { * Set a user config * * @param string $key - * @param string $value + * @param string|bool $value * @throws \Exception * @throws \InvalidArgumentException */ - public function setConfig($key, $value) { + public function setConfig(string $key, $value): void { if ($this->user === null) { throw new \Exception('No user logged in'); } @@ -129,7 +128,7 @@ class UserConfig { } $userId = $this->user->getUID(); - $userConfigs = array_map(function(string $key) use ($userId): string|bool { + $userConfigs = array_map(function(string $key) use ($userId) { $value = $this->config->getUserValue($userId, Application::APP_ID, $key, $this->getDefaultConfigValue($key)); // If the default is expected to be a boolean, we need to cast the value if (is_bool($this->getDefaultConfigValue($key))) { -- cgit v1.2.3