Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions apps/files_external/lib/Lib/Auth/InvalidAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @author Vincent Petry <[email protected]>
*
* @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)
;
}

}
65 changes: 65 additions & 0 deletions apps/files_external/lib/Lib/Backend/InvalidBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @author Vincent Petry <[email protected]>
*
* @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));
}
}

10 changes: 8 additions & 2 deletions apps/files_external/lib/Service/StoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -295,11 +297,11 @@ public function createStorage(
) {
$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);
Expand Down Expand Up @@ -382,6 +384,10 @@ public function updateStorage(StorageConfig $updatedStorage) {

$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());
Expand Down
1 change: 1 addition & 0 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class LoginController extends Controller {
* @param IURLGenerator $urlGenerator
* @param ILogger $logger
* @param Manager $twoFactorManager
* @param Defaults $defaults
*/
public function __construct($appName,
IRequest $request,
Expand Down
7 changes: 6 additions & 1 deletion tests/Core/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -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();
Expand All @@ -65,6 +68,7 @@ public function setUp() {
$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',
Expand All @@ -75,7 +79,8 @@ public function setUp() {
$this->userSession,
$this->urlGenerator,
$this->logger,
$this->twoFactorManager
$this->twoFactorManager,
$this->defaults
);
}

Expand Down