Browse Source

Handle invalid ext storage backend to keep mount point visible

Keep mount point visible and also ext storage config visible when
dealing with configs relating to storage backends or auth mechanisms
that were provided by an app that is currently disabled.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
tags/v13.0.0beta1
Vincent Petry 7 years ago
parent
commit
5df5b9c8b1
No account linked to committer's email address

+ 14
- 0
apps/files_external/js/settings.js 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) {

+ 44
- 0
apps/files_external/lib/Lib/Auth/InvalidAuth.php 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)
;
}

}

+ 57
- 0
apps/files_external/lib/Lib/Backend/InvalidBackend.php View File

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


+ 30
- 0
apps/files_external/lib/Lib/Storage/InvalidStorage.php View File

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

+ 8
- 2
apps/files_external/lib/Service/StoragesService.php 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());

Loading…
Cancel
Save