Pass the user when updating external storage status

This commit is contained in:
Robin Appelman 2016-01-05 16:56:09 +01:00
parent 3fe802d931
commit 7e01f32c27
3 changed files with 50 additions and 7 deletions

View File

@ -212,6 +212,15 @@ abstract class StoragesController extends Controller {
return null; return null;
} }
protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage);
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage);
}
/** /**
* Check whether the given storage is available / valid. * Check whether the given storage is available / valid.
* *
@ -222,13 +231,10 @@ abstract class StoragesController extends Controller {
*/ */
protected function updateStorageStatus(StorageConfig &$storage) { protected function updateStorageStatus(StorageConfig &$storage) {
try { try {
/** @var AuthMechanism */ $this->manipulateStorageConfig($storage);
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage);
/** @var Backend */ /** @var Backend */
$backend = $storage->getBackend(); $backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage);
// update status (can be time-consuming) // update status (can be time-consuming)
$storage->setStatus( $storage->setStatus(
\OC_Mount_Config::getBackendStatus( \OC_Mount_Config::getBackendStatus(

View File

@ -21,6 +21,7 @@
namespace OCA\Files_External\Controller; namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCP\IRequest; use \OCP\IRequest;
use \OCP\IL10N; use \OCP\IL10N;
use \OCP\AppFramework\Http\DataResponse; use \OCP\AppFramework\Http\DataResponse;
@ -30,11 +31,17 @@ use \OCA\Files_external\Service\UserGlobalStoragesService;
use \OCA\Files_external\NotFoundException; use \OCA\Files_external\NotFoundException;
use \OCA\Files_external\Lib\StorageConfig; use \OCA\Files_external\Lib\StorageConfig;
use \OCA\Files_External\Lib\Backend\Backend; use \OCA\Files_External\Lib\Backend\Backend;
use OCP\IUserSession;
/** /**
* User global storages controller * User global storages controller
*/ */
class UserGlobalStoragesController extends StoragesController { class UserGlobalStoragesController extends StoragesController {
/**
* @var IUserSession
*/
private $userSession;
/** /**
* Creates a new user global storages controller. * Creates a new user global storages controller.
* *
@ -42,12 +49,14 @@ class UserGlobalStoragesController extends StoragesController {
* @param IRequest $request request object * @param IRequest $request request object
* @param IL10N $l10n l10n service * @param IL10N $l10n l10n service
* @param UserGlobalStoragesService $userGlobalStoragesService storage service * @param UserGlobalStoragesService $userGlobalStoragesService storage service
* @param IUserSession $userSession
*/ */
public function __construct( public function __construct(
$AppName, $AppName,
IRequest $request, IRequest $request,
IL10N $l10n, IL10N $l10n,
UserGlobalStoragesService $userGlobalStoragesService UserGlobalStoragesService $userGlobalStoragesService,
IUserSession $userSession
) { ) {
parent::__construct( parent::__construct(
$AppName, $AppName,
@ -55,6 +64,7 @@ class UserGlobalStoragesController extends StoragesController {
$l10n, $l10n,
$userGlobalStoragesService $userGlobalStoragesService
); );
$this->userSession = $userSession;
} }
/** /**
@ -78,12 +88,22 @@ class UserGlobalStoragesController extends StoragesController {
); );
} }
protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
}
/** /**
* Get an external storage entry. * Get an external storage entry.
* *
* @param int $id storage id * @param int $id storage id
* @return DataResponse * @return DataResponse
* *
* @NoCSRFRequired
* @NoAdminRequired * @NoAdminRequired
*/ */
public function show($id) { public function show($id) {

View File

@ -23,6 +23,7 @@
namespace OCA\Files_External\Controller; namespace OCA\Files_External\Controller;
use OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCP\IConfig; use \OCP\IConfig;
use \OCP\IUserSession; use \OCP\IUserSession;
use \OCP\IRequest; use \OCP\IRequest;
@ -40,6 +41,11 @@ use \OCA\Files_External\Lib\Backend\Backend;
* User storages controller * User storages controller
*/ */
class UserStoragesController extends StoragesController { class UserStoragesController extends StoragesController {
/**
* @var IUserSession
*/
private $userSession;
/** /**
* Creates a new user storages controller. * Creates a new user storages controller.
* *
@ -52,7 +58,8 @@ class UserStoragesController extends StoragesController {
$AppName, $AppName,
IRequest $request, IRequest $request,
IL10N $l10n, IL10N $l10n,
UserStoragesService $userStoragesService UserStoragesService $userStoragesService,
IUserSession $userSession
) { ) {
parent::__construct( parent::__construct(
$AppName, $AppName,
@ -60,6 +67,16 @@ class UserStoragesController extends StoragesController {
$l10n, $l10n,
$userStoragesService $userStoragesService
); );
$this->userSession = $userSession;
}
protected function manipulateStorageConfig(StorageConfig $storage) {
/** @var AuthMechanism */
$authMechanism = $storage->getAuthMechanism();
$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
/** @var Backend */
$backend = $storage->getBackend();
$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
} }
/** /**