aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Controller/UserGlobalStoragesController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Controller/UserGlobalStoragesController.php')
-rw-r--r--apps/files_external/lib/Controller/UserGlobalStoragesController.php61
1 files changed, 20 insertions, 41 deletions
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
);
}