diff options
Diffstat (limited to 'apps/files_external/lib/Controller/UserStoragesController.php')
-rw-r--r-- | apps/files_external/lib/Controller/UserStoragesController.php | 119 |
1 files changed, 53 insertions, 66 deletions
diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 724bdd01463..7b564d57f7e 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -1,79 +1,63 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.com> - * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Vincent Petry <pvince81@owncloud.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 OCP\ILogger; -use \OCP\IUserSession; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Http; -use OCA\Files_External\Service\UserStoragesService; -use OCA\Files_External\NotFoundException; +use OCA\Files_External\Lib\Backend\Backend; use OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; +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\Attribute\PasswordConfirmationRequired; +use OCP\AppFramework\Http\DataResponse; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IRequest; +use OCP\IUserSession; +use Psr\Log\LoggerInterface; /** * User storages controller */ class UserStoragesController extends StoragesController { /** - * @var IUserSession - */ - private $userSession; - - /** * Creates a new user storages controller. * * @param string $AppName application name * @param IRequest $request request object * @param IL10N $l10n l10n service * @param UserStoragesService $userStoragesService storage service + * @param LoggerInterface $logger * @param IUserSession $userSession - * @param ILogger $logger + * @param IGroupManager $groupManager */ public function __construct( $AppName, IRequest $request, IL10N $l10n, UserStoragesService $userStoragesService, + LoggerInterface $logger, IUserSession $userSession, - ILogger $logger + IGroupManager $groupManager, + IConfig $config, ) { parent::__construct( $AppName, $request, $l10n, $userStoragesService, - $logger + $logger, + $userSession, + $groupManager, + $config ); - $this->userSession = $userSession; } protected function manipulateStorageConfig(StorageConfig $storage) { @@ -88,10 +72,9 @@ class UserStoragesController extends StoragesController { /** * Get all storage entries * - * @NoAdminRequired - * * @return DataResponse */ + #[NoAdminRequired] public function index() { return parent::index(); } @@ -99,12 +82,11 @@ class UserStoragesController extends StoragesController { /** * Return storage * - * @NoAdminRequired - * * {@inheritdoc} */ - public function show($id, $testOnly = true) { - return parent::show($id, $testOnly); + #[NoAdminRequired] + public function show(int $id) { + return parent::show($id); } /** @@ -117,16 +99,25 @@ class UserStoragesController extends StoragesController { * @param array $mountOptions backend-specific mount options * * @return DataResponse - * - * @NoAdminRequired */ + #[NoAdminRequired] + #[PasswordConfirmationRequired(strict: true)] public function create( $mountPoint, $backend, $authMechanism, $backendOptions, - $mountOptions + $mountOptions, ) { + $canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true); + if (!$canCreateNewLocalStorage && $backend === 'local') { + return new DataResponse( + [ + 'message' => $this->l10n->t('Forbidden to manage local mounts') + ], + Http::STATUS_FORBIDDEN + ); + } $newStorage = $this->createStorage( $mountPoint, $backend, @@ -134,7 +125,7 @@ class UserStoragesController extends StoragesController { $backendOptions, $mountOptions ); - if ($newStorage instanceOf DataResponse) { + if ($newStorage instanceof DataResponse) { return $newStorage; } @@ -147,7 +138,7 @@ class UserStoragesController extends StoragesController { $this->updateStorageStatus($newStorage); return new DataResponse( - $newStorage, + $newStorage->jsonSerialize(true), Http::STATUS_CREATED ); } @@ -161,12 +152,11 @@ class UserStoragesController extends StoragesController { * @param string $authMechanism authentication mechanism identifier * @param array $backendOptions backend-specific options * @param array $mountOptions backend-specific mount options - * @param bool $testOnly whether to storage should only test the connection or do more things * * @return DataResponse - * - * @NoAdminRequired */ + #[NoAdminRequired] + #[PasswordConfirmationRequired(strict: true)] public function update( $id, $mountPoint, @@ -174,7 +164,6 @@ class UserStoragesController extends StoragesController { $authMechanism, $backendOptions, $mountOptions, - $testOnly = true ) { $storage = $this->createStorage( $mountPoint, @@ -183,7 +172,7 @@ class UserStoragesController extends StoragesController { $backendOptions, $mountOptions ); - if ($storage instanceOf DataResponse) { + if ($storage instanceof DataResponse) { return $storage; } $storage->setId($id); @@ -198,30 +187,28 @@ class UserStoragesController extends StoragesController { } catch (NotFoundException $e) { return new DataResponse( [ - 'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id)) + 'message' => $this->l10n->t('Storage with ID "%d" not found', [$id]) ], Http::STATUS_NOT_FOUND ); } - $this->updateStorageStatus($storage, $testOnly); + $this->updateStorageStatus($storage); return new DataResponse( - $storage, + $storage->jsonSerialize(true), Http::STATUS_OK ); - } /** * Delete storage * - * @NoAdminRequired - * * {@inheritdoc} */ - public function destroy($id) { + #[NoAdminRequired] + #[PasswordConfirmationRequired(strict: true)] + public function destroy(int $id) { return parent::destroy($id); } - } |