diff options
Diffstat (limited to 'apps/files_external/controller')
5 files changed, 0 insertions, 1022 deletions
diff --git a/apps/files_external/controller/ajaxcontroller.php b/apps/files_external/controller/ajaxcontroller.php deleted file mode 100644 index c3df3fa8522..00000000000 --- a/apps/files_external/controller/ajaxcontroller.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -/** - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Ross Nicoll <jrn@jrn.me.uk> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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/> - * - */ - -namespace OCA\Files_External\Controller; - -use OCP\AppFramework\Controller; -use OCP\IRequest; -use OCP\AppFramework\Http\JSONResponse; -use OCA\Files_External\Lib\Auth\PublicKey\RSA; - -class AjaxController extends Controller { - /** @var RSA */ - private $rsaMechanism; - - public function __construct($appName, IRequest $request, RSA $rsaMechanism) { - parent::__construct($appName, $request); - $this->rsaMechanism = $rsaMechanism; - } - - private function generateSshKeys() { - $key = $this->rsaMechanism->createKey(); - // Replace the placeholder label with a more meaningful one - $key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']); - - return $key; - } - - /** - * Generates an SSH public/private key pair. - * - * @NoAdminRequired - */ - public function getSshKeys() { - $key = $this->generateSshKeys(); - return new JSONResponse( - array('data' => array( - 'private_key' => $key['privatekey'], - 'public_key' => $key['publickey'] - ), - 'status' => 'success' - )); - } -} diff --git a/apps/files_external/controller/globalstoragescontroller.php b/apps/files_external/controller/globalstoragescontroller.php deleted file mode 100644 index b443cf4ea8f..00000000000 --- a/apps/files_external/controller/globalstoragescontroller.php +++ /dev/null @@ -1,189 +0,0 @@ -<?php -/** - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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/> - * - */ - -namespace OCA\Files_External\Controller; - - -use \OCP\IConfig; -use OCP\ILogger; -use \OCP\IUserSession; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; -use \OCA\Files_external\Service\GlobalStoragesService; -use \OCA\Files_external\NotFoundException; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_External\Service\BackendService; - -/** - * Global storages controller - */ -class GlobalStoragesController extends StoragesController { - /** - * Creates a new global storages controller. - * - * @param string $AppName application name - * @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, - ILogger $logger - ) { - parent::__construct( - $AppName, - $request, - $l10n, - $globalStoragesService, - $logger - ); - } - - /** - * Create an external storage entry. - * - * @param string $mountPoint storage mount point - * @param string $backend backend identifier - * @param string $authMechanism authentication mechanism identifier - * @param array $backendOptions backend-specific options - * @param array $mountOptions mount-specific options - * @param array $applicableUsers users for which to mount the storage - * @param array $applicableGroups groups for which to mount the storage - * @param int $priority priority - * - * @return DataResponse - */ - public function create( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions, - $applicableUsers, - $applicableGroups, - $priority - ) { - $newStorage = $this->createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions, - $applicableUsers, - $applicableGroups, - $priority - ); - if ($newStorage instanceof DataResponse) { - return $newStorage; - } - - $response = $this->validate($newStorage); - if (!empty($response)) { - return $response; - } - - $newStorage = $this->service->addStorage($newStorage); - - $this->updateStorageStatus($newStorage); - - return new DataResponse( - $newStorage, - Http::STATUS_CREATED - ); - } - - /** - * Update an external storage entry. - * - * @param int $id storage id - * @param string $mountPoint storage mount point - * @param string $backend backend identifier - * @param string $authMechanism authentication mechansim identifier - * @param array $backendOptions backend-specific options - * @param array $mountOptions mount-specific options - * @param array $applicableUsers users for which to mount the storage - * @param array $applicableGroups groups for which to mount the storage - * @param int $priority priority - * - * @return DataResponse - */ - public function update( - $id, - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions, - $applicableUsers, - $applicableGroups, - $priority - ) { - $storage = $this->createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions, - $applicableUsers, - $applicableGroups, - $priority - ); - if ($storage instanceof DataResponse) { - return $storage; - } - $storage->setId($id); - - $response = $this->validate($storage); - if (!empty($response)) { - return $response; - } - - try { - $storage = $this->service->updateStorage($storage); - } 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); - - return new DataResponse( - $storage, - Http::STATUS_OK - ); - - } - - -} diff --git a/apps/files_external/controller/storagescontroller.php b/apps/files_external/controller/storagescontroller.php deleted file mode 100644 index 09b83104700..00000000000 --- a/apps/files_external/controller/storagescontroller.php +++ /dev/null @@ -1,342 +0,0 @@ -<?php -/** - * @author Jesús Macias <jmacias@solidgear.es> - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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/> - * - */ - -namespace OCA\Files_External\Controller; - - -use \OCP\IConfig; -use OCP\ILogger; -use OCP\IUser; -use \OCP\IUserSession; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; -use \OCA\Files_external\Service\StoragesService; -use \OCA\Files_external\NotFoundException; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCP\Files\StorageNotAvailableException; -use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; -use \OCA\Files_External\Service\BackendService; - -/** - * Base class for storages controllers - */ -abstract class StoragesController extends Controller { - - /** - * L10N service - * - * @var IL10N - */ - protected $l10n; - - /** - * Storages service - * - * @var StoragesService - */ - 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, - ILogger $logger - ) { - parent::__construct($AppName, $request); - $this->l10n = $l10n; - $this->service = $storagesService; - $this->logger = $logger; - } - - /** - * Create a storage from its parameters - * - * @param string $mountPoint storage mount point - * @param string $backend backend identifier - * @param string $authMechanism authentication mechanism identifier - * @param array $backendOptions backend-specific options - * @param array|null $mountOptions mount-specific options - * @param array|null $applicableUsers users for which to mount the storage - * @param array|null $applicableGroups groups for which to mount the storage - * @param int|null $priority priority - * - * @return StorageConfig|DataResponse - */ - protected function createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions = null, - $applicableUsers = null, - $applicableGroups = null, - $priority = null - ) { - try { - return $this->service->createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions, - $applicableUsers, - $applicableGroups, - $priority - ); - } catch (\InvalidArgumentException $e) { - $this->logger->logException($e); - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class') - ], - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - } - - /** - * Validate storage config - * - * @param StorageConfig $storage storage config - *1 - * @return DataResponse|null returns response in case of validation error - */ - protected function validate(StorageConfig $storage) { - $mountPoint = $storage->getMountPoint(); - if ($mountPoint === '' || $mountPoint === '/') { - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Invalid mount point') - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - if ($storage->getBackendOption('objectstore')) { - // objectstore must not be sent from client side - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Objectstore forbidden') - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - /** @var Backend */ - $backend = $storage->getBackend(); - /** @var AuthMechanism */ - $authMechanism = $storage->getAuthMechanism(); - if ($backend->checkDependencies()) { - // invalid backend - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [ - $backend->getIdentifier() - ]) - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - if (!$backend->isVisibleFor($this->service->getVisibilityType())) { - // not permitted to use backend - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [ - $backend->getIdentifier() - ]) - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) { - // not permitted to use auth mechanism - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [ - $authMechanism->getIdentifier() - ]) - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - if (!$backend->validateStorage($storage)) { - // unsatisfied parameters - return new DataResponse( - array( - 'message' => (string)$this->l10n->t('Unsatisfied backend parameters') - ), - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - if (!$authMechanism->validateStorage($storage)) { - // unsatisfied parameters - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters') - ], - Http::STATUS_UNPROCESSABLE_ENTITY - ); - } - - 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. - * - * Note that this operation can be time consuming depending - * on whether the remote storage is available or not. - * - * @param StorageConfig $storage storage configuration - */ - protected function updateStorageStatus(StorageConfig &$storage) { - try { - $this->manipulateStorageConfig($storage); - - /** @var Backend */ - $backend = $storage->getBackend(); - // update status (can be time-consuming) - $storage->setStatus( - \OC_Mount_Config::getBackendStatus( - $backend->getStorageClass(), - $storage->getBackendOptions(), - false - ) - ); - } catch (InsufficientDataForMeaningfulAnswerException $e) { - $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; - $storage->setStatus( - $status, - $this->l10n->t('Insufficient data: %s', [$e->getMessage()]) - ); - } catch (StorageNotAvailableException $e) { - $storage->setStatus( - $e->getCode(), - $this->l10n->t('%s', [$e->getMessage()]) - ); - } catch (\Exception $e) { - // FIXME: convert storage exceptions to StorageNotAvailableException - $storage->setStatus( - StorageNotAvailableException::STATUS_ERROR, - get_class($e).': '.$e->getMessage() - ); - } - } - - /** - * Get all storage entries - * - * @return DataResponse - */ - public function index() { - $storages = $this->service->getStorages(); - - return new DataResponse( - $storages, - Http::STATUS_OK - ); - } - - /** - * Get an external storage entry. - * - * @param int $id storage id - * - * @return DataResponse - */ - public function show($id) { - try { - $storage = $this->service->getStorage($id); - - $this->updateStorageStatus($storage); - } catch (NotFoundException $e) { - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Storage with id "%i" not found', array($id)) - ], - Http::STATUS_NOT_FOUND - ); - } - - return new DataResponse( - $storage, - Http::STATUS_OK - ); - } - - /** - * Deletes the storage with the given id. - * - * @param int $id storage id - * - * @return DataResponse - */ - public function destroy($id) { - try { - $this->service->removeStorage($id); - } catch (NotFoundException $e) { - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Storage with id "%i" not found', array($id)) - ], - Http::STATUS_NOT_FOUND - ); - } - - return new DataResponse([], Http::STATUS_NO_CONTENT); - } - -} - diff --git a/apps/files_external/controller/userglobalstoragescontroller.php b/apps/files_external/controller/userglobalstoragescontroller.php deleted file mode 100644 index 36c3740eed3..00000000000 --- a/apps/files_external/controller/userglobalstoragescontroller.php +++ /dev/null @@ -1,201 +0,0 @@ -<?php -/** - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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/> - * - */ - -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\Http; -use \OCA\Files_external\Service\UserGlobalStoragesService; -use \OCA\Files_external\NotFoundException; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; -use OCP\IUserSession; - -/** - * User global storages controller - */ -class UserGlobalStoragesController extends StoragesController { - /** - * @var IUserSession - */ - private $userSession; - - /** - * Creates a new user global storages controller. - * - * @param string $AppName application name - * @param IRequest $request request object - * @param IL10N $l10n l10n service - * @param UserGlobalStoragesService $userGlobalStoragesService storage service - * @param IUserSession $userSession - */ - public function __construct( - $AppName, - IRequest $request, - IL10N $l10n, - UserGlobalStoragesService $userGlobalStoragesService, - IUserSession $userSession, - ILogger $logger - ) { - parent::__construct( - $AppName, - $request, - $l10n, - $userGlobalStoragesService, - $logger - ); - $this->userSession = $userSession; - } - - /** - * Get all storage entries - * - * @return DataResponse - * - * @NoAdminRequired - */ - public function index() { - $storages = $this->service->getUniqueStorages(); - - // remove configuration data, this must be kept private - foreach ($storages as $storage) { - $this->sanitizeStorage($storage); - } - - return new DataResponse( - $storages, - Http::STATUS_OK - ); - } - - 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. - * - * @param int $id storage id - * @return DataResponse - * - * @NoAdminRequired - */ - public function show($id) { - try { - $storage = $this->service->getStorage($id); - - $this->updateStorageStatus($storage); - } catch (NotFoundException $e) { - return new DataResponse( - [ - 'message' => (string)$this->l10n->t('Storage with id "%i" not found', array($id)) - ], - Http::STATUS_NOT_FOUND - ); - } - - $this->sanitizeStorage($storage); - - return new DataResponse( - $storage, - Http::STATUS_OK - ); - } - - /** - * 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 - * - * @param StorageConfig $storage - */ - 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 - } - } - } - -} diff --git a/apps/files_external/controller/userstoragescontroller.php b/apps/files_external/controller/userstoragescontroller.php deleted file mode 100644 index e53ea21f005..00000000000 --- a/apps/files_external/controller/userstoragescontroller.php +++ /dev/null @@ -1,226 +0,0 @@ -<?php -/** - * @author Robin Appelman <icewind@owncloud.com> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @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/> - * - */ - -namespace OCA\Files_External\Controller; - - -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; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; -use \OCA\Files_external\Service\UserStoragesService; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_external\NotFoundException; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; - -/** - * 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 IUserSession $userSession - * @param ILogger $logger - */ - public function __construct( - $AppName, - IRequest $request, - IL10N $l10n, - UserStoragesService $userStoragesService, - IUserSession $userSession, - ILogger $logger - ) { - parent::__construct( - $AppName, - $request, - $l10n, - $userStoragesService, - $logger - ); - $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()); - } - - /** - * Get all storage entries - * - * @NoAdminRequired - * - * @return DataResponse - */ - public function index() { - return parent::index(); - } - - /** - * Return storage - * - * @NoAdminRequired - * - * {@inheritdoc} - */ - public function show($id) { - return parent::show($id); - } - - /** - * Create an external storage entry. - * - * @param string $mountPoint storage mount point - * @param string $backend backend identifier - * @param string $authMechanism authentication mechanism identifier - * @param array $backendOptions backend-specific options - * @param array $mountOptions backend-specific mount options - * - * @return DataResponse - * - * @NoAdminRequired - */ - public function create( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions - ) { - $newStorage = $this->createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions - ); - if ($newStorage instanceOf DataResponse) { - return $newStorage; - } - - $response = $this->validate($newStorage); - if (!empty($response)) { - return $response; - } - - $newStorage = $this->service->addStorage($newStorage); - $this->updateStorageStatus($newStorage); - - return new DataResponse( - $newStorage, - Http::STATUS_CREATED - ); - } - - /** - * Update an external storage entry. - * - * @param int $id storage id - * @param string $mountPoint storage mount point - * @param string $backend backend identifier - * @param string $authMechanism authentication mechanism identifier - * @param array $backendOptions backend-specific options - * @param array $mountOptions backend-specific mount options - * - * @return DataResponse - * - * @NoAdminRequired - */ - public function update( - $id, - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions - ) { - $storage = $this->createStorage( - $mountPoint, - $backend, - $authMechanism, - $backendOptions, - $mountOptions - ); - if ($storage instanceOf DataResponse) { - return $storage; - } - $storage->setId($id); - - $response = $this->validate($storage); - if (!empty($response)) { - return $response; - } - - try { - $storage = $this->service->updateStorage($storage); - } 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); - - return new DataResponse( - $storage, - Http::STATUS_OK - ); - - } - - /** - * Delete storage - * - * @NoAdminRequired - * - * {@inheritdoc} - */ - public function destroy($id) { - return parent::destroy($id); - } - -} |