diff options
Diffstat (limited to 'apps/files_external')
21 files changed, 120 insertions, 122 deletions
diff --git a/apps/files_external/composer/composer/autoload_classmap.php b/apps/files_external/composer/composer/autoload_classmap.php index 156847d5620..3e246225484 100644 --- a/apps/files_external/composer/composer/autoload_classmap.php +++ b/apps/files_external/composer/composer/autoload_classmap.php @@ -22,6 +22,7 @@ return array( 'OCA\\Files_External\\Command\\Scan' => $baseDir . '/../lib/Command/Scan.php', 'OCA\\Files_External\\Command\\StorageAuthBase' => $baseDir . '/../lib/Command/StorageAuthBase.php', 'OCA\\Files_External\\Command\\Verify' => $baseDir . '/../lib/Command/Verify.php', + 'OCA\\Files_External\\ConfigLexicon' => $baseDir . '/../lib/ConfigLexicon.php', 'OCA\\Files_External\\Config\\ConfigAdapter' => $baseDir . '/../lib/Config/ConfigAdapter.php', 'OCA\\Files_External\\Config\\ExternalMountPoint' => $baseDir . '/../lib/Config/ExternalMountPoint.php', 'OCA\\Files_External\\Config\\IConfigHandler' => $baseDir . '/../lib/Config/IConfigHandler.php', diff --git a/apps/files_external/composer/composer/autoload_static.php b/apps/files_external/composer/composer/autoload_static.php index 186f85bc5bc..86ad9eb3f78 100644 --- a/apps/files_external/composer/composer/autoload_static.php +++ b/apps/files_external/composer/composer/autoload_static.php @@ -37,6 +37,7 @@ class ComposerStaticInitFiles_External 'OCA\\Files_External\\Command\\Scan' => __DIR__ . '/..' . '/../lib/Command/Scan.php', 'OCA\\Files_External\\Command\\StorageAuthBase' => __DIR__ . '/..' . '/../lib/Command/StorageAuthBase.php', 'OCA\\Files_External\\Command\\Verify' => __DIR__ . '/..' . '/../lib/Command/Verify.php', + 'OCA\\Files_External\\ConfigLexicon' => __DIR__ . '/..' . '/../lib/ConfigLexicon.php', 'OCA\\Files_External\\Config\\ConfigAdapter' => __DIR__ . '/..' . '/../lib/Config/ConfigAdapter.php', 'OCA\\Files_External\\Config\\ExternalMountPoint' => __DIR__ . '/..' . '/../lib/Config/ExternalMountPoint.php', 'OCA\\Files_External\\Config\\IConfigHandler' => __DIR__ . '/..' . '/../lib/Config/IConfigHandler.php', diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php index 761fc97b7aa..5dae81d558c 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/apps/files_external/lib/AppInfo/Application.php @@ -9,6 +9,7 @@ namespace OCA\Files_External\AppInfo; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files_External\Config\ConfigAdapter; use OCA\Files_External\Config\UserPlaceholderHandler; +use OCA\Files_External\ConfigLexicon; use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; use OCA\Files_External\Lib\Auth\Builtin; use OCA\Files_External\Lib\Auth\NullMechanism; @@ -73,6 +74,7 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); + $context->registerConfigLexicon(ConfigLexicon::class); } public function boot(IBootContext $context): void { diff --git a/apps/files_external/lib/Command/Backends.php b/apps/files_external/lib/Command/Backends.php index c2d844dc781..399bdadcacf 100644 --- a/apps/files_external/lib/Command/Backends.php +++ b/apps/files_external/lib/Command/Backends.php @@ -94,7 +94,7 @@ class Backends extends Base { */ private function formatConfiguration(array $parameters): array { $configuration = array_filter($parameters, function (DefinitionParameter $parameter) { - return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN; + return $parameter->isFlagSet(DefinitionParameter::FLAG_HIDDEN); }); return array_map(function (DefinitionParameter $parameter) { return $parameter->getTypeName(); diff --git a/apps/files_external/lib/Command/Scan.php b/apps/files_external/lib/Command/Scan.php index bd54415df55..4f29dae1ce0 100644 --- a/apps/files_external/lib/Command/Scan.php +++ b/apps/files_external/lib/Command/Scan.php @@ -11,6 +11,7 @@ namespace OCA\Files_External\Command; use OC\Files\Cache\Scanner; use OCA\Files_External\Service\GlobalStoragesService; use OCP\IUserManager; +use OCP\Lock\LockedException; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -82,7 +83,19 @@ class Scan extends StorageAuthBase { $this->abortIfInterrupted(); }); - $scanner->scan($path); + try { + $scanner->scan($path); + } catch (LockedException $e) { + if (is_string($e->getReadablePath()) && str_starts_with($e->getReadablePath(), 'scanner::')) { + if ($e->getReadablePath() === 'scanner::') { + $output->writeln('<error>Another process is already scanning this storage</error>'); + } else { + $output->writeln('<error>Another process is already scanning \'' . substr($e->getReadablePath(), strlen('scanner::')) . '\' in this storage</error>'); + } + } else { + throw $e; + } + } $this->presentStats($output); diff --git a/apps/files_external/lib/ConfigLexicon.php b/apps/files_external/lib/ConfigLexicon.php new file mode 100644 index 00000000000..e162efc92cf --- /dev/null +++ b/apps/files_external/lib/ConfigLexicon.php @@ -0,0 +1,41 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Files_External; + +use NCU\Config\Lexicon\ConfigLexiconEntry; +use NCU\Config\Lexicon\ConfigLexiconStrictness; +use NCU\Config\Lexicon\IConfigLexicon; +use NCU\Config\ValueType; + +/** + * Config Lexicon for files_sharing. + * + * Please Add & Manage your Config Keys in that file and keep the Lexicon up to date! + * + * {@see IConfigLexicon} + */ +class ConfigLexicon implements IConfigLexicon { + public const ALLOW_USER_MOUNTING = 'allow_user_mounting'; + public const USER_MOUNTING_BACKENDS = 'user_mounting_backends'; + + public function getStrictness(): ConfigLexiconStrictness { + return ConfigLexiconStrictness::NOTICE; + } + + public function getAppConfigs(): array { + return [ + new ConfigLexiconEntry(self::ALLOW_USER_MOUNTING, ValueType::BOOL, false, 'allow users to mount their own external filesystems', true), + new ConfigLexiconEntry(self::USER_MOUNTING_BACKENDS, ValueType::STRING, '', 'list of mounting backends available for users', true), + ]; + } + + public function getUserConfigs(): array { + return []; + } +} diff --git a/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php b/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php index b215201b4f4..688e04c4210 100644 --- a/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php +++ b/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php @@ -21,14 +21,17 @@ class OAuth1 extends AuthMechanism { ->setText($l->t('OAuth1')) ->addParameters([ (new DefinitionParameter('configured', 'configured')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_TEXT) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), new DefinitionParameter('app_key', $l->t('App key')), (new DefinitionParameter('app_secret', $l->t('App secret'))) ->setType(DefinitionParameter::VALUE_PASSWORD), (new DefinitionParameter('token', 'token')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), (new DefinitionParameter('token_secret', 'token_secret')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), ]) ->addCustomJs('oauth1') ; diff --git a/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php b/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php index 6b41fef90d5..b6c1e1d9557 100644 --- a/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php +++ b/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php @@ -21,12 +21,14 @@ class OAuth2 extends AuthMechanism { ->setText($l->t('OAuth2')) ->addParameters([ (new DefinitionParameter('configured', 'configured')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_TEXT) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), new DefinitionParameter('client_id', $l->t('Client ID')), (new DefinitionParameter('client_secret', $l->t('Client secret'))) ->setType(DefinitionParameter::VALUE_PASSWORD), (new DefinitionParameter('token', 'token')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), ]) ->addCustomJs('oauth2') ; diff --git a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php index e3453a477d4..57df6316361 100644 --- a/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php +++ b/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php @@ -43,7 +43,9 @@ class LoginCredentials extends AuthMechanism { ->setText($l->t('Log-in credentials, save in database')) ->addParameters([ (new DefinitionParameter('password', $l->t('Password'))) - ->setType(DefinitionParameter::VALUE_PASSWORD), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]); $eventDispatcher->addServiceListener(UserLoggedInEvent::class, StorePasswordListener::class); diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php index 6b7a51a8828..8af82ab228c 100644 --- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php +++ b/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php @@ -32,7 +32,9 @@ class SessionCredentials extends AuthMechanism { ->setText($l->t('Log-in credentials, save in session')) ->addParameters([ (new DefinitionParameter('password', $l->t('Password'))) - ->setType(DefinitionParameter::VALUE_PASSWORD), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]); } diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index 2371ce0a219..87072299d6d 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -31,7 +31,8 @@ class RSA extends AuthMechanism { new DefinitionParameter('user', $l->t('Login')), new DefinitionParameter('public_key', $l->t('Public key')), (new DefinitionParameter('private_key', 'private_key')) - ->setType(DefinitionParameter::VALUE_HIDDEN), + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), ]) ->addCustomJs('public_key') ; diff --git a/apps/files_external/lib/Lib/Backend/LegacyBackend.php b/apps/files_external/lib/Lib/Backend/LegacyBackend.php index 11396913fbd..a74412e8373 100644 --- a/apps/files_external/lib/Lib/Backend/LegacyBackend.php +++ b/apps/files_external/lib/Lib/Backend/LegacyBackend.php @@ -52,10 +52,6 @@ class LegacyBackend extends Backend { $type = DefinitionParameter::VALUE_PASSWORD; $placeholder = substr($placeholder, 1); break; - case '#': - $type = DefinitionParameter::VALUE_HIDDEN; - $placeholder = substr($placeholder, 1); - break; } $this->addParameter((new DefinitionParameter($name, $placeholder)) ->setType($type) diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php index c4a68fea6e1..b246b0638f0 100644 --- a/apps/files_external/lib/Lib/Backend/SMB.php +++ b/apps/files_external/lib/Lib/Backend/SMB.php @@ -49,8 +49,9 @@ class SMB extends Backend { ->setFlag(DefinitionParameter::FLAG_OPTIONAL) ->setTooltip($l->t("Check the ACL's of each file or folder inside a directory to filter out items where the account has no read permissions, comes with a performance penalty")), (new DefinitionParameter('timeout', $l->t('Timeout'))) - ->setType(DefinitionParameter::VALUE_HIDDEN) - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ->setType(DefinitionParameter::VALUE_TEXT) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL) + ->setFlag(DefinitionParameter::FLAG_HIDDEN), ]) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) ->addAuthScheme(AuthMechanism::SCHEME_SMB) diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/apps/files_external/lib/Lib/DefinitionParameter.php index 1e611edd1ed..3c668c6b83d 100644 --- a/apps/files_external/lib/Lib/DefinitionParameter.php +++ b/apps/files_external/lib/Lib/DefinitionParameter.php @@ -18,12 +18,12 @@ class DefinitionParameter implements \JsonSerializable { public const VALUE_TEXT = 0; public const VALUE_BOOLEAN = 1; public const VALUE_PASSWORD = 2; - public const VALUE_HIDDEN = 3; /** Flag constants */ public const FLAG_NONE = 0; public const FLAG_OPTIONAL = 1; public const FLAG_USER_PROVIDED = 2; + public const FLAG_HIDDEN = 4; /** @var string human-readable parameter tooltip */ private string $tooltip = ''; diff --git a/apps/files_external/lib/Listener/LoadAdditionalListener.php b/apps/files_external/lib/Listener/LoadAdditionalListener.php index 66d06675291..6ba917759c3 100644 --- a/apps/files_external/lib/Listener/LoadAdditionalListener.php +++ b/apps/files_external/lib/Listener/LoadAdditionalListener.php @@ -10,10 +10,11 @@ namespace OCA\Files_External\Listener; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files_External\AppInfo\Application; +use OCA\Files_External\ConfigLexicon; use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\Util; /** @@ -22,7 +23,7 @@ use OCP\Util; class LoadAdditionalListener implements IEventListener { public function __construct( - private IConfig $config, + private readonly IAppConfig $appConfig, private IInitialState $initialState, ) { } @@ -32,7 +33,7 @@ class LoadAdditionalListener implements IEventListener { return; } - $allowUserMounting = $this->config->getAppValue('files_external', 'allow_user_mounting', 'no') === 'yes'; + $allowUserMounting = $this->appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING); $this->initialState->provideInitialState('allowUserMounting', $allowUserMounting); Util::addInitScript(Application::APP_ID, 'init'); diff --git a/apps/files_external/lib/Service/BackendService.php b/apps/files_external/lib/Service/BackendService.php index b452b27e175..4726dbd4cad 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/apps/files_external/lib/Service/BackendService.php @@ -7,14 +7,14 @@ namespace OCA\Files_External\Service; use OCA\Files_External\Config\IConfigHandler; +use OCA\Files_External\ConfigLexicon; 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 OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\Server; /** @@ -56,19 +56,12 @@ class BackendService { private $configHandlers = []; - /** - * @param IConfig $config - */ public function __construct( - protected IConfig $config, + protected IAppConfig $appConfig, ) { // Load config values - if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { - $this->userMountingAllowed = false; - } - $this->userMountingBackends = explode(',', - $this->config->getAppValue('files_external', 'user_mounting_backends', '') - ); + $this->userMountingAllowed = $appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING); + $this->userMountingBackends = explode(',', $appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS)); // if no backend is in the list an empty string is in the array and user mounting is disabled if ($this->userMountingBackends === ['']) { diff --git a/apps/files_external/src/settings.js b/apps/files_external/src/settings.js index aa9b57786d9..033696c9d24 100644 --- a/apps/files_external/src/settings.js +++ b/apps/files_external/src/settings.js @@ -647,13 +647,13 @@ const MountConfigListView = function($el, options) { MountConfigListView.ParameterFlags = { OPTIONAL: 1, USER_PROVIDED: 2, + HIDDEN: 4, } MountConfigListView.ParameterTypes = { TEXT: 0, BOOLEAN: 1, PASSWORD: 2, - HIDDEN: 3, } /** @@ -1142,13 +1142,13 @@ MountConfigListView.prototype = _.extend({ let newElement const trimmedPlaceholder = placeholder.value - if (placeholder.type === MountConfigListView.ParameterTypes.PASSWORD) { + if (hasFlag(MountConfigListView.ParameterFlags.HIDDEN)) { + newElement = $('<input type="hidden" class="' + classes.join(' ') + '" data-parameter="' + parameter + '" />') + } else if (placeholder.type === MountConfigListView.ParameterTypes.PASSWORD) { newElement = $('<input type="password" class="' + classes.join(' ') + '" data-parameter="' + parameter + '" placeholder="' + trimmedPlaceholder + '" />') } else if (placeholder.type === MountConfigListView.ParameterTypes.BOOLEAN) { const checkboxId = _.uniqueId('checkbox_') newElement = $('<div><label><input type="checkbox" id="' + checkboxId + '" class="' + classes.join(' ') + '" data-parameter="' + parameter + '" />' + trimmedPlaceholder + '</label></div>') - } else if (placeholder.type === MountConfigListView.ParameterTypes.HIDDEN) { - newElement = $('<input type="hidden" class="' + classes.join(' ') + '" data-parameter="' + parameter + '" />') } else { newElement = $('<input type="text" class="' + classes.join(' ') + '" data-parameter="' + parameter + '" placeholder="' + trimmedPlaceholder + '" />') } diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index d1a8f78076a..5aad7b018af 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -7,7 +7,6 @@ */ use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Backend\Backend; -use OCA\Files_External\Lib\DefinitionParameter; use OCA\Files_External\Service\BackendService; /** @var array $_ */ @@ -42,63 +41,6 @@ foreach ($_['authMechanisms'] as $authMechanism) { } } -function writeParameterInput($parameter, $options, $classes = []) { - $value = ''; - if (isset($options[$parameter->getName()])) { - $value = $options[$parameter->getName()]; - } - $placeholder = $parameter->getText(); - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); - - switch ($parameter->getType()) { - case DefinitionParameter::VALUE_PASSWORD: ?> - <?php if ($is_optional) { - $classes[] = 'optional'; - } ?> - <input type="password" - <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> - data-parameter="<?php p($parameter->getName()); ?>" - value="<?php p($value); ?>" - placeholder="<?php p($placeholder); ?>" - /> - <?php - break; - case DefinitionParameter::VALUE_BOOLEAN: ?> - <?php $checkboxId = uniqid('checkbox_'); ?> - <div> - <label> - <input type="checkbox" - id="<?php p($checkboxId); ?>" - <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> - data-parameter="<?php p($parameter->getName()); ?>" - <?php if ($value === true): ?> checked="checked"<?php endif; ?> - /> - <?php p($placeholder); ?> - </label> - </div> - <?php - break; - case DefinitionParameter::VALUE_HIDDEN: ?> - <input type="hidden" - <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> - data-parameter="<?php p($parameter->getName()); ?>" - value="<?php p($value); ?>" - /> - <?php - break; - default: ?> - <?php if ($is_optional) { - $classes[] = 'optional'; - } ?> - <input type="text" - <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> - data-parameter="<?php p($parameter->getName()); ?>" - value="<?php p($value); ?>" - placeholder="<?php p($placeholder); ?>" - /> - <?php - } -} ?> <div class="emptyfilelist emptycontent hidden"> diff --git a/apps/files_external/tests/Backend/LegacyBackendTest.php b/apps/files_external/tests/Backend/LegacyBackendTest.php index 303700c6611..cea46c1a0cd 100644 --- a/apps/files_external/tests/Backend/LegacyBackendTest.php +++ b/apps/files_external/tests/Backend/LegacyBackendTest.php @@ -32,7 +32,6 @@ class LegacyBackendTest extends \Test\TestCase { 'textfield' => 'Text field', 'passwordfield' => '*Password field', 'checkbox' => '!Checkbox', - 'hiddenfield' => '#Hidden field', 'optionaltext' => '&Optional text field', 'optionalpassword' => '&*Optional password field', ], @@ -66,9 +65,6 @@ class LegacyBackendTest extends \Test\TestCase { $this->assertEquals('Checkbox', $parameters['checkbox']->getText()); $this->assertEquals(DefinitionParameter::VALUE_BOOLEAN, $parameters['checkbox']->getType()); $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['checkbox']->getFlags()); - $this->assertEquals('Hidden field', $parameters['hiddenfield']->getText()); - $this->assertEquals(DefinitionParameter::VALUE_HIDDEN, $parameters['hiddenfield']->getType()); - $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['hiddenfield']->getFlags()); $this->assertEquals('Optional text field', $parameters['optionaltext']->getText()); $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['optionaltext']->getType()); $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionaltext']->getFlags()); diff --git a/apps/files_external/tests/DefinitionParameterTest.php b/apps/files_external/tests/DefinitionParameterTest.php index 0b1d11bbf0c..3fc65eaf897 100644 --- a/apps/files_external/tests/DefinitionParameterTest.php +++ b/apps/files_external/tests/DefinitionParameterTest.php @@ -38,12 +38,12 @@ class DefinitionParameterTest extends \Test\TestCase { 'tooltip' => '', ], $param->jsonSerialize()); - $param->setType(Param::VALUE_HIDDEN); - $param->setFlags(Param::FLAG_NONE); + $param->setType(Param::VALUE_TEXT); + $param->setFlags(Param::FLAG_HIDDEN); $this->assertEquals([ 'value' => 'bar', - 'flags' => Param::FLAG_NONE, - 'type' => Param::VALUE_HIDDEN, + 'flags' => Param::FLAG_HIDDEN, + 'type' => Param::VALUE_TEXT, 'tooltip' => '', ], $param->jsonSerialize()); } @@ -53,6 +53,7 @@ class DefinitionParameterTest extends \Test\TestCase { [Param::VALUE_TEXT, Param::FLAG_NONE, 'abc', true], [Param::VALUE_TEXT, Param::FLAG_NONE, '', false], [Param::VALUE_TEXT, Param::FLAG_OPTIONAL, '', true], + [Param::VALUE_TEXT, Param::FLAG_HIDDEN, '', false], [Param::VALUE_BOOLEAN, Param::FLAG_NONE, false, true], [Param::VALUE_BOOLEAN, Param::FLAG_NONE, 123, false], @@ -62,8 +63,6 @@ class DefinitionParameterTest extends \Test\TestCase { [Param::VALUE_PASSWORD, Param::FLAG_NONE, 'foobar', true], [Param::VALUE_PASSWORD, Param::FLAG_NONE, '', false], - - [Param::VALUE_HIDDEN, Param::FLAG_NONE, '', false] ]; } diff --git a/apps/files_external/tests/Service/BackendServiceTest.php b/apps/files_external/tests/Service/BackendServiceTest.php index e7644d8e523..c3a77d81b67 100644 --- a/apps/files_external/tests/Service/BackendServiceTest.php +++ b/apps/files_external/tests/Service/BackendServiceTest.php @@ -12,15 +12,15 @@ 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\Service\BackendService; -use OCP\IConfig; +use OCP\IAppConfig; class BackendServiceTest extends \Test\TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ - protected $config; + /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ + protected $appConfig; protected function setUp(): void { - $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); } /** @@ -52,7 +52,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testRegisterBackend(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backend = $this->getBackendMock('\Foo\Bar'); @@ -80,7 +80,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testBackendProvider(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backend1 = $this->getBackendMock('\Foo\Bar'); $backend2 = $this->getBackendMock('\Bar\Foo'); @@ -99,7 +99,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testAuthMechanismProvider(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backend1 = $this->getAuthMechanismMock('\Foo\Bar'); $backend2 = $this->getAuthMechanismMock('\Bar\Foo'); @@ -118,7 +118,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testMultipleBackendProviders(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backend1a = $this->getBackendMock('\Foo\Bar'); $backend1b = $this->getBackendMock('\Bar\Foo'); @@ -146,14 +146,16 @@ class BackendServiceTest extends \Test\TestCase { } public function testUserMountingBackends(): void { - $this->config->expects($this->exactly(2)) - ->method('getAppValue') - ->willReturnMap([ - ['files_external', 'allow_user_mounting', 'yes', 'yes'], - ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias'] - ]); + $this->appConfig->expects($this->once()) + ->method('getValueString') + ->with('files_external', 'user_mounting_backends') + ->willReturn('identifier:\User\Mount\Allowed,identifier_alias'); + $this->appConfig->expects($this->once()) + ->method('getValueBool') + ->with('files_external', 'allow_user_mounting') + ->willReturn(true); - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backendAllowed = $this->getBackendMock('\User\Mount\Allowed'); $backendAllowed->expects($this->never()) @@ -177,7 +179,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testGetAvailableBackends(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $backendAvailable = $this->getBackendMock('\Backend\Available'); $backendAvailable->expects($this->once()) @@ -220,7 +222,7 @@ class BackendServiceTest extends \Test\TestCase { public function testRegisterConfigHandlerInvalid(array $placeholders): void { $this->expectException(\RuntimeException::class); - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $mock = $this->createMock(IConfigHandler::class); $cb = function () use ($mock) { return $mock; @@ -231,7 +233,7 @@ class BackendServiceTest extends \Test\TestCase { } public function testConfigHandlers(): void { - $service = new BackendService($this->config); + $service = new BackendService($this->appConfig); $mock = $this->createMock(IConfigHandler::class); $mock->expects($this->exactly(3)) ->method('handle'); |