mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
fix(files_external): ignore unsatisfied optional dependencies
Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
This commit is contained in:
parent
f2907f133c
commit
0f4d6b8027
4 changed files with 17 additions and 9 deletions
|
|
@ -140,7 +140,7 @@ abstract class StoragesController extends Controller {
|
|||
$backend = $storage->getBackend();
|
||||
/** @var AuthMechanism */
|
||||
$authMechanism = $storage->getAuthMechanism();
|
||||
if ($backend->checkDependencies()) {
|
||||
if ($backend->checkRequiredDependencies()) {
|
||||
// invalid backend
|
||||
return new DataResponse(
|
||||
[
|
||||
|
|
|
|||
|
|
@ -15,11 +15,23 @@ namespace OCA\Files_External\Lib;
|
|||
trait DependencyTrait {
|
||||
|
||||
/**
|
||||
* Check if object is valid for use
|
||||
* Check if object has unsatisfied required or optional dependencies
|
||||
*
|
||||
* @return MissingDependency[] Unsatisfied dependencies
|
||||
*/
|
||||
public function checkDependencies() {
|
||||
return []; // no dependencies by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object has unsatisfied required dependencies
|
||||
*
|
||||
* @return MissingDependency[] Unsatisfied required dependencies
|
||||
*/
|
||||
public function checkRequiredDependencies() {
|
||||
return array_filter(
|
||||
$this->checkDependencies(),
|
||||
fn (MissingDependency $dependency) => !$dependency->isOptional()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use OCA\Files_External\Lib\Auth\AuthMechanism;
|
|||
use OCA\Files_External\Lib\Backend\Backend;
|
||||
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
|
||||
use OCA\Files_External\Lib\Config\IBackendProvider;
|
||||
use OCA\Files_External\Lib\MissingDependency;
|
||||
use OCP\EventDispatcher\GenericEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAppConfig;
|
||||
|
|
@ -179,10 +178,7 @@ class BackendService {
|
|||
* @return Backend[]
|
||||
*/
|
||||
public function getAvailableBackends() {
|
||||
return array_filter($this->getBackends(), function ($backend) {
|
||||
$missing = array_filter($backend->checkDependencies(), fn (MissingDependency $dependency) => !$dependency->isOptional());
|
||||
return count($missing) === 0;
|
||||
});
|
||||
return array_filter($this->getBackends(), fn (Backend $backend) => !$backend->checkRequiredDependencies());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -175,11 +175,11 @@ class BackendServiceTest extends \Test\TestCase {
|
|||
|
||||
$backendAvailable = $this->getBackendMock('\Backend\Available');
|
||||
$backendAvailable->expects($this->once())
|
||||
->method('checkDependencies')
|
||||
->method('checkRequiredDependencies')
|
||||
->willReturn([]);
|
||||
$backendNotAvailable = $this->getBackendMock('\Backend\NotAvailable');
|
||||
$backendNotAvailable->expects($this->once())
|
||||
->method('checkDependencies')
|
||||
->method('checkRequiredDependencies')
|
||||
->willReturn([
|
||||
$this->getMockBuilder('\OCA\Files_External\Lib\MissingDependency')
|
||||
->disableOriginalConstructor()
|
||||
|
|
|
|||
Loading…
Reference in a new issue