diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-09-04 14:17:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-04 14:17:28 +0200 |
commit | 30ca3b70edea01dea092e495db1acf85183bfb80 (patch) | |
tree | 0261443100bc8867f600d2668d1c93d21268ffce | |
parent | c04a494ea7c960c0a6b85c0826f02f35a07c8886 (diff) | |
parent | 0326c2c54fe26dc742ebe00c66bd0363e083712d (diff) | |
download | nextcloud-server-30ca3b70edea01dea092e495db1acf85183bfb80.tar.gz nextcloud-server-30ca3b70edea01dea092e495db1acf85183bfb80.zip |
Merge pull request #6196 from nextcloud/downstream-26539-2
Handle invalid ext storage backend to keep mount point visible
-rw-r--r-- | apps/files_external/js/settings.js | 14 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Auth/InvalidAuth.php | 44 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Backend/InvalidBackend.php | 65 | ||||
-rw-r--r-- | apps/files_external/lib/Service/StoragesService.php | 10 | ||||
-rw-r--r-- | core/Controller/LoginController.php | 1 | ||||
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 7 |
6 files changed, 138 insertions, 3 deletions
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 112676b8c27..30074ab179a 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -805,6 +805,13 @@ MountConfigListView.prototype = _.extend({ var mountPoint = storageConfig.mountPoint; var backend = this._allBackends[storageConfig.backend]; + if (!backend) { + backend = { + name: 'Unknown: ' + storageConfig.backend, + invalid: true + }; + } + // FIXME: Replace with a proper Handlebar template var $tr = this.$el.find('tr#addMountPoint'); this.$el.find('tbody').append($tr.clone()); @@ -829,6 +836,13 @@ MountConfigListView.prototype = _.extend({ $tr.addClass(backend.identifier); $tr.find('.backend').data('identifier', backend.identifier); + if (backend.invalid) { + $tr.find('[name=mountPoint]').prop('disabled', true); + $tr.find('.applicable,.mountOptionsToggle').empty(); + this.updateStatus($tr, false, 'Unknown backend: ' + backend.name); + return $tr; + } + var selectAuthMechanism = $('<select class="selectAuthMechanism"></select>'); var neededVisibility = (this._isPersonal) ? StorageConfig.Visibility.PERSONAL : StorageConfig.Visibility.ADMIN; $.each(this._allAuthMechanisms, function(authIdentifier, authMechanism) { diff --git a/apps/files_external/lib/Lib/Auth/InvalidAuth.php b/apps/files_external/lib/Lib/Auth/InvalidAuth.php new file mode 100644 index 00000000000..c99eaa73d16 --- /dev/null +++ b/apps/files_external/lib/Lib/Auth/InvalidAuth.php @@ -0,0 +1,44 @@ +<?php +/** + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @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\Lib\Auth; + +/** + * Invalid authentication representing an auth mechanism + * that could not be resolved0 + */ +class InvalidAuth extends AuthMechanism { + + /** + * Constructs a new InvalidAuth with the id of the invalid auth + * for display purposes + * + * @param string $invalidId invalid id + */ + public function __construct($invalidId) { + $this + ->setIdentifier($invalidId) + ->setScheme(self::SCHEME_NULL) + ->setText('Unknown auth mechanism backend ' . $invalidId) + ; + } + +} diff --git a/apps/files_external/lib/Lib/Backend/InvalidBackend.php b/apps/files_external/lib/Lib/Backend/InvalidBackend.php new file mode 100644 index 00000000000..6c8eda22d07 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/InvalidBackend.php @@ -0,0 +1,65 @@ +<?php +/** + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @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\Lib\Backend; + +use OCA\Files_External\Lib\Storage\InvalidStorage; +use OCA\Files_External\Lib\StorageConfig; +use OCP\Files\StorageNotAvailableException; +use OCP\IUser; + +/** + * Invalid storage backend representing a backend + * that could not be resolved + */ +class InvalidBackend extends Backend { + + /** @var string Invalid backend id */ + private $invalidId; + + /** + * Constructs a new InvalidBackend with the id of the invalid backend + * for display purposes + * + * @param string $invalidId id of the backend that did not exist + */ + function __construct($invalidId) { + $this->invalidId = $invalidId; + $this + ->setIdentifier($invalidId) + ->setStorageClass('\OC\Files\Storage\FailedStorage') + ->setText('Unknown storage backend ' . $invalidId); + } + + /** + * Returns the invalid backend id + * + * @return string invalid backend id + */ + public function getInvalidId() { + return $this->invalidId; + } + + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + $storage->setBackendOption('exception', new \Exception('Unknown storage backend "' . $this->invalidId . '"', StorageNotAvailableException::STATUS_ERROR)); + } +} + diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index 4e38ea96259..d52bf410461 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -29,6 +29,8 @@ namespace OCA\Files_External\Service; use \OC\Files\Filesystem; +use OCA\Files_External\Lib\Auth\InvalidAuth; +use OCA\Files_External\Lib\Backend\InvalidBackend; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; use \OCA\Files_External\Lib\Backend\Backend; @@ -295,11 +297,11 @@ abstract class StoragesService { ) { $backend = $this->backendService->getBackend($backendIdentifier); if (!$backend) { - throw new \InvalidArgumentException('Unable to get backend for ' . $backendIdentifier); + $backend = new InvalidBackend($backendIdentifier); } $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); if (!$authMechanism) { - throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier); + $authMechanism = new InvalidAuth($authMechanismIdentifier); } $newStorage = new StorageConfig(); $newStorage->setMountPoint($mountPoint); @@ -382,6 +384,10 @@ abstract class StoragesService { $oldStorage = $this->getStorageConfigFromDBMount($existingMount); + if ($oldStorage->getBackend() instanceof InvalidBackend) { + throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); + } + $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index 3a294ce855c..47c14cbeaf4 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -78,6 +78,7 @@ class LoginController extends Controller { * @param IURLGenerator $urlGenerator * @param ILogger $logger * @param Manager $twoFactorManager + * @param Defaults $defaults */ public function __construct($appName, IRequest $request, diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 169beff2b9d..e02b8403a2a 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -26,6 +26,7 @@ use OC\Core\Controller\LoginController; use OC\User\Session; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\Defaults; use OCP\IConfig; use OCP\ILogger; use OCP\IRequest; @@ -54,6 +55,8 @@ class LoginControllerTest extends TestCase { private $logger; /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */ private $twoFactorManager; + /** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */ + private $defaults; public function setUp() { parent::setUp(); @@ -65,6 +68,7 @@ class LoginControllerTest extends TestCase { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->logger = $this->createMock(ILogger::class); $this->twoFactorManager = $this->createMock(Manager::class); + $this->defaults = $this->createMock(Defaults::class); $this->loginController = new LoginController( 'core', @@ -75,7 +79,8 @@ class LoginControllerTest extends TestCase { $this->userSession, $this->urlGenerator, $this->logger, - $this->twoFactorManager + $this->twoFactorManager, + $this->defaults ); } |