Jan-Philipp Litza
19 hours ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
17 additions and
9 deletions
-
apps/files_external/lib/Controller/StoragesController.php
-
apps/files_external/lib/Lib/DependencyTrait.php
-
apps/files_external/lib/Service/BackendService.php
-
apps/files_external/tests/Service/BackendServiceTest.php
|
|
@ -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( |
|
|
|
[ |
|
|
|
|
|
@ -13,11 +13,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() |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -13,7 +13,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; |
|
|
@ -188,10 +187,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() |
|
|
|