diff options
-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 | 57 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/InvalidStorage.php | 30 | ||||
-rw-r--r-- | apps/files_external/lib/Service/StoragesService.php | 10 |
5 files changed, 153 insertions, 2 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..1a426c4bbb7 --- /dev/null +++ b/apps/files_external/lib/Lib/Backend/InvalidBackend.php @@ -0,0 +1,57 @@ +<?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; + +/** + * 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('\OCA\Files_External\Lib\Storage\InvalidStorage') + ->setText('Unknown storage backend ' . $invalidId) + ; + } + + /** + * Returns the invalid backend id + * + * @return string invalid backend id + */ + public function getInvalidId() { + return $this->invalidId; + } +} + diff --git a/apps/files_external/lib/Lib/Storage/InvalidStorage.php b/apps/files_external/lib/Lib/Storage/InvalidStorage.php new file mode 100644 index 00000000000..bc4ecee8369 --- /dev/null +++ b/apps/files_external/lib/Lib/Storage/InvalidStorage.php @@ -0,0 +1,30 @@ +<?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\Storage; + +use OCP\Files\StorageNotAvailableException; + +class InvalidStorage { + public function __construct($params) { + throw new StorageNotAvailableException(); + } +} 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()); |