Skip to content
1 change: 1 addition & 0 deletions apps/files_external/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected function loadAuthMechanisms() {
$container->query('OCA\Files_External\Lib\Auth\Password\Password'),
$container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
$container->query('OCA\Files_External\Lib\Auth\Password\LoginCredentials'),
$container->query('OCA\Files_External\Lib\Auth\Password\UserProvided'),

// AuthMechanism::SCHEME_OAUTH1 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
Expand Down
8 changes: 6 additions & 2 deletions apps/files_external/controller/globalstoragescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


use \OCP\IConfig;
use OCP\ILogger;
use \OCP\IUserSession;
use \OCP\IRequest;
use \OCP\IL10N;
Expand All @@ -46,18 +47,21 @@ class GlobalStoragesController extends StoragesController {
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param GlobalStoragesService $globalStoragesService storage service
* @param ILogger $logger
*/
public function __construct(
$AppName,
IRequest $request,
IL10N $l10n,
GlobalStoragesService $globalStoragesService
GlobalStoragesService $globalStoragesService,
ILogger $logger
) {
parent::__construct(
$AppName,
$request,
$l10n,
$globalStoragesService
$globalStoragesService,
$logger
);
}

Expand Down
15 changes: 13 additions & 2 deletions apps/files_external/controller/storagescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@


use \OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use \OCP\IUserSession;
use \OCP\IRequest;
use \OCP\IL10N;
Expand Down Expand Up @@ -59,23 +61,31 @@ abstract class StoragesController extends Controller {
*/
protected $service;

/**
* @var ILogger
*/
protected $logger;

/**
* Creates a new storages controller.
*
* @param string $AppName application name
* @param IRequest $request request object
* @param IL10N $l10n l10n service
* @param StoragesService $storagesService storage service
* @param ILogger $logger
*/
public function __construct(
$AppName,
IRequest $request,
IL10N $l10n,
StoragesService $storagesService
StoragesService $storagesService,
ILogger $logger
) {
parent::__construct($AppName, $request);
$this->l10n = $l10n;
$this->service = $storagesService;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -114,6 +124,7 @@ protected function createStorage(
$priority
);
} catch (\InvalidArgumentException $e) {
$this->logger->logException($e);
return new DataResponse(
[
'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class')
Expand All @@ -127,7 +138,7 @@ protected function createStorage(
* Validate storage config
*
* @param StorageConfig $storage storage config
*
*1
* @return DataResponse|null returns response in case of validation error
*/
protected function validate(StorageConfig $storage) {
Expand Down
66 changes: 63 additions & 3 deletions apps/files_external/controller/userglobalstoragescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
namespace OCA\Files_External\Controller;

use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\IUserProvided;
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
use OCP\ILogger;
use \OCP\IRequest;
use \OCP\IL10N;
use \OCP\AppFramework\Http\DataResponse;
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http;
use \OCA\Files_external\Service\UserGlobalStoragesService;
use \OCA\Files_external\NotFoundException;
Expand Down Expand Up @@ -56,13 +58,15 @@ public function __construct(
IRequest $request,
IL10N $l10n,
UserGlobalStoragesService $userGlobalStoragesService,
IUserSession $userSession
IUserSession $userSession,
ILogger $logger
) {
parent::__construct(
$AppName,
$request,
$l10n,
$userGlobalStoragesService
$userGlobalStoragesService,
$logger
);
$this->userSession = $userSession;
}
Expand Down Expand Up @@ -127,6 +131,54 @@ public function show($id) {
);
}

/**
* Update an external storage entry.
* Only allows setting user provided backend fields
*
* @param int $id storage id
* @param array $backendOptions backend-specific options
*
* @return DataResponse
*
* @NoAdminRequired
*/
public function update(
$id,
$backendOptions
) {
try {
$storage = $this->service->getStorage($id);
$authMechanism = $storage->getAuthMechanism();
if ($authMechanism instanceof IUserProvided) {
$authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
} else {
return new DataResponse(
[
'message' => (string)$this->l10n->t('Storage with id "%i" is not user editable', array($id))
],
Http::STATUS_FORBIDDEN
);
}
} catch (NotFoundException $e) {
return new DataResponse(
[
'message' => (string)$this->l10n->t('Storage with id "%i" not found', array($id))
],
Http::STATUS_NOT_FOUND
);
}

$this->updateStorageStatus($storage);
$this->sanitizeStorage($storage);

return new DataResponse(
$storage,
Http::STATUS_OK
);

}

/**
* Remove sensitive data from a StorageConfig before returning it to the user
*
Expand All @@ -135,6 +187,14 @@ public function show($id) {
protected function sanitizeStorage(StorageConfig $storage) {
$storage->setBackendOptions([]);
$storage->setMountOptions([]);

if ($storage->getAuthMechanism() instanceof IUserProvided) {
try {
$storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
} catch (InsufficientDataForMeaningfulAnswerException $e) {
// not configured yet
}
}
}

}
9 changes: 7 additions & 2 deletions apps/files_external/controller/userstoragescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

use OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use \OCP\IUserSession;
use \OCP\IRequest;
use \OCP\IL10N;
Expand Down Expand Up @@ -54,19 +56,22 @@ class UserStoragesController extends StoragesController {
* @param IL10N $l10n l10n service
* @param UserStoragesService $userStoragesService storage service
* @param IUserSession $userSession
* @param ILogger $logger
*/
public function __construct(
$AppName,
IRequest $request,
IL10N $l10n,
UserStoragesService $userStoragesService,
IUserSession $userSession
IUserSession $userSession,
ILogger $logger
) {
parent::__construct(
$AppName,
$request,
$l10n,
$userStoragesService
$userStoragesService,
$logger
);
$this->userSession = $userSession;
}
Expand Down
Loading