Merge pull request #6196 from nextcloud/downstream-26539-2

Handle invalid ext storage backend to keep mount point visible
This commit is contained in:
Morris Jobke 2017-09-04 14:17:28 +02:00 committed by GitHub
commit 30ca3b70ed
6 changed files with 138 additions and 3 deletions

View File

@ -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) {

View File

@ -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)
;
}
}

View File

@ -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));
}
}

View File

@ -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());

View File

@ -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,

View File

@ -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
);
}