fix(files_external): ignore unsatisfied optional dependencies

Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
This commit is contained in:
Jan-Philipp Litza 2025-07-22 16:57:44 +02:00 committed by Ferdinand Thiessen
parent f2907f133c
commit 0f4d6b8027
4 changed files with 17 additions and 9 deletions

View file

@ -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(
[

View file

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

View file

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

View file

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