aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Controller')
-rw-r--r--apps/files_external/lib/Controller/AjaxController.php56
-rw-r--r--apps/files_external/lib/Controller/ApiController.php90
-rw-r--r--apps/files_external/lib/Controller/GlobalStoragesController.php37
-rw-r--r--apps/files_external/lib/Controller/StoragesController.php117
-rw-r--r--apps/files_external/lib/Controller/UserGlobalStoragesController.php61
-rw-r--r--apps/files_external/lib/Controller/UserStoragesController.php54
6 files changed, 126 insertions, 289 deletions
diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php
index db23ecd709d..9faba64416f 100644
--- a/apps/files_external/lib/Controller/AjaxController.php
+++ b/apps/files_external/lib/Controller/AjaxController.php
@@ -1,36 +1,15 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Martin Mattel <martin.mattel@diemattels.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Ross Nicoll <jrn@jrn.me.uk>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IGroupManager;
use OCP\IRequest;
@@ -55,11 +34,11 @@ class AjaxController extends Controller {
* @param IGroupManager $groupManager
*/
public function __construct($appName,
- IRequest $request,
- RSA $rsaMechanism,
- GlobalAuth $globalAuth,
- IUserSession $userSession,
- IGroupManager $groupManager) {
+ IRequest $request,
+ RSA $rsaMechanism,
+ GlobalAuth $globalAuth,
+ IUserSession $userSession,
+ IGroupManager $groupManager) {
parent::__construct($appName, $request);
$this->rsaMechanism = $rsaMechanism;
$this->globalAuth = $globalAuth;
@@ -82,9 +61,9 @@ class AjaxController extends Controller {
/**
* Generates an SSH public/private key pair.
*
- * @NoAdminRequired
* @param int $keyLength
*/
+ #[NoAdminRequired]
public function getSshKeys($keyLength = 1024) {
$key = $this->generateSshKeys($keyLength);
return new JSONResponse(
@@ -97,24 +76,29 @@ class AjaxController extends Controller {
}
/**
- * @NoAdminRequired
- *
* @param string $uid
* @param string $user
* @param string $password
* @return bool
*/
+ #[NoAdminRequired]
public function saveGlobalCredentials($uid, $user, $password) {
$currentUser = $this->userSession->getUser();
+ if ($currentUser === null) {
+ return false;
+ }
// Non-admins can only edit their own credentials
- $allowedToEdit = ($this->groupManager->isAdmin($currentUser->getUID()) || $currentUser->getUID() === $uid);
+ // Admin can edit global credentials
+ $allowedToEdit = $uid === ''
+ ? $this->groupManager->isAdmin($currentUser->getUID())
+ : $currentUser->getUID() === $uid;
if ($allowedToEdit) {
$this->globalAuth->saveAuth($uid, $user, $password);
return true;
- } else {
- return false;
}
+
+ return false;
}
}
diff --git a/apps/files_external/lib/Controller/ApiController.php b/apps/files_external/lib/Controller/ApiController.php
index 40539d0bbca..56242938593 100644
--- a/apps/files_external/lib/Controller/ApiController.php
+++ b/apps/files_external/lib/Controller/ApiController.php
@@ -3,59 +3,38 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jesús Macias <jmacias@solidgear.es>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\ResponseDefinitions;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
+use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
-use OCP\IUserSession;
+/**
+ * @psalm-import-type Files_ExternalMount from ResponseDefinitions
+ */
class ApiController extends OCSController {
- /** @var IUserSession */
- private $userSession;
- /** @var UserGlobalStoragesService */
- private $userGlobalStoragesService;
- /** @var UserStoragesService */
- private $userStoragesService;
+ private UserGlobalStoragesService $userGlobalStoragesService;
+ private UserStoragesService $userStoragesService;
public function __construct(
string $appName,
IRequest $request,
- IUserSession $userSession,
UserGlobalStoragesService $userGlobalStorageService,
UserStoragesService $userStorageService
) {
parent::__construct($appName, $request);
-
- $this->userSession = $userSession;
$this->userGlobalStoragesService = $userGlobalStorageService;
$this->userStoragesService = $userStorageService;
}
@@ -66,7 +45,7 @@ class ApiController extends OCSController {
* @param string $mountPoint mount point name, relative to the data dir
* @param StorageConfig $mountConfig mount config to format
*
- * @return array entry
+ * @return Files_ExternalMount
*/
private function formatMount(string $mountPoint, StorageConfig $mountConfig): array {
// split path from mount point
@@ -84,25 +63,27 @@ class ApiController extends OCSController {
}
$entry = [
+ 'id' => $mountConfig->getId(),
+ 'type' => 'dir',
'name' => basename($mountPoint),
'path' => $path,
- 'type' => 'dir',
- 'backend' => $mountConfig->getBackend()->getText(),
- 'scope' => $isSystemMount ? 'system' : 'personal',
'permissions' => $permissions,
- 'id' => $mountConfig->getId(),
+ 'scope' => $isSystemMount ? 'system' : 'personal',
+ 'backend' => $mountConfig->getBackend()->getText(),
'class' => $mountConfig->getBackend()->getIdentifier(),
+ 'config' => $mountConfig->jsonSerialize(true),
];
return $entry;
}
/**
- * @NoAdminRequired
+ * Get the mount points visible for this user
*
- * Returns the mount points visible for this user.
+ * @return DataResponse<Http::STATUS_OK, Files_ExternalMount[], array{}>
*
- * @return DataResponse share information
+ * 200: User mounts returned
*/
+ #[NoAdminRequired]
public function getUserMounts(): DataResponse {
$entries = [];
$mountPoints = [];
@@ -122,4 +103,31 @@ class ApiController extends OCSController {
return new DataResponse($entries);
}
+
+ /**
+ * Ask for credentials using a browser's native basic auth prompt
+ * Then returns it if provided
+ */
+ #[NoAdminRequired]
+ #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
+ public function askNativeAuth(): DataResponse {
+ if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
+ $response = new DataResponse([], Http::STATUS_UNAUTHORIZED);
+ $response->addHeader('WWW-Authenticate', 'Basic realm="Storage authentification needed"');
+ return $response;
+ }
+
+ $user = $_SERVER['PHP_AUTH_USER'];
+ $password = $_SERVER['PHP_AUTH_PW'];
+
+ // Reset auth
+ unset($_SERVER['PHP_AUTH_USER']);
+ unset($_SERVER['PHP_AUTH_PW']);
+
+ // Using 401 again to ensure we clear any cached Authorization
+ return new DataResponse([
+ 'user' => $user,
+ 'password' => $password,
+ ], Http::STATUS_UNAUTHORIZED);
+ }
}
diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php
index 2630fcc365a..d773f3ea5e2 100644
--- a/apps/files_external/lib/Controller/GlobalStoragesController.php
+++ b/apps/files_external/lib/Controller/GlobalStoragesController.php
@@ -1,29 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
@@ -34,9 +13,9 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* Global storages controller
@@ -49,7 +28,7 @@ class GlobalStoragesController extends StoragesController {
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param GlobalStoragesService $globalStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
* @param IConfig $config
@@ -59,7 +38,7 @@ class GlobalStoragesController extends StoragesController {
IRequest $request,
IL10N $l10n,
GlobalStoragesService $globalStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
@@ -134,7 +113,7 @@ class GlobalStoragesController extends StoragesController {
$this->updateStorageStatus($newStorage);
return new DataResponse(
- $this->formatStorageForUI($newStorage),
+ $newStorage->jsonSerialize(true),
Http::STATUS_CREATED
);
}
@@ -201,7 +180,7 @@ class GlobalStoragesController extends StoragesController {
$this->updateStorageStatus($storage, $testOnly);
return new DataResponse(
- $this->formatStorageForUI($storage),
+ $storage->jsonSerialize(true),
Http::STATUS_OK
);
}
diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php
index c8eda8658ef..fd004b49b37 100644
--- a/apps/files_external/lib/Controller/StoragesController.php
+++ b/apps/files_external/lib/Controller/StoragesController.php
@@ -1,36 +1,13 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Jesús Macias <jmacias@solidgear.es>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Backend\Backend;
-use OCA\Files_External\Lib\DefinitionParameter;
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
@@ -42,49 +19,14 @@ use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* Base class for storages controllers
*/
abstract class StoragesController extends Controller {
-
- /**
- * L10N service
- *
- * @var IL10N
- */
- protected $l10n;
-
- /**
- * Storages service
- *
- * @var StoragesService
- */
- protected $service;
-
- /**
- * @var ILogger
- */
- protected $logger;
-
- /**
- * @var IUserSession
- */
- protected $userSession;
-
- /**
- * @var IGroupManager
- */
- protected $groupManager;
-
- /**
- * @var IConfig
- */
- protected $config;
-
/**
* Creates a new storages controller.
*
@@ -92,25 +34,19 @@ abstract class StoragesController extends Controller {
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param StoragesService $storagesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
*/
public function __construct(
$AppName,
IRequest $request,
- IL10N $l10n,
- StoragesService $storagesService,
- ILogger $logger,
- IUserSession $userSession,
- IGroupManager $groupManager,
- IConfig $config
+ protected IL10N $l10n,
+ protected StoragesService $service,
+ protected LoggerInterface $logger,
+ protected IUserSession $userSession,
+ protected IGroupManager $groupManager,
+ protected IConfig $config
) {
parent::__construct($AppName, $request);
- $this->l10n = $l10n;
- $this->service = $storagesService;
- $this->logger = $logger;
- $this->userSession = $userSession;
- $this->groupManager = $groupManager;
- $this->config = $config;
}
/**
@@ -159,7 +95,7 @@ abstract class StoragesController extends Controller {
$priority
);
} catch (\InvalidArgumentException $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return new DataResponse(
[
'message' => $this->l10n->t('Invalid backend or authentication mechanism class')
@@ -317,7 +253,7 @@ abstract class StoragesController extends Controller {
* @return DataResponse
*/
public function index() {
- $storages = $this->formatStoragesForUI($this->service->getStorages());
+ $storages = array_map(static fn ($storage) => $storage->jsonSerialize(true), $this->service->getStorages());
return new DataResponse(
$storages,
@@ -325,29 +261,6 @@ abstract class StoragesController extends Controller {
);
}
- protected function formatStoragesForUI(array $storages): array {
- return array_map(function ($storage) {
- return $this->formatStorageForUI($storage);
- }, $storages);
- }
-
- protected function formatStorageForUI(StorageConfig $storage): StorageConfig {
- /** @var DefinitionParameter[] $parameters */
- $parameters = array_merge($storage->getBackend()->getParameters(), $storage->getAuthMechanism()->getParameters());
-
- $options = $storage->getBackendOptions();
- foreach ($options as $key => $value) {
- foreach ($parameters as $parameter) {
- if ($parameter->getName() === $key && $parameter->getType() === DefinitionParameter::VALUE_PASSWORD) {
- $storage->setBackendOption($key, DefinitionParameter::UNMODIFIED_PLACEHOLDER);
- break;
- }
- }
- }
-
- return $storage;
- }
-
/**
* Get an external storage entry.
*
@@ -370,9 +283,9 @@ abstract class StoragesController extends Controller {
);
}
- $data = $this->formatStorageForUI($storage)->jsonSerialize();
+ $data = $storage->jsonSerialize(true);
$isAdmin = $this->groupManager->isAdmin($this->userSession->getUser()->getUID());
- $data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl || $isAdmin;
+ $data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAL || $isAdmin;
return new DataResponse(
$data,
diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php
index 74424bce006..3d364fff57d 100644
--- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php
+++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php
@@ -1,28 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
@@ -35,13 +15,14 @@ use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* User global storages controller
@@ -54,7 +35,7 @@ class UserGlobalStoragesController extends StoragesController {
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserGlobalStoragesService $userGlobalStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
*/
@@ -63,7 +44,7 @@ class UserGlobalStoragesController extends StoragesController {
IRequest $request,
IL10N $l10n,
UserGlobalStoragesService $userGlobalStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
@@ -84,16 +65,16 @@ class UserGlobalStoragesController extends StoragesController {
* Get all storage entries
*
* @return DataResponse
- *
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
public function index() {
- $storages = $this->formatStoragesForUI($this->service->getUniqueStorages());
-
- // remove configuration data, this must be kept private
- foreach ($storages as $storage) {
+ /** @var UserGlobalStoragesService */
+ $service = $this->service;
+ $storages = array_map(function ($storage) {
+ // remove configuration data, this must be kept private
$this->sanitizeStorage($storage);
- }
+ return $storage->jsonSerialize(true);
+ }, $service->getUniqueStorages());
return new DataResponse(
$storages,
@@ -116,9 +97,8 @@ class UserGlobalStoragesController extends StoragesController {
* @param int $id storage id
* @param bool $testOnly whether to storage should only test the connection or do more things
* @return DataResponse
- *
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
public function show($id, $testOnly = true) {
try {
$storage = $this->service->getStorage($id);
@@ -135,9 +115,9 @@ class UserGlobalStoragesController extends StoragesController {
$this->sanitizeStorage($storage);
- $data = $this->formatStorageForUI($storage)->jsonSerialize();
+ $data = $storage->jsonSerialize(true);
$isAdmin = $this->groupManager->isAdmin($this->userSession->getUser()->getUID());
- $data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl || $isAdmin;
+ $data['can_edit'] = $storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAL || $isAdmin;
return new DataResponse(
$data,
@@ -154,9 +134,8 @@ class UserGlobalStoragesController extends StoragesController {
* @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
- *
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
public function update(
$id,
$backendOptions,
@@ -171,7 +150,7 @@ class UserGlobalStoragesController extends StoragesController {
} else {
return new DataResponse(
[
- 'message' => $this->l10n->t('Storage with ID "%d" is not user editable', [$id])
+ 'message' => $this->l10n->t('Storage with ID "%d" is not editable by non-admins', [$id])
],
Http::STATUS_FORBIDDEN
);
@@ -189,7 +168,7 @@ class UserGlobalStoragesController extends StoragesController {
$this->sanitizeStorage($storage);
return new DataResponse(
- $this->formatStorageForUI($storage),
+ $storage->jsonSerialize(true),
Http::STATUS_OK
);
}
diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php
index c0a460fd8e3..a85aa3faa96 100644
--- a/apps/files_external/lib/Controller/UserStoragesController.php
+++ b/apps/files_external/lib/Controller/UserStoragesController.php
@@ -1,30 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_External\Controller;
@@ -34,13 +12,14 @@ use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
+use Psr\Log\LoggerInterface;
/**
* User storages controller
@@ -53,7 +32,7 @@ class UserStoragesController extends StoragesController {
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param UserStoragesService $userStoragesService storage service
- * @param ILogger $logger
+ * @param LoggerInterface $logger
* @param IUserSession $userSession
* @param IGroupManager $groupManager
*/
@@ -62,7 +41,7 @@ class UserStoragesController extends StoragesController {
IRequest $request,
IL10N $l10n,
UserStoragesService $userStoragesService,
- ILogger $logger,
+ LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
@@ -91,10 +70,9 @@ class UserStoragesController extends StoragesController {
/**
* Get all storage entries
*
- * @NoAdminRequired
- *
* @return DataResponse
*/
+ #[NoAdminRequired]
public function index() {
return parent::index();
}
@@ -102,10 +80,9 @@ class UserStoragesController extends StoragesController {
/**
* Return storage
*
- * @NoAdminRequired
- *
* {@inheritdoc}
*/
+ #[NoAdminRequired]
public function show($id, $testOnly = true) {
return parent::show($id, $testOnly);
}
@@ -120,9 +97,8 @@ class UserStoragesController extends StoragesController {
* @param array $mountOptions backend-specific mount options
*
* @return DataResponse
- *
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
public function create(
$mountPoint,
$backend,
@@ -159,7 +135,7 @@ class UserStoragesController extends StoragesController {
$this->updateStorageStatus($newStorage);
return new DataResponse(
- $this->formatStorageForUI($newStorage),
+ $newStorage->jsonSerialize(true),
Http::STATUS_CREATED
);
}
@@ -176,9 +152,8 @@ class UserStoragesController extends StoragesController {
* @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
- *
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
public function update(
$id,
$mountPoint,
@@ -219,7 +194,7 @@ class UserStoragesController extends StoragesController {
$this->updateStorageStatus($storage, $testOnly);
return new DataResponse(
- $this->formatStorageForUI($storage),
+ $storage->jsonSerialize(true),
Http::STATUS_OK
);
}
@@ -227,10 +202,9 @@ class UserStoragesController extends StoragesController {
/**
* Delete storage
*
- * @NoAdminRequired
- *
* {@inheritdoc}
*/
+ #[NoAdminRequired]
public function destroy($id) {
return parent::destroy($id);
}