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.php30
-rw-r--r--apps/files_external/lib/Controller/GlobalStoragesController.php5
-rw-r--r--apps/files_external/lib/Controller/StoragesController.php11
-rw-r--r--apps/files_external/lib/Controller/UserGlobalStoragesController.php10
-rw-r--r--apps/files_external/lib/Controller/UserStoragesController.php9
5 files changed, 35 insertions, 30 deletions
diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php
index 3332044c948..5cee6422530 100644
--- a/apps/files_external/lib/Controller/AjaxController.php
+++ b/apps/files_external/lib/Controller/AjaxController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,10 +10,12 @@ 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;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IGroupManager;
+use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
@@ -32,6 +35,7 @@ class AjaxController extends Controller {
private GlobalAuth $globalAuth,
private IUserSession $userSession,
private IGroupManager $groupManager,
+ private IL10N $l10n,
) {
parent::__construct($appName, $request);
}
@@ -56,27 +60,30 @@ class AjaxController extends Controller {
#[NoAdminRequired]
public function getSshKeys($keyLength = 1024) {
$key = $this->generateSshKeys($keyLength);
- return new JSONResponse(
- ['data' => [
+ return new JSONResponse([
+ 'data' => [
'private_key' => $key['privatekey'],
'public_key' => $key['publickey']
],
- 'status' => 'success'
- ]);
+ 'status' => 'success',
+ ]);
}
/**
* @param string $uid
* @param string $user
* @param string $password
- * @return bool
+ * @return JSONResponse
*/
#[NoAdminRequired]
#[PasswordConfirmationRequired(strict: true)]
- public function saveGlobalCredentials($uid, $user, $password) {
+ public function saveGlobalCredentials($uid, $user, $password): JSONResponse {
$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
- return false;
+ return new JSONResponse([
+ 'status' => 'error',
+ 'message' => $this->l10n->t('You are not logged in'),
+ ], Http::STATUS_UNAUTHORIZED);
}
// Non-admins can only edit their own credentials
@@ -87,9 +94,14 @@ class AjaxController extends Controller {
if ($allowedToEdit) {
$this->globalAuth->saveAuth($uid, $user, $password);
- return true;
+ return new JSONResponse([
+ 'status' => 'success',
+ ]);
}
- return false;
+ return new JSONResponse([
+ 'status' => 'success',
+ 'message' => $this->l10n->t('Permission denied'),
+ ], Http::STATUS_FORBIDDEN);
}
}
diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php
index 466c4f6f551..e7274c9cfb6 100644
--- a/apps/files_external/lib/Controller/GlobalStoragesController.php
+++ b/apps/files_external/lib/Controller/GlobalStoragesController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -132,7 +133,6 @@ class GlobalStoragesController extends StoragesController {
* @param array $applicableUsers users for which to mount the storage
* @param array $applicableGroups groups for which to mount the storage
* @param int $priority priority
- * @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*/
@@ -147,7 +147,6 @@ class GlobalStoragesController extends StoragesController {
$applicableUsers,
$applicableGroups,
$priority,
- $testOnly = true,
) {
$storage = $this->createStorage(
$mountPoint,
@@ -180,7 +179,7 @@ class GlobalStoragesController extends StoragesController {
);
}
- $this->updateStorageStatus($storage, $testOnly);
+ $this->updateStorageStatus($storage);
return new DataResponse(
$storage->jsonSerialize(true),
diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php
index 72bcbd48a4c..df3a4528054 100644
--- a/apps/files_external/lib/Controller/StoragesController.php
+++ b/apps/files_external/lib/Controller/StoragesController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -212,9 +213,8 @@ abstract class StoragesController extends Controller {
* on whether the remote storage is available or not.
*
* @param StorageConfig $storage storage configuration
- * @param bool $testOnly whether to storage should only test the connection or do more things
*/
- protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) {
+ protected function updateStorageStatus(StorageConfig &$storage) {
try {
$this->manipulateStorageConfig($storage);
@@ -225,8 +225,6 @@ abstract class StoragesController extends Controller {
MountConfig::getBackendStatus(
$backend->getStorageClass(),
$storage->getBackendOptions(),
- false,
- $testOnly
)
);
} catch (InsufficientDataForMeaningfulAnswerException $e) {
@@ -267,15 +265,14 @@ abstract class StoragesController extends Controller {
* Get an external storage entry.
*
* @param int $id storage id
- * @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*/
- public function show(int $id, $testOnly = true) {
+ public function show(int $id) {
try {
$storage = $this->service->getStorage($id);
- $this->updateStorageStatus($storage, $testOnly);
+ $this->updateStorageStatus($storage);
} catch (NotFoundException $e) {
return new DataResponse(
[
diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php
index a7c4fc61997..88a9f936401 100644
--- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php
+++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -96,15 +97,14 @@ class UserGlobalStoragesController extends StoragesController {
* Get an external storage entry.
*
* @param int $id storage id
- * @param bool $testOnly whether to storage should only test the connection or do more things
* @return DataResponse
*/
#[NoAdminRequired]
- public function show($id, $testOnly = true) {
+ public function show($id) {
try {
$storage = $this->service->getStorage($id);
- $this->updateStorageStatus($storage, $testOnly);
+ $this->updateStorageStatus($storage);
} catch (NotFoundException $e) {
return new DataResponse(
[
@@ -132,7 +132,6 @@ class UserGlobalStoragesController extends StoragesController {
*
* @param int $id storage id
* @param array $backendOptions backend-specific options
- * @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*/
@@ -141,7 +140,6 @@ class UserGlobalStoragesController extends StoragesController {
public function update(
$id,
$backendOptions,
- $testOnly = true,
) {
try {
$storage = $this->service->getStorage($id);
@@ -166,7 +164,7 @@ class UserGlobalStoragesController extends StoragesController {
);
}
- $this->updateStorageStatus($storage, $testOnly);
+ $this->updateStorageStatus($storage);
$this->sanitizeStorage($storage);
return new DataResponse(
diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php
index 6d797b5818d..7b564d57f7e 100644
--- a/apps/files_external/lib/Controller/UserStoragesController.php
+++ b/apps/files_external/lib/Controller/UserStoragesController.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -84,8 +85,8 @@ class UserStoragesController extends StoragesController {
* {@inheritdoc}
*/
#[NoAdminRequired]
- public function show(int $id, $testOnly = true) {
- return parent::show($id, $testOnly);
+ public function show(int $id) {
+ return parent::show($id);
}
/**
@@ -151,7 +152,6 @@ 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
*/
@@ -164,7 +164,6 @@ class UserStoragesController extends StoragesController {
$authMechanism,
$backendOptions,
$mountOptions,
- $testOnly = true,
) {
$storage = $this->createStorage(
$mountPoint,
@@ -194,7 +193,7 @@ class UserStoragesController extends StoragesController {
);
}
- $this->updateStorageStatus($storage, $testOnly);
+ $this->updateStorageStatus($storage);
return new DataResponse(
$storage->jsonSerialize(true),