diff --git a/apps/encryption/lib/Migration.php b/apps/encryption/lib/Migration.php index 30567dd042d3..0c283c575a31 100644 --- a/apps/encryption/lib/Migration.php +++ b/apps/encryption/lib/Migration.php @@ -320,7 +320,7 @@ private function renameFileKeys($user, $path, $trash = false) { * @return array */ protected function getSystemMountPoints() { - return \OC_Mount_Config::getSystemMountPoints(); + return \OC\Files\External\LegacyUtil::getSystemMountPoints(); } /** diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index e0c9dbf413ee..f27b320541f8 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -46,5 +46,3 @@ "name" => $l->t('External storage') ]); -$mountProvider = $appContainer->query('OCA\Files_External\Config\ConfigAdapter'); -\OC::$server->getMountProviderCollection()->registerProvider($mountProvider); diff --git a/apps/files_external/appinfo/database.xml b/apps/files_external/appinfo/database.xml deleted file mode 100644 index 54ee642ead65..000000000000 --- a/apps/files_external/appinfo/database.xml +++ /dev/null @@ -1,225 +0,0 @@ - - *dbname* - true - false - utf8 - - *dbprefix*external_mounts - - - mount_id - integer - 0 - true - 1 - 6 - - - mount_point - text - 128 - true - - - storage_backend - text - 64 - true - - - auth_backend - text - 64 - true - - - priority - integer - 100 - 4 - true - - - - type - integer - 4 - true - - -
- - *dbprefix*external_applicable - - - applicable_id - integer - 0 - true - 1 - 6 - - - - mount_id - integer - true - 6 - - - - type - integer - 4 - true - - - - value - text - 64 - - - - applicable_mount - - mount_id - ascending - - - - applicable_type_value - - type - ascending - - - value - ascending - - - - applicable_type_value_mount - true - - type - ascending - - - value - ascending - - - mount_id - ascending - - - -
- - - *dbprefix*external_config - - - config_id - integer - 0 - true - 1 - 6 - - - - mount_id - integer - true - 6 - - - key - text - true - 64 - - - value - text - true - 4096 - - - - config_mount - - mount_id - ascending - - - - config_mount_key - true - - mount_id - ascending - - - key - ascending - - - -
- - - *dbprefix*external_options - - - option_id - integer - 0 - true - 1 - 6 - - - - mount_id - integer - true - 6 - - - key - text - true - 64 - - - value - text - true - 256 - - - - option_mount - - mount_id - ascending - - - - option_mount_key - true - - mount_id - ascending - - - key - ascending - - - -
-
diff --git a/apps/files_external/appinfo/info.xml b/apps/files_external/appinfo/info.xml index 842918f1925d..2571aef76b33 100644 --- a/apps/files_external/appinfo/info.xml +++ b/apps/files_external/appinfo/info.xml @@ -13,7 +13,7 @@ admin-external-storage false - 0.6.0 + 0.7.0 diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php index ccdfcb2ffa80..991667735641 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/apps/files_external/lib/AppInfo/Application.php @@ -30,9 +30,9 @@ use \OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use \OCP\IContainer; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Config\IBackendProvider; -use \OCA\Files_External\Lib\Config\IAuthMechanismProvider; +use \OCP\Files\External\IStoragesBackendService; +use \OCP\Files\External\Config\IBackendProvider; +use \OCP\Files\External\Config\IAuthMechanismProvider; /** * @package OCA\Files_External\AppInfo @@ -47,28 +47,28 @@ public function __construct(array $urlParams = []) { $container->registerService('OCP\Files\Config\IUserMountCache', function (IAppContainer $c) { return $c->getServer()->query('UserMountCache'); }); + $container->registerService('OCP\Files\External\IStoragesBackendService', function (IAppContainer $c) { + return $c->getServer()->query('StoragesBackendService'); + }); + $container->registerService('OCP\Files\External\Service\IGlobalStoragesService', function (IAppContainer $c) { + return $c->getServer()->query('OCP\Files\External\Service\IGlobalStoragesService'); + }); + $container->registerService('OCP\Files\External\Service\IUserGlobalStoragesService', function (IAppContainer $c) { + return $c->getServer()->query('OCP\Files\External\Service\IUserGlobalStoragesService'); + }); + $container->registerService('OCP\Files\External\Service\IUserStoragesService', function (IAppContainer $c) { + return $c->getServer()->query('OCP\Files\External\Service\IUserStoragesService'); + }); - $backendService = $container->query('OCA\\Files_External\\Service\\BackendService'); + $backendService = $container->getServer()->query('StoragesBackendService'); $backendService->registerBackendProvider($this); $backendService->registerAuthMechanismProvider($this); - - // force-load auth mechanisms since some will register hooks - // TODO: obsolete these and use the TokenProvider to get the user's password from the session - $this->getAuthMechanisms(); - - // app developers: do NOT depend on this! it will disappear with oC 9.0! - \OC::$server->getEventDispatcher()->dispatch( - 'OCA\\Files_External::loadAdditionalBackends' - ); } /** * Register settings templates */ public function registerSettings() { - $container = $this->getContainer(); - $backendService = $container->query('OCA\\Files_External\\Service\\BackendService'); - \OCP\App::registerAdmin('files_external', 'settings'); \OCP\App::registerPersonal('files_external', 'personal'); } @@ -103,16 +103,6 @@ public function getAuthMechanisms() { $container = $this->getContainer(); return [ - // AuthMechanism::SCHEME_NULL mechanism - $container->query('OCA\Files_External\Lib\Auth\NullMechanism'), - - // AuthMechanism::SCHEME_BUILTIN mechanism - $container->query('OCA\Files_External\Lib\Auth\Builtin'), - - // AuthMechanism::SCHEME_PASSWORD mechanisms - $container->query('OCA\Files_External\Lib\Auth\Password\Password'), - $container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'), - // AuthMechanism::SCHEME_OAUTH1 mechanisms $container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'), diff --git a/apps/files_external/lib/Command/Applicable.php b/apps/files_external/lib/Command/Applicable.php index 05784ff587c3..ec63fe0cf377 100644 --- a/apps/files_external/lib/Command/Applicable.php +++ b/apps/files_external/lib/Command/Applicable.php @@ -23,9 +23,9 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Service\GlobalStoragesService; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\Service\IGlobalStoragesService; use OCP\IGroupManager; use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; @@ -35,7 +35,7 @@ class Applicable extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $globalService; @@ -50,7 +50,7 @@ class Applicable extends Base { private $groupManager; function __construct( - GlobalStoragesService $globalService, + IGlobalStoragesService $globalService, IUserManager $userManager, IGroupManager $groupManager ) { @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 404; } - if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { + if ($mount->getType() === IStorageConfig::MOUNT_TYPE_PERSONAl) { $output->writeln('Can\'t change applicables on personal mounts'); return 1; } diff --git a/apps/files_external/lib/Command/Backends.php b/apps/files_external/lib/Command/Backends.php index c9f77bd3be8b..d288ab960dd8 100644 --- a/apps/files_external/lib/Command/Backends.php +++ b/apps/files_external/lib/Command/Backends.php @@ -22,10 +22,10 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -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; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStoragesBackendService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableHelper; @@ -37,10 +37,10 @@ use Symfony\Component\Console\Output\OutputInterface; class Backends extends Base { - /** @var BackendService */ + /** @var IStoragesBackendService */ private $backendService; - function __construct(BackendService $backendService + function __construct(IStoragesBackendService $backendService ) { parent::__construct(); diff --git a/apps/files_external/lib/Command/Config.php b/apps/files_external/lib/Command/Config.php index 50a799115773..21b331d94f93 100644 --- a/apps/files_external/lib/Command/Config.php +++ b/apps/files_external/lib/Command/Config.php @@ -23,9 +23,9 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Service\GlobalStoragesService; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\Service\IGlobalStoragesService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableHelper; @@ -36,11 +36,11 @@ class Config extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $globalService; - function __construct(GlobalStoragesService $globalService) { + function __construct(IGlobalStoragesService $globalService) { parent::__construct(); $this->globalService = $globalService; } @@ -84,11 +84,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { } /** - * @param StorageConfig $mount + * @param IStorageConfig $mount * @param string $key * @param OutputInterface $output */ - protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { + protected function getOption(IStorageConfig $mount, $key, OutputInterface $output) { if ($key === 'mountpoint' || $key === 'mount_point') { $value = $mount->getMountPoint(); } else { @@ -101,12 +101,12 @@ protected function getOption(StorageConfig $mount, $key, OutputInterface $output } /** - * @param StorageConfig $mount + * @param IStorageConfig $mount * @param string $key * @param string $value * @param OutputInterface $output */ - protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { + protected function setOption(IStorageConfig $mount, $key, $value, OutputInterface $output) { $decoded = json_decode($value, true); if (!is_null($decoded)) { $value = $decoded; diff --git a/apps/files_external/lib/Command/Create.php b/apps/files_external/lib/Command/Create.php index c9d40eac073f..4ef9a92d0c80 100644 --- a/apps/files_external/lib/Command/Create.php +++ b/apps/files_external/lib/Command/Create.php @@ -25,13 +25,13 @@ use OC\Core\Command\Base; use OC\Files\Filesystem; use OC\User\NoUserException; -use OCA\Files_External\Lib\Auth\AuthMechanism; -use OCA\Files_External\Lib\Backend\Backend; -use OCA\Files_External\Lib\DefinitionParameter; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\BackendService; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\UserStoragesService; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\Service\IGlobalStoragesService; +use OCP\Files\External\Service\IUserStoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Input\ArrayInput; @@ -42,12 +42,12 @@ class Create extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ private $globalService; /** - * @var UserStoragesService + * @var IUserStoragesService */ private $userService; @@ -56,17 +56,17 @@ class Create extends Base { */ private $userManager; - /** @var BackendService */ + /** @var IStoragesBackendService */ private $backendService; /** @var IUserSession */ private $userSession; - function __construct(GlobalStoragesService $globalService, - UserStoragesService $userService, + function __construct(IGlobalStoragesService $globalService, + IUserStoragesService $userService, IUserManager $userManager, IUserSession $userSession, - BackendService $backendService + IStoragesBackendService $backendService ) { parent::__construct(); $this->globalService = $globalService; @@ -158,7 +158,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $config[$key] = $value; } - $mount = new StorageConfig(); + $mount = $this->getStorageService($user)->createConfig(); $mount->setMountPoint($mountPoint); $mount->setBackend($storageBackend); $mount->setAuthMechanism($authBackend); @@ -199,7 +199,7 @@ private function validateParam($key, &$value, Backend $storageBackend, AuthMecha return false; } - private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { + private function showMount($user, IStorageConfig $mount, InputInterface $input, OutputInterface $output) { $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); $listInput = new ArrayInput([], $listCommand->getDefinition()); $listInput->setOption('output', $input->getOption('output')); diff --git a/apps/files_external/lib/Command/Delete.php b/apps/files_external/lib/Command/Delete.php index 43792c6ce0fa..cf0f2fd4a999 100644 --- a/apps/files_external/lib/Command/Delete.php +++ b/apps/files_external/lib/Command/Delete.php @@ -23,9 +23,9 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\UserStoragesService; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\Service\IGlobalStoragesService; +use OCP\Files\External\Service\IUserStoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Input\ArrayInput; @@ -37,12 +37,12 @@ class Delete extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $globalService; /** - * @var UserStoragesService + * @var IUserStoragesService */ protected $userService; @@ -56,7 +56,7 @@ class Delete extends Base { */ protected $userManager; - function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { + function __construct(IGlobalStoragesService $globalService, IUserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { parent::__construct(); $this->globalService = $globalService; $this->userService = $userService; diff --git a/apps/files_external/lib/Command/Import.php b/apps/files_external/lib/Command/Import.php index 4c1498342ba1..cf245a88e062 100644 --- a/apps/files_external/lib/Command/Import.php +++ b/apps/files_external/lib/Command/Import.php @@ -24,11 +24,10 @@ use OC\Core\Command\Base; use OC\User\NoUserException; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\BackendService; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\ImportLegacyStoragesService; -use OCA\Files_External\Service\UserStoragesService; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\Service\IGlobalStoragesService; +use OCP\Files\External\Service\IUserStoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Input\ArrayInput; @@ -36,15 +35,16 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use OCP\Files\External\Service\IStoragesService; class Import extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ private $globalService; /** - * @var UserStoragesService + * @var IUserStoragesService */ private $userService; @@ -58,25 +58,20 @@ class Import extends Base { */ private $userManager; - /** @var ImportLegacyStoragesService */ - private $importLegacyStorageService; - - /** @var BackendService */ + /** @var IStoragesBackendService */ private $backendService; - function __construct(GlobalStoragesService $globalService, - UserStoragesService $userService, + function __construct(IGlobalStoragesService $globalService, + IUserStoragesService $userService, IUserSession $userSession, IUserManager $userManager, - ImportLegacyStoragesService $importLegacyStorageService, - BackendService $backendService + IStoragesBackendService $backendService ) { parent::__construct(); $this->globalService = $globalService; $this->userService = $userService; $this->userSession = $userSession; $this->userManager = $userManager; - $this->importLegacyStorageService = $importLegacyStorageService; $this->backendService = $backendService; } @@ -126,21 +121,19 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 1; } + $storageService = $this->getStorageService($user); + $isLegacy = isset($data['user']) || isset($data['group']); if ($isLegacy) { - $this->importLegacyStorageService->setData($data); - $mounts = $this->importLegacyStorageService->getAllStorages(); - foreach ($mounts as $mount) { - if ($mount->getBackendOption('password') === false) { - $output->writeln('Failed to decrypt password'); - return 1; - } - } + $output->writeln('Importing legacy mount.json format not supported any more'); + return 1; } else { if (!isset($data[0])) { //normalize to an array of mounts $data = [$data]; } - $mounts = array_map([$this, 'parseData'], $data); + $mounts = array_map(function($entry) use ($storageService) { + return $this->parseData($entry, $storageService); + }, $data); } if ($user) { @@ -151,8 +144,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { } } - $storageService = $this->getStorageService($user); - $existingMounts = $storageService->getAllStorages(); foreach ($mounts as $mount) { @@ -187,8 +178,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 0; } - private function parseData(array $data) { - $mount = new StorageConfig($data['mount_id']); + private function parseData(array $data, IStoragesService $storageService) { + // FIXME: use service to create config + $mount = $storageService->createConfig(); + $mount->setId($data['mount_id']); $mount->setMountPoint($data['mount_point']); $mount->setBackend($this->getBackendByClass($data['storage'])); $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']); diff --git a/apps/files_external/lib/Command/ListCommand.php b/apps/files_external/lib/Command/ListCommand.php index 71a31219e9c8..683c1088db02 100644 --- a/apps/files_external/lib/Command/ListCommand.php +++ b/apps/files_external/lib/Command/ListCommand.php @@ -24,9 +24,9 @@ use OC\Core\Command\Base; use OC\User\NoUserException; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\UserStoragesService; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Service\IGlobalStoragesService; +use OCP\Files\External\Service\IUserStoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Helper\Table; @@ -37,12 +37,12 @@ class ListCommand extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $globalService; /** - * @var UserStoragesService + * @var IUserStoragesService */ protected $userService; @@ -58,7 +58,7 @@ class ListCommand extends Base { const ALL = -1; - function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { + function __construct(IGlobalStoragesService $globalService, IUserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { parent::__construct(); $this->globalService = $globalService; $this->userService = $userService; @@ -95,14 +95,14 @@ protected function configure() { protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('all')) { - /** @var $mounts StorageConfig[] */ + /** @var $mounts IStorageConfig[] */ $mounts = $this->globalService->getStorageForAllUsers(); $userId = self::ALL; } else { $userId = $input->getArgument('user_id'); $storageService = $this->getStorageService($userId); - /** @var $mounts StorageConfig[] */ + /** @var $mounts IStorageConfig[] */ $mounts = $storageService->getAllStorages(); } @@ -111,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { /** * @param $userId $userId - * @param StorageConfig[] $mounts + * @param IStorageConfig[] $mounts * @param InputInterface $input * @param OutputInterface $output */ @@ -159,7 +159,7 @@ public function listMounts($userId, array $mounts, InputInterface $input, Output return strtolower(str_replace(' ', '_', $header)); }, $headers); - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { + $pairs = array_map(function (IStorageConfig $config) use ($keys, $userId) { $values = [ $config->getId(), $config->getMountPoint(), @@ -173,7 +173,7 @@ public function listMounts($userId, array $mounts, InputInterface $input, Output $values[] = $config->getApplicableGroups(); } if ($userId === self::ALL) { - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; + $values[] = $config->getType() === IStorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; } return array_combine($keys, $values); @@ -192,7 +192,7 @@ public function listMounts($userId, array $mounts, InputInterface $input, Output 'enable_sharing' => false, 'encoding_compatibility' => false ]; - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { + $rows = array_map(function (IStorageConfig $config) use ($userId, $defaultMountOptions, $full) { $storageConfig = $config->getBackendOptions(); $keys = array_keys($storageConfig); $values = array_values($storageConfig); @@ -246,7 +246,7 @@ public function listMounts($userId, array $mounts, InputInterface $input, Output $values[] = $applicableGroups; } if ($userId === self::ALL) { - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; + $values[] = $config->getType() === IStorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; } return $values; diff --git a/apps/files_external/lib/Command/Option.php b/apps/files_external/lib/Command/Option.php index a7652f625fe2..378bd4e88c69 100644 --- a/apps/files_external/lib/Command/Option.php +++ b/apps/files_external/lib/Command/Option.php @@ -22,7 +22,7 @@ namespace OCA\Files_External\Command; -use OCA\Files_External\Lib\StorageConfig; +use OCP\Files\External\IStorageConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; @@ -47,11 +47,11 @@ protected function configure() { } /** - * @param StorageConfig $mount + * @param IStorageConfig $mount * @param string $key * @param OutputInterface $output */ - protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { + protected function getOption(IStorageConfig $mount, $key, OutputInterface $output) { $value = $mount->getMountOption($key); if (!is_string($value)) { // show bools and objects correctly $value = json_encode($value); @@ -60,12 +60,12 @@ protected function getOption(StorageConfig $mount, $key, OutputInterface $output } /** - * @param StorageConfig $mount + * @param IStorageConfig $mount * @param string $key * @param string $value * @param OutputInterface $output */ - protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { + protected function setOption(IStorageConfig $mount, $key, $value, OutputInterface $output) { $decoded = json_decode($value, true); if (!is_null($decoded)) { $value = $decoded; diff --git a/apps/files_external/lib/Command/Verify.php b/apps/files_external/lib/Command/Verify.php index 5e1c7b2ce073..25e47edafc73 100644 --- a/apps/files_external/lib/Command/Verify.php +++ b/apps/files_external/lib/Command/Verify.php @@ -23,12 +23,12 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -use OCA\Files_External\Lib\Auth\AuthMechanism; -use OCA\Files_External\Lib\Backend\Backend; -use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Service\GlobalStoragesService; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\InsufficientDataForMeaningfulAnswerException; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\Service\IGlobalStoragesService; use OCP\Files\StorageNotAvailableException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -37,11 +37,11 @@ class Verify extends Base { /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $globalService; - function __construct(GlobalStoragesService $globalService) { + function __construct(IGlobalStoragesService $globalService) { parent::__construct(); $this->globalService = $globalService; } @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { ]); } - private function manipulateStorageConfig(StorageConfig $storage) { + private function manipulateStorageConfig(IStorageConfig $storage) { /** @var AuthMechanism */ $authMechanism = $storage->getAuthMechanism(); $authMechanism->manipulateStorageConfig($storage); @@ -92,7 +92,7 @@ private function manipulateStorageConfig(StorageConfig $storage) { $backend->manipulateStorageConfig($storage); } - private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) { + private function updateStorageStatus(IStorageConfig &$storage, $configInput, OutputInterface $output) { try { try { $this->manipulateStorageConfig($storage); diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index 1cb045096c6e..36042d7ca882 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -27,12 +27,12 @@ use OCP\ILogger; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Http; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\NotFoundException; +use OCP\IRequest; +use OCP\IL10N; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http; +use OCP\Files\External\Service\IGlobalStoragesService; +use OCP\Files\External\NotFoundException; /** * Global storages controller @@ -44,14 +44,14 @@ class GlobalStoragesController extends StoragesController { * @param string $AppName application name * @param IRequest $request request object * @param IL10N $l10n l10n service - * @param GlobalStoragesService $globalStoragesService storage service + * @param IGlobalStoragesService $globalStoragesService storage service * @param ILogger $logger */ public function __construct( $AppName, IRequest $request, IL10N $l10n, - GlobalStoragesService $globalStoragesService, + IGlobalStoragesService $globalStoragesService, ILogger $logger ) { parent::__construct( diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 6e75390cc61a..b8b2ad9f6624 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -28,18 +28,18 @@ use OCP\ILogger; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; -use OCA\Files_External\Service\StoragesService; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCP\Files\StorageNotAvailableException; -use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; +use OCP\IRequest; +use OCP\IL10N; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\Files\External\Service\IStoragesService; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\StorageNotAvailableException; +use OCP\Files\External\InsufficientDataForMeaningfulAnswerException; /** * Base class for storages controllers @@ -56,7 +56,7 @@ abstract class StoragesController extends Controller { /** * Storages service * - * @var StoragesService + * @var IStoragesService */ protected $service; @@ -71,14 +71,14 @@ abstract class StoragesController extends Controller { * @param string $AppName application name * @param IRequest $request request object * @param IL10N $l10n l10n service - * @param StoragesService $storagesService storage service + * @param IStoragesService $storagesService storage service * @param ILogger $logger */ public function __construct( $AppName, IRequest $request, IL10N $l10n, - StoragesService $storagesService, + IStoragesService $storagesService, ILogger $logger ) { parent::__construct($AppName, $request); @@ -99,7 +99,7 @@ public function __construct( * @param array|null $applicableGroups groups for which to mount the storage * @param int|null $priority priority * - * @return StorageConfig|DataResponse + * @return IStorageConfig|DataResponse */ protected function createStorage( $mountPoint, @@ -136,11 +136,11 @@ protected function createStorage( /** * Validate storage config * - * @param StorageConfig $storage storage config + * @param IStorageConfig $storage storage config *1 * @return DataResponse|null returns response in case of validation error */ - protected function validate(StorageConfig $storage) { + protected function validate(IStorageConfig $storage) { $mountPoint = $storage->getMountPoint(); if ($mountPoint === '' || $mountPoint === '/') { return new DataResponse( @@ -222,7 +222,7 @@ protected function validate(StorageConfig $storage) { return null; } - protected function manipulateStorageConfig(StorageConfig $storage) { + protected function manipulateStorageConfig(IStorageConfig $storage) { /** @var AuthMechanism */ $authMechanism = $storage->getAuthMechanism(); $authMechanism->manipulateStorageConfig($storage); @@ -237,10 +237,10 @@ protected function manipulateStorageConfig(StorageConfig $storage) { * Note that this operation can be time consuming depending * on whether the remote storage is available or not. * - * @param StorageConfig $storage storage configuration + * @param IStorageConfig $storage storage configuration * @param bool $testOnly whether to storage should only test the connection or do more things */ - protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) { + protected function updateStorageStatus(IStorageConfig &$storage, $testOnly = true) { try { $this->manipulateStorageConfig($storage); diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 0b8b6a47b2a2..3c9744b554ed 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -24,18 +24,18 @@ namespace OCA\Files_External\Controller; -use OCA\Files_External\Lib\Auth\AuthMechanism; -use OCA\Files_External\Lib\Auth\IUserProvided; -use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Auth\IUserProvided; +use OCP\Files\External\InsufficientDataForMeaningfulAnswerException; use OCP\ILogger; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Http; -use OCA\Files_External\Service\UserGlobalStoragesService; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; +use OCP\IRequest; +use OCP\IL10N; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http; +use OCP\Files\External\Service\IUserGlobalStoragesService; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Backend\Backend; use OCP\IUserSession; /** @@ -53,14 +53,14 @@ class UserGlobalStoragesController extends StoragesController { * @param string $AppName application name * @param IRequest $request request object * @param IL10N $l10n l10n service - * @param UserGlobalStoragesService $userGlobalStoragesService storage service + * @param IUserGlobalStoragesService $userGlobalStoragesService storage service * @param IUserSession $userSession */ public function __construct( $AppName, IRequest $request, IL10N $l10n, - UserGlobalStoragesService $userGlobalStoragesService, + IUserGlobalStoragesService $userGlobalStoragesService, IUserSession $userSession, ILogger $logger ) { @@ -95,7 +95,7 @@ public function index() { ); } - protected function manipulateStorageConfig(StorageConfig $storage) { + protected function manipulateStorageConfig(IStorageConfig $storage) { /** @var AuthMechanism */ $authMechanism = $storage->getAuthMechanism(); $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); @@ -186,11 +186,11 @@ public function update( } /** - * Remove sensitive data from a StorageConfig before returning it to the user + * Remove sensitive data from a IStorageConfig before returning it to the user * - * @param StorageConfig $storage + * @param IStorageConfig $storage */ - protected function sanitizeStorage(StorageConfig $storage) { + protected function sanitizeStorage(IStorageConfig $storage) { $storage->setBackendOptions([]); $storage->setMountOptions([]); diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index f80c6fbfd9e3..aa47650f5c24 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -26,17 +26,17 @@ namespace OCA\Files_External\Controller; -use OCA\Files_External\Lib\Auth\AuthMechanism; use OCP\ILogger; -use \OCP\IUserSession; -use \OCP\IRequest; -use \OCP\IL10N; -use \OCP\AppFramework\Http\DataResponse; -use \OCP\AppFramework\Http; -use OCA\Files_External\Service\UserStoragesService; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; +use OCP\IUserSession; +use OCP\IRequest; +use OCP\IL10N; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Service\IUserStoragesService; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Lib\Backend\Backend; /** * User storages controller @@ -53,7 +53,7 @@ class UserStoragesController extends StoragesController { * @param string $AppName application name * @param IRequest $request request object * @param IL10N $l10n l10n service - * @param UserStoragesService $userStoragesService storage service + * @param IUserStoragesService $userStoragesService storage service * @param IUserSession $userSession * @param ILogger $logger */ @@ -61,7 +61,7 @@ public function __construct( $AppName, IRequest $request, IL10N $l10n, - UserStoragesService $userStoragesService, + IUserStoragesService $userStoragesService, IUserSession $userSession, ILogger $logger ) { @@ -75,7 +75,7 @@ public function __construct( $this->userSession = $userSession; } - protected function manipulateStorageConfig(StorageConfig $storage) { + protected function manipulateStorageConfig(IStorageConfig $storage) { /** @var AuthMechanism */ $authMechanism = $storage->getAuthMechanism(); $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser()); diff --git a/apps/files_external/lib/Lib/Api.php b/apps/files_external/lib/Lib/Api.php index fada53fdf49e..865fee7859d7 100644 --- a/apps/files_external/lib/Lib/Api.php +++ b/apps/files_external/lib/Lib/Api.php @@ -74,6 +74,7 @@ private static function formatMount($mountPoint, $mountConfig) { * @return \OC_OCS_Result share information */ public static function getUserMounts($params) { + // FIXME: use the service API for this $entries = []; $user = \OC::$server->getUserSession()->getUser()->getUID(); diff --git a/apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php b/apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php index 9119ff119a13..51bf6c1d99c8 100644 --- a/apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php +++ b/apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php @@ -21,9 +21,9 @@ namespace OCA\Files_External\Lib\Auth\AmazonS3; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * Amazon S3 access key authentication diff --git a/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php b/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php index 6c3640569520..a2a1e608d836 100644 --- a/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php +++ b/apps/files_external/lib/Lib/Auth/OAuth1/OAuth1.php @@ -21,9 +21,9 @@ namespace OCA\Files_External\Lib\Auth\OAuth1; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * OAuth1 authentication diff --git a/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php b/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php index e9c5c01332b2..abcee5680e00 100644 --- a/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php +++ b/apps/files_external/lib/Lib/Auth/OAuth2/OAuth2.php @@ -21,9 +21,9 @@ namespace OCA\Files_External\Lib\Auth\OAuth2; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * OAuth2 authentication diff --git a/apps/files_external/lib/Lib/Auth/OpenStack/OpenStack.php b/apps/files_external/lib/Lib/Auth/OpenStack/OpenStack.php index de85ad379c48..cbae1608a37d 100644 --- a/apps/files_external/lib/Lib/Auth/OpenStack/OpenStack.php +++ b/apps/files_external/lib/Lib/Auth/OpenStack/OpenStack.php @@ -21,9 +21,9 @@ namespace OCA\Files_External\Lib\Auth\OpenStack; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * OpenStack Keystone authentication diff --git a/apps/files_external/lib/Lib/Auth/OpenStack/Rackspace.php b/apps/files_external/lib/Lib/Auth/OpenStack/Rackspace.php index 09fec2712981..f36999899311 100644 --- a/apps/files_external/lib/Lib/Auth/OpenStack/Rackspace.php +++ b/apps/files_external/lib/Lib/Auth/OpenStack/Rackspace.php @@ -21,9 +21,9 @@ namespace OCA\Files_External\Lib\Auth\OpenStack; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * Rackspace authentication diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index 0c5f13ea056a..f640ceae023d 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -21,11 +21,11 @@ namespace OCA\Files_External\Lib\Auth\PublicKey; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Lib\StorageConfig; -use \OCP\IConfig; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStorageConfig; +use OCP\IConfig; use OCP\IUser; use \phpseclib\Crypt\RSA as RSACrypt; @@ -56,7 +56,7 @@ public function __construct(IL10N $l, IConfig $config) { ; } - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { diff --git a/apps/files_external/lib/Lib/Backend/AmazonS3.php b/apps/files_external/lib/Lib/Backend/AmazonS3.php index 132669016e59..6b5a32dff1bd 100644 --- a/apps/files_external/lib/Lib/Backend/AmazonS3.php +++ b/apps/files_external/lib/Lib/Backend/AmazonS3.php @@ -21,20 +21,19 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\DefinitionParameter; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; -use \OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; +use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; class AmazonS3 extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, AccessKey $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('amazons3') ->addIdentifierAlias('\OC\Files\Storage\AmazonS3') // legacy compat @@ -53,8 +52,7 @@ public function __construct(IL10N $l, AccessKey $legacyAuth) { (new DefinitionParameter('use_path_style', $l->t('Enable Path Style'))) ->setType(DefinitionParameter::VALUE_BOOLEAN), ]) - ->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY) - ->setLegacyAuthMechanism($legacyAuth) + ->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY); ; } diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php index 452e9c21cb22..148a6c6fd644 100644 --- a/apps/files_external/lib/Lib/Backend/Backend.php +++ b/apps/files_external/lib/Lib/Backend/Backend.php @@ -21,145 +21,10 @@ namespace OCA\Files_External\Lib\Backend; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\VisibilityTrait; -use \OCA\Files_External\Lib\FrontendDefinitionTrait; -use \OCA\Files_External\Lib\PriorityTrait; -use \OCA\Files_External\Lib\DependencyTrait; -use \OCA\Files_External\Lib\StorageModifierTrait; -use \OCA\Files_External\Lib\IdentifierTrait; -use \OCA\Files_External\Lib\Auth\AuthMechanism; - /** - * Storage backend - * - * A backend can have services injected during construction, - * such as \OCP\IDB for database operations. This allows a backend - * to perform advanced operations based on provided information. - * - * An authenication scheme defines the parameter interface, common to the - * storage implementation, the backend and the authentication mechanism. - * A storage implementation expects parameters according to the authentication - * scheme, which are provided from the authentication mechanism. - * - * This class uses the following traits: - * - VisibilityTrait - * Restrict usage to admin-only/none - * - FrontendDefinitionTrait - * Specify configuration parameters and other definitions - * - PriorityTrait - * Allow objects to prioritize over others with the same mountpoint - * - DependencyTrait - * The object requires certain dependencies to be met - * - StorageModifierTrait - * Object can affect storage mounting + * @deprecated use \OCP\Files\External\Backend instead */ -class Backend implements \JsonSerializable { - - use VisibilityTrait; - use FrontendDefinitionTrait; - use PriorityTrait; - use DependencyTrait; - use StorageModifierTrait; - use IdentifierTrait; - - /** @var string storage class */ - private $storageClass; - - /** @var array 'scheme' => true, supported authentication schemes */ - private $authSchemes = []; - - /** @var AuthMechanism|callable authentication mechanism fallback */ - private $legacyAuthMechanism; - - /** - * @return string - */ - public function getStorageClass() { - return $this->storageClass; - } - - /** - * @param string $class - * @return self - */ - public function setStorageClass($class) { - $this->storageClass = $class; - return $this; - } - - /** - * @return array - */ - public function getAuthSchemes() { - if (empty($this->authSchemes)) { - return [AuthMechanism::SCHEME_NULL => true]; - } - return $this->authSchemes; - } - - /** - * @param string $scheme - * @return self - */ - public function addAuthScheme($scheme) { - $this->authSchemes[$scheme] = true; - return $this; - } - - /** - * @param array $parameters storage parameters, for dynamic mechanism selection - * @return AuthMechanism - */ - public function getLegacyAuthMechanism(array $parameters = []) { - if (is_callable($this->legacyAuthMechanism)) { - return call_user_func($this->legacyAuthMechanism, $parameters); - } - return $this->legacyAuthMechanism; - } - - /** - * @param AuthMechanism $authMechanism - * @return self - */ - public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { - $this->legacyAuthMechanism = $authMechanism; - return $this; - } - - /** - * @param callable $callback dynamic auth mechanism selection - * @return self - */ - public function setLegacyAuthMechanismCallback(callable $callback) { - $this->legacyAuthMechanism = $callback; - } - - /** - * Serialize into JSON for client-side JS - * - * @return array - */ - public function jsonSerialize() { - $data = $this->jsonSerializeDefinition(); - $data += $this->jsonSerializeIdentifier(); - - $data['backend'] = $data['name']; // legacy compat - $data['priority'] = $this->getPriority(); - $data['authSchemes'] = $this->getAuthSchemes(); - - return $data; - } - - /** - * Check if parameters are satisfied in a StorageConfig - * - * @param StorageConfig $storage - * @return bool - */ - public function validateStorage(StorageConfig $storage) { - return $this->validateStorageDefinition($storage); - } +class Backend extends \OCP\Files\External\Backend\Backend { } diff --git a/apps/files_external/lib/Lib/Backend/DAV.php b/apps/files_external/lib/Lib/Backend/DAV.php index 516130066252..c95843fd8ed6 100644 --- a/apps/files_external/lib/Lib/Backend/DAV.php +++ b/apps/files_external/lib/Lib/Backend/DAV.php @@ -21,20 +21,17 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\Password\Password; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; class DAV extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, Password $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('dav') ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat @@ -47,8 +44,7 @@ public function __construct(IL10N $l, Password $legacyAuth) { (new DefinitionParameter('secure', $l->t('Secure https://'))) ->setType(DefinitionParameter::VALUE_BOOLEAN), ]) - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD); ; } diff --git a/apps/files_external/lib/Lib/Backend/Dropbox.php b/apps/files_external/lib/Lib/Backend/Dropbox.php index 04ceb6f07241..818125c35abf 100644 --- a/apps/files_external/lib/Lib/Backend/Dropbox.php +++ b/apps/files_external/lib/Lib/Backend/Dropbox.php @@ -21,20 +21,17 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\OAuth1\OAuth1; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; class Dropbox extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, OAuth1 $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('dropbox') ->addIdentifierAlias('\OC\Files\Storage\Dropbox') // legacy compat @@ -45,7 +42,6 @@ public function __construct(IL10N $l, OAuth1 $legacyAuth) { ]) ->addAuthScheme(AuthMechanism::SCHEME_OAUTH1) ->addCustomJs('dropbox') - ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/Lib/Backend/Google.php b/apps/files_external/lib/Lib/Backend/Google.php index 458e25c303bb..f05c73f03625 100644 --- a/apps/files_external/lib/Lib/Backend/Google.php +++ b/apps/files_external/lib/Lib/Backend/Google.php @@ -21,20 +21,17 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -use \OCA\Files_External\Lib\Auth\OAuth2\OAuth2; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; class Google extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, OAuth2 $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('googledrive') ->addIdentifierAlias('\OC\Files\Storage\Google') // legacy compat @@ -45,7 +42,6 @@ public function __construct(IL10N $l, OAuth2 $legacyAuth) { ]) ->addAuthScheme(AuthMechanism::SCHEME_OAUTH2) ->addCustomJs('gdrive') - ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/Lib/Backend/LegacyBackend.php b/apps/files_external/lib/Lib/Backend/LegacyBackend.php deleted file mode 100644 index 92239b774985..000000000000 --- a/apps/files_external/lib/Lib/Backend/LegacyBackend.php +++ /dev/null @@ -1,104 +0,0 @@ - - * - * @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 - * - */ - -namespace OCA\Files_External\Lib\Backend; - -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\Builtin; -use \OCA\Files_External\Lib\MissingDependency; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; - -/** - * Legacy compatibility for OC_Mount_Config::registerBackend() - */ -class LegacyBackend extends Backend { - - use LegacyDependencyCheckPolyfill { - LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies; - } - - /** @var bool */ - protected $hasDependencies = false; - - /** - * @param string $class - * @param array $definition - * @param Builtin $authMechanism - */ - public function __construct($class, array $definition, Builtin $authMechanism) { - $this - ->setIdentifier($class) - ->setStorageClass($class) - ->setText($definition['backend']) - ->addAuthScheme(Builtin::SCHEME_BUILTIN) - ->setLegacyAuthMechanism($authMechanism) - ; - - foreach ($definition['configuration'] as $name => $placeholder) { - $flags = DefinitionParameter::FLAG_NONE; - $type = DefinitionParameter::VALUE_TEXT; - if ($placeholder[0] === '&') { - $flags = DefinitionParameter::FLAG_OPTIONAL; - $placeholder = substr($placeholder, 1); - } - switch ($placeholder[0]) { - case '!': - $type = DefinitionParameter::VALUE_BOOLEAN; - $placeholder = substr($placeholder, 1); - break; - case '*': - $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) - ->setFlags($flags) - ); - } - - if (isset($definition['priority'])) { - $this->setPriority($definition['priority']); - } - if (isset($definition['custom'])) { - $this->addCustomJs($definition['custom']); - } - if (isset($definition['has_dependencies']) && $definition['has_dependencies']) { - $this->hasDependencies = true; - } - } - - /** - * @return MissingDependency[] - */ - public function checkDependencies() { - if ($this->hasDependencies) { - return $this->doCheckDependencies(); - } - return []; - } - -} diff --git a/apps/files_external/lib/Lib/Backend/Local.php b/apps/files_external/lib/Lib/Backend/Local.php index f4d5ecab94f2..a5c742c725a9 100644 --- a/apps/files_external/lib/Lib/Backend/Local.php +++ b/apps/files_external/lib/Lib/Backend/Local.php @@ -21,16 +21,15 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\NullMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStoragesBackendService; class Local extends Backend { - public function __construct(IL10N $l, NullMechanism $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('local') ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat @@ -39,10 +38,9 @@ public function __construct(IL10N $l, NullMechanism $legacyAuth) { ->addParameters([ (new DefinitionParameter('datadir', $l->t('Location'))), ]) - ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) - ->setPriority(BackendService::PRIORITY_DEFAULT + 50) + ->setAllowedVisibility(IStoragesBackendService::VISIBILITY_ADMIN) + ->setPriority(IStoragesBackendService::PRIORITY_DEFAULT + 50) ->addAuthScheme(AuthMechanism::SCHEME_NULL) - ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/Lib/Backend/OwnCloud.php b/apps/files_external/lib/Lib/Backend/OwnCloud.php index fbcb581aead8..181227e443fd 100644 --- a/apps/files_external/lib/Lib/Backend/OwnCloud.php +++ b/apps/files_external/lib/Lib/Backend/OwnCloud.php @@ -21,17 +21,14 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; - -use \OCA\Files_External\Lib\Auth\Password\Password; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; class OwnCloud extends Backend { - public function __construct(IL10N $l, Password $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('owncloud') ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat @@ -45,7 +42,6 @@ public function __construct(IL10N $l, Password $legacyAuth) { ->setType(DefinitionParameter::VALUE_BOOLEAN), ]) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/Lib/Backend/SFTP.php b/apps/files_external/lib/Lib/Backend/SFTP.php index 9da13dc6110f..27b19cd3b18a 100644 --- a/apps/files_external/lib/Lib/Backend/SFTP.php +++ b/apps/files_external/lib/Lib/Backend/SFTP.php @@ -21,17 +21,14 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; - -use \OCA\Files_External\Lib\Auth\Password\Password; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; class SFTP extends Backend { - public function __construct(IL10N $l, Password $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('sftp') ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat @@ -44,7 +41,6 @@ public function __construct(IL10N $l, Password $legacyAuth) { ]) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) - ->setLegacyAuthMechanism($legacyAuth) ; } diff --git a/apps/files_external/lib/Lib/Backend/SFTP_Key.php b/apps/files_external/lib/Lib/Backend/SFTP_Key.php index 41c83c02275b..9752a54c58f6 100644 --- a/apps/files_external/lib/Lib/Backend/SFTP_Key.php +++ b/apps/files_external/lib/Lib/Backend/SFTP_Key.php @@ -21,17 +21,15 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\PublicKey\RSA; -use \OCA\Files_External\Lib\Backend\SFTP; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCA\Files_External\Lib\Backend\SFTP; class SFTP_Key extends Backend { - public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { + public function __construct(IL10N $l, SFTP $sftpBackend) { $this ->setIdentifier('\OC\Files\Storage\SFTP_Key') ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') @@ -42,7 +40,6 @@ public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]) ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) - ->setLegacyAuthMechanism($legacyAuth) ->deprecateTo($sftpBackend) ; } diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php index c6f5390fd168..058bb6152c90 100644 --- a/apps/files_external/lib/Lib/Backend/SMB.php +++ b/apps/files_external/lib/Lib/Backend/SMB.php @@ -21,22 +21,20 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\IStorageConfig; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; -use \OCA\Files_External\Lib\Auth\Password\Password; use OCP\IUser; class SMB extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, Password $legacyAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('smb') ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat @@ -51,7 +49,6 @@ public function __construct(IL10N $l, Password $legacyAuth) { ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) ; } @@ -59,7 +56,7 @@ public function __construct(IL10N $l, Password $legacyAuth) { * @param StorageConfig $storage * @param IUser $user */ - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { $user = $storage->getBackendOption('user'); if ($domain = $storage->getBackendOption('domain')) { $storage->setBackendOption('user', $domain.'\\'.$user); diff --git a/apps/files_external/lib/Lib/Backend/SMB_OC.php b/apps/files_external/lib/Lib/Backend/SMB_OC.php index d2b31c099e1b..11bff829c2de 100644 --- a/apps/files_external/lib/Lib/Backend/SMB_OC.php +++ b/apps/files_external/lib/Lib/Backend/SMB_OC.php @@ -21,15 +21,14 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\Password\SessionCredentials; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; -use \OCA\Files_External\Lib\Backend\SMB; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\IStorageConfig; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; +use OCA\Files_External\Lib\Backend\SMB; use OCP\IUser; /** @@ -39,7 +38,7 @@ class SMB_OC extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) { + public function __construct(IL10N $l, SMB $smbBackend) { $this ->setIdentifier('\OC\Files\Storage\SMB_OC') ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') @@ -53,14 +52,13 @@ public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBa (new DefinitionParameter('root', $l->t('Remote subfolder'))) ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]) - ->setPriority(BackendService::PRIORITY_DEFAULT - 10) + ->setPriority(IStoragesBackendService::PRIORITY_DEFAULT - 10) ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) - ->setLegacyAuthMechanism($legacyAuth) ->deprecateTo($smbBackend) ; } - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { $username_as_share = ($storage->getBackendOption('username_as_share') === true); if ($username_as_share) { diff --git a/apps/files_external/lib/Lib/Backend/Swift.php b/apps/files_external/lib/Lib/Backend/Swift.php index 175a60453dfb..aacf96d15ced 100644 --- a/apps/files_external/lib/Lib/Backend/Swift.php +++ b/apps/files_external/lib/Lib/Backend/Swift.php @@ -21,20 +21,17 @@ namespace OCA\Files_External\Lib\Backend; -use \OCP\IL10N; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Lib\Auth\OpenStack\OpenStack; -use \OCA\Files_External\Lib\Auth\OpenStack\Rackspace; -use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; +use OCP\IL10N; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; +use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill; class Swift extends Backend { use LegacyDependencyCheckPolyfill; - public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) { + public function __construct(IL10N $l) { $this ->setIdentifier('swift') ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat @@ -50,12 +47,6 @@ public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $racks ->setFlag(DefinitionParameter::FLAG_OPTIONAL), ]) ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK) - ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) { - if (isset($params['options']['key']) && $params['options']['key']) { - return $rackspaceAuth; - } - return $openstackAuth; - }) ; } diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php index a61735bc1f01..acf96d65928b 100644 --- a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php +++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php @@ -21,7 +21,7 @@ namespace OCA\Files_External\Lib; -use \OCA\Files_External\Lib\MissingDependency; +use \OC\Files\External\MissingDependency; /** * Polyfill for checking dependencies using legacy Storage::checkDependencies() diff --git a/apps/files_external/lib/Migration/StorageMigrator.php b/apps/files_external/lib/Migration/StorageMigrator.php deleted file mode 100644 index 1a5ae28a34b1..000000000000 --- a/apps/files_external/lib/Migration/StorageMigrator.php +++ /dev/null @@ -1,147 +0,0 @@ - - * @author Robin Appelman - * @author Vincent Petry - * - * @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 - * - */ - -namespace OCA\Files_External\Migration; - -use OCA\Files_External\Service\BackendService; -use OCA\Files_External\Service\DBConfigService; -use OCA\Files_External\Service\GlobalLegacyStoragesService; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\LegacyStoragesService; -use OCA\Files_External\Service\StoragesService; -use OCA\Files_External\Service\UserLegacyStoragesService; -use OCA\Files_External\Service\UserStoragesService; -use OCP\Files\Config\IUserMountCache; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\ILogger; -use OCP\IUser; - -/** - * Migrate mount config from mount.json to the database - */ -class StorageMigrator { - /** - * @var BackendService - */ - private $backendService; - - /** - * @var DBConfigService - */ - private $dbConfig; - - /** - * @var IConfig - */ - private $config; - - /** - * @var IDBConnection - */ - private $connection; - - /** - * @var ILogger - */ - private $logger; - - /** @var IUserMountCache */ - private $userMountCache; - - /** - * StorageMigrator constructor. - * - * @param BackendService $backendService - * @param DBConfigService $dbConfig - * @param IConfig $config - * @param IDBConnection $connection - * @param ILogger $logger - * @param IUserMountCache $userMountCache - */ - public function __construct( - BackendService $backendService, - DBConfigService $dbConfig, - IConfig $config, - IDBConnection $connection, - ILogger $logger, - IUserMountCache $userMountCache - ) { - $this->backendService = $backendService; - $this->dbConfig = $dbConfig; - $this->config = $config; - $this->connection = $connection; - $this->logger = $logger; - $this->userMountCache = $userMountCache; - } - - private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { - $existingStorage = $legacyService->getAllStorages(); - - $this->connection->beginTransaction(); - try { - foreach ($existingStorage as $storage) { - $mountOptions = $storage->getMountOptions(); - if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { - // existing mounts must have sharing enabled by default to avoid surprises - $mountOptions['enable_sharing'] = true; - $storage->setMountOptions($mountOptions); - } - $storageService->addStorage($storage); - } - $this->connection->commit(); - } catch (\Exception $e) { - $this->logger->logException($e); - $this->connection->rollBack(); - } - } - - /** - * Migrate admin configured storages - */ - public function migrateGlobal() { - $legacyService = new GlobalLegacyStoragesService($this->backendService); - $storageService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->userMountCache); - - $this->migrate($legacyService, $storageService); - } - - /** - * Migrate personal storages configured by the current user - * - * @param IUser $user - */ - public function migrateUser(IUser $user) { - $dummySession = new DummyUserSession(); - $dummySession->setUser($user); - $userId = $user->getUID(); - $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); - if (version_compare($userVersion, '0.5.0', '<')) { - $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); - $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); - $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); - - $this->migrate($legacyService, $storageService); - } - } -} diff --git a/apps/files_external/lib/Service/LegacyStoragesService.php b/apps/files_external/lib/Service/LegacyStoragesService.php deleted file mode 100644 index 487bdf1bf725..000000000000 --- a/apps/files_external/lib/Service/LegacyStoragesService.php +++ /dev/null @@ -1,211 +0,0 @@ - - * @author Robin Appelman - * @author Stefan Weil - * - * @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 - * - */ - -namespace OCA\Files_External\Service; - -use OCA\Files_External\Lib\StorageConfig; - -/** - * Read mount config from legacy mount.json - */ -abstract class LegacyStoragesService { - /** @var BackendService */ - protected $backendService; - - /** - * Read legacy config data - * - * @return array list of mount configs - */ - abstract protected function readLegacyConfig(); - - /** - * Copy legacy storage options into the given storage config object. - * - * @param StorageConfig $storageConfig storage config to populate - * @param string $mountType mount type - * @param string $applicable applicable user or group - * @param array $storageOptions legacy storage options - * - * @return StorageConfig populated storage config - */ - protected function populateStorageConfigWithLegacyOptions( - &$storageConfig, - $mountType, - $applicable, - $storageOptions - ) { - $backend = $this->backendService->getBackend($storageOptions['backend']); - if (!$backend) { - throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']); - } - $storageConfig->setBackend($backend); - if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { - $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); - } else { - $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); - $storageOptions['authMechanism'] = 'null'; // to make error handling easier - } - if (!$authMechanism) { - throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']); - } - $storageConfig->setAuthMechanism($authMechanism); - $storageConfig->setBackendOptions($storageOptions['options']); - if (isset($storageOptions['mountOptions'])) { - $storageConfig->setMountOptions($storageOptions['mountOptions']); - } - if (!isset($storageOptions['priority'])) { - $storageOptions['priority'] = $backend->getPriority(); - } - $storageConfig->setPriority($storageOptions['priority']); - if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) { - $applicableUsers = $storageConfig->getApplicableUsers(); - if ($applicable !== 'all') { - $applicableUsers[] = $applicable; - $storageConfig->setApplicableUsers($applicableUsers); - } - } else if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) { - $applicableGroups = $storageConfig->getApplicableGroups(); - $applicableGroups[] = $applicable; - $storageConfig->setApplicableGroups($applicableGroups); - } - return $storageConfig; - } - - /** - * Read the external storages config - * - * @return StorageConfig[] map of storage id to storage config - */ - public function getAllStorages() { - $mountPoints = $this->readLegacyConfig(); - /** - * Here is the how the horribly messy mount point array looks like - * from the mount.json file: - * - * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath] - * - * - $mountType is either "user" or "group" - * - $applicable is the name of a user or group (or the current user for personal mounts) - * - $mountPath is the mount point path (where the storage must be mounted) - * - $storageOptions is a map of storage options: - * - "priority": storage priority - * - "backend": backend identifier - * - "class": LEGACY backend class name - * - "options": backend-specific options - * - "authMechanism": authentication mechanism identifier - * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) - */ - // group by storage id - /** @var StorageConfig[] $storages */ - $storages = []; - // for storages without id (legacy), group by config hash for - // later processing - $storagesWithConfigHash = []; - foreach ($mountPoints as $mountType => $applicables) { - foreach ($applicables as $applicable => $mountPaths) { - foreach ($mountPaths as $rootMountPath => $storageOptions) { - $currentStorage = null; - /** - * Flag whether the config that was read already has an id. - * If not, it will use a config hash instead and generate - * a proper id later - * - * @var boolean - */ - $hasId = false; - // the root mount point is in the format "/$user/files/the/mount/point" - // we remove the "/$user/files" prefix - $parts = explode('/', ltrim($rootMountPath, '/'), 3); - if (count($parts) < 3) { - // something went wrong, skip - \OCP\Util::writeLog( - 'files_external', - 'Could not parse mount point "' . $rootMountPath . '"', - \OCP\Util::ERROR - ); - continue; - } - $relativeMountPath = rtrim($parts[2], '/'); - // note: we cannot do this after the loop because the decrypted config - // options might be needed for the config hash - $storageOptions['options'] = \OC_Mount_Config::decryptPasswords($storageOptions['options']); - if (!isset($storageOptions['backend'])) { - $storageOptions['backend'] = $storageOptions['class']; // legacy compat - } - if (!isset($storageOptions['authMechanism'])) { - $storageOptions['authMechanism'] = null; // ensure config hash works - } - if (isset($storageOptions['id'])) { - $configId = (int)$storageOptions['id']; - if (isset($storages[$configId])) { - $currentStorage = $storages[$configId]; - } - $hasId = true; - } else { - // missing id in legacy config, need to generate - // but at this point we don't know the max-id, so use - // first group it by config hash - $storageOptions['mountpoint'] = $rootMountPath; - $configId = \OC_Mount_Config::makeConfigHash($storageOptions); - if (isset($storagesWithConfigHash[$configId])) { - $currentStorage = $storagesWithConfigHash[$configId]; - } - } - if (is_null($currentStorage)) { - // create new - $currentStorage = new StorageConfig($configId); - $currentStorage->setMountPoint($relativeMountPath); - } - try { - $this->populateStorageConfigWithLegacyOptions( - $currentStorage, - $mountType, - $applicable, - $storageOptions - ); - if ($hasId) { - $storages[$configId] = $currentStorage; - } else { - $storagesWithConfigHash[$configId] = $currentStorage; - } - } catch (\UnexpectedValueException $e) { - // don't die if a storage backend doesn't exist - \OCP\Util::writeLog( - 'files_external', - 'Could not load storage: "' . $e->getMessage() . '"', - \OCP\Util::ERROR - ); - } - } - } - } - - // convert parameter values - foreach ($storages as $storage) { - $storage->getBackend()->validateStorageDefinition($storage); - $storage->getAuthMechanism()->validateStorageDefinition($storage); - } - return $storages; - } -} diff --git a/apps/files_external/lib/Service/UserLegacyStoragesService.php b/apps/files_external/lib/Service/UserLegacyStoragesService.php deleted file mode 100644 index df6400baef7f..000000000000 --- a/apps/files_external/lib/Service/UserLegacyStoragesService.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @author Robin Appelman - * - * @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 - * - */ - -namespace OCA\Files_External\Service; - -use OCP\IUserSession; - -/** - * Read user defined mounts from the legacy mount.json - */ -class UserLegacyStoragesService extends LegacyStoragesService { - /** - * @var IUserSession - */ - private $userSession; - - /** - * @param BackendService $backendService - * @param IUserSession $userSession - */ - public function __construct(BackendService $backendService, IUserSession $userSession) { - $this->backendService = $backendService; - $this->userSession = $userSession; - } - - /** - * Read legacy config data - * - * @return array list of storage configs - */ - protected function readLegacyConfig() { - // read user config - $user = $this->userSession->getUser()->getUID(); - return \OC_Mount_Config::readData($user); - } -} diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index b057f58e48f7..162e2536f667 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -33,242 +33,15 @@ * */ -use phpseclib\Crypt\AES; use \OCA\Files_External\AppInfo\Application; -use \OCA\Files_External\Lib\Backend\LegacyBackend; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCP\Files\StorageNotAvailableException; /** * Class to configure mount.json globally and for users */ -class OC_Mount_Config { - // TODO: make this class non-static and give it a proper namespace - - const MOUNT_TYPE_GLOBAL = 'global'; - const MOUNT_TYPE_GROUP = 'group'; - const MOUNT_TYPE_USER = 'user'; - const MOUNT_TYPE_PERSONAL = 'personal'; - - // whether to skip backend test (for unit tests, as this static class is not mockable) - public static $skipTest = false; - +class OC_Mount_Config extends \OC\Files\External\LegacyUtil { /** @var Application */ public static $app; - /** - * @param string $class - * @param array $definition - * @return bool - * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend() - */ - public static function registerBackend($class, $definition) { - $backendService = self::$app->getContainer()->query('OCA\Files_External\Service\BackendService'); - $auth = self::$app->getContainer()->query('OCA\Files_External\Lib\Auth\Builtin'); - - $backendService->registerBackend(new LegacyBackend($class, $definition, $auth)); - - return true; - } - - /** - * Returns the mount points for the given user. - * The mount point is relative to the data directory. - * - * @param string $uid user - * @return array of mount point string as key, mountpoint config as value - * - * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages() - */ - public static function getAbsoluteMountPoints($uid) { - $mountPoints = []; - - $userGlobalStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserGlobalStoragesService'); - $userStoragesService = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService'); - $user = self::$app->getContainer()->query('OCP\IUserManager')->get($uid); - - $userGlobalStoragesService->setUser($user); - $userStoragesService->setUser($user); - - foreach ($userGlobalStoragesService->getStorages() as $storage) { - /** @var \OCA\Files_External\Lib\StorageConfig $storage */ - $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); - $mountEntry = self::prepareMountPointEntry($storage, false); - foreach ($mountEntry['options'] as &$option) { - $option = self::setUserVars($uid, $option); - } - $mountPoints[$mountPoint] = $mountEntry; - } - - foreach ($userStoragesService->getStorages() as $storage) { - $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); - $mountEntry = self::prepareMountPointEntry($storage, true); - foreach ($mountEntry['options'] as &$option) { - $option = self::setUserVars($uid, $option); - } - $mountPoints[$mountPoint] = $mountEntry; - } - - $userGlobalStoragesService->resetUser(); - $userStoragesService->resetUser(); - - return $mountPoints; - } - - /** - * Get the system mount points - * - * @return array - * - * @deprecated 8.2.0 use GlobalStoragesService::getStorages() - */ - public static function getSystemMountPoints() { - $mountPoints = []; - $service = self::$app->getContainer()->query('OCA\Files_External\Service\GlobalStoragesService'); - - foreach ($service->getStorages() as $storage) { - $mountPoints[] = self::prepareMountPointEntry($storage, false); - } - - return $mountPoints; - } - - /** - * Get the personal mount points of the current user - * - * @return array - * - * @deprecated 8.2.0 use UserStoragesService::getStorages() - */ - public static function getPersonalMountPoints() { - $mountPoints = []; - $service = self::$app->getContainer()->query('OCA\Files_External\Service\UserStoragesService'); - - foreach ($service->getStorages() as $storage) { - $mountPoints[] = self::prepareMountPointEntry($storage, true); - } - - return $mountPoints; - } - - /** - * Convert a StorageConfig to the legacy mountPoints array format - * There's a lot of extra information in here, to satisfy all of the legacy functions - * - * @param StorageConfig $storage - * @param bool $isPersonal - * @return array - */ - private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) { - $mountEntry = []; - - $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash - $mountEntry['class'] = $storage->getBackend()->getIdentifier(); - $mountEntry['backend'] = $storage->getBackend()->getText(); - $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier(); - $mountEntry['personal'] = $isPersonal; - $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions()); - $mountEntry['mountOptions'] = $storage->getMountOptions(); - $mountEntry['priority'] = $storage->getPriority(); - $mountEntry['applicable'] = [ - 'groups' => $storage->getApplicableGroups(), - 'users' => $storage->getApplicableUsers(), - ]; - // if mountpoint is applicable to all users the old API expects ['all'] - if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) { - $mountEntry['applicable']['users'] = ['all']; - } - - $mountEntry['id'] = $storage->getId(); - - return $mountEntry; - } - - /** - * fill in the correct values for $user - * - * @param string $user user value - * @param string|array $input - * @return string - */ - public static function setUserVars($user, $input) { - if (is_array($input)) { - foreach ($input as $key => $value) { - if (is_string($value)) { - $input[$key] = str_replace('$user', $user, $value); - } - } - } else { - if (is_string($input)) { - $input = str_replace('$user', $user, $input); - } - } - return $input; - } - - /** - * Test connecting using the given backend configuration - * - * @param string $class backend class name - * @param array $options backend configuration options - * @param boolean $isPersonal - * @return int see self::STATUS_* - * @throws Exception - */ - public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) { - if (self::$skipTest) { - return StorageNotAvailableException::STATUS_SUCCESS; - } - foreach ($options as $key => $option) { - $options[$key] = self::setUserVars(OCP\User::getUser(), $option); - } - if (class_exists($class)) { - try { - /** @var \OC\Files\Storage\Common $storage */ - $storage = new $class($options); - - try { - $result = $storage->test($isPersonal, $testOnly); - $storage->setAvailability($result); - if ($result) { - return StorageNotAvailableException::STATUS_SUCCESS; - } - } catch (\Exception $e) { - $storage->setAvailability(false); - throw $e; - } - } catch (Exception $exception) { - \OCP\Util::logException('files_external', $exception); - throw $exception; - } - } - return StorageNotAvailableException::STATUS_ERROR; - } - - /** - * Read the mount points in the config file into an array - * - * @param string|null $user If not null, personal for $user, otherwise system - * @return array - */ - public static function readData($user = null) { - if (isset($user)) { - $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json'; - } else { - $config = \OC::$server->getConfig(); - $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); - $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json'); - } - if (is_file($jsonFile)) { - $mountPoints = json_decode(file_get_contents($jsonFile), true); - if (is_array($mountPoints)) { - return $mountPoints; - } - } - return []; - } - /** * Get backend dependency message * TODO: move into AppFramework along with templates @@ -317,96 +90,4 @@ private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $back return (string)$l->t('Note: "%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$module, $backend]); } } - - /** - * Encrypt passwords in the given config options - * - * @param array $options mount options - * @return array updated options - */ - public static function encryptPasswords($options) { - if (isset($options['password'])) { - $options['password_encrypted'] = self::encryptPassword($options['password']); - // do not unset the password, we want to keep the keys order - // on load... because that's how the UI currently works - $options['password'] = ''; - } - return $options; - } - - /** - * Decrypt passwords in the given config options - * - * @param array $options mount options - * @return array updated options - */ - public static function decryptPasswords($options) { - // note: legacy options might still have the unencrypted password in the "password" field - if (isset($options['password_encrypted'])) { - $options['password'] = self::decryptPassword($options['password_encrypted']); - unset($options['password_encrypted']); - } - return $options; - } - - /** - * Encrypt a single password - * - * @param string $password plain text password - * @return string encrypted password - */ - private static function encryptPassword($password) { - $cipher = self::getCipher(); - $iv = \OCP\Util::generateRandomBytes(16); - $cipher->setIV($iv); - return base64_encode($iv . $cipher->encrypt($password)); - } - - /** - * Decrypts a single password - * - * @param string $encryptedPassword encrypted password - * @return string plain text password - */ - private static function decryptPassword($encryptedPassword) { - $cipher = self::getCipher(); - $binaryPassword = base64_decode($encryptedPassword); - $iv = substr($binaryPassword, 0, 16); - $cipher->setIV($iv); - $binaryPassword = substr($binaryPassword, 16); - return $cipher->decrypt($binaryPassword); - } - - /** - * Returns the encryption cipher - * - * @return AES - */ - private static function getCipher() { - $cipher = new AES(AES::MODE_CBC); - $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); - return $cipher; - } - - /** - * Computes a hash based on the given configuration. - * This is mostly used to find out whether configurations - * are the same. - * - * @param array $config - * @return string - */ - public static function makeConfigHash($config) { - $data = json_encode( - [ - 'c' => $config['backend'], - 'a' => $config['authMechanism'], - 'm' => $config['mountpoint'], - 'o' => $config['options'], - 'p' => isset($config['priority']) ? $config['priority'] : -1, - 'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [], - ] - ); - return hash('md5', $data); - } } diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php index a46a1aee210b..44bf8063873c 100644 --- a/apps/files_external/personal.php +++ b/apps/files_external/personal.php @@ -24,16 +24,16 @@ * */ -use \OCA\Files_External\Service\BackendService; +use \OCP\Files\External\IStoragesBackendService; // we must use the same container $appContainer = \OC_Mount_Config::$app->getContainer(); -$backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); -$userStoragesService = $appContainer->query('OCA\Files_External\Service\UserStoragesService'); +$backendService = \OC::$server->query('StoragesBackendService'); +$userStoragesService = \OC::$server->getUserStoragesService(); $tmpl = new OCP\Template('files_external', 'settings'); $tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); -$tmpl->assign('visibilityType', BackendService::VISIBILITY_PERSONAL); +$tmpl->assign('visibilityType', IStoragesBackendService::VISIBILITY_PERSONAL); $tmpl->assign('storages', $userStoragesService->getStorages()); $tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends())); $tmpl->assign('backends', $backendService->getAvailableBackends()); diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php index 8b4325cba364..54e34d65c05f 100644 --- a/apps/files_external/settings.php +++ b/apps/files_external/settings.php @@ -24,21 +24,21 @@ * */ -use \OCA\Files_External\Service\BackendService; +use OCP\Files\External\IStoragesBackendService; \OCP\User::checkAdminUser(); // we must use the same container $appContainer = \OC_Mount_Config::$app->getContainer(); -$backendService = $appContainer->query('OCA\Files_External\Service\BackendService'); -$globalStoragesService = $appContainer->query('OCA\Files_External\Service\GlobalStoragesService'); +$backendService = \OC::$server->query('StoragesBackendService'); +$globalStoragesService = \OC::$server->getGlobalStoragesService(); \OC_Util::addVendorScript('select2/select2'); \OC_Util::addVendorStyle('select2/select2'); $tmpl = new OCP\Template('files_external', 'settings'); $tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled()); -$tmpl->assign('visibilityType', BackendService::VISIBILITY_ADMIN); +$tmpl->assign('visibilityType', IStoragesBackendService::VISIBILITY_ADMIN); $tmpl->assign('storages', $globalStoragesService->getStorages()); $tmpl->assign('backends', $backendService->getAvailableBackends()); $tmpl->assign('authMechanisms', $backendService->getAuthMechanisms()); diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 6662f637039c..0c429d6862b6 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -1,8 +1,8 @@ t("Enable encryption"); $l->t("Enable previews"); @@ -87,7 +87,7 @@ function writeParameterInput($parameter, $options, $classes = []) {

t('External Storage')); ?>

'')) print_unescaped(''.$_['dependencies'].''); ?> - '> +
'> @@ -95,14 +95,14 @@ function writeParameterInput($parameter, $options, $classes = []) { - '.$l->t('Available for').''); ?> + '.$l->t('Available for').''); ?> + style="display: none;" > @@ -134,7 +134,7 @@ function writeParameterInput($parameter, $options, $classes = []) { - + @@ -159,7 +159,7 @@ function writeParameterInput($parameter, $options, $classes = []) {
t('External storage')); ?> t('Authentication')); ?> t('Configuration')); ?>   
'>

- +
/> @@ -169,14 +169,14 @@ function writeParameterInput($parameter, $options, $classes = []) { t('Allow users to mount the following external storage')); ?>
isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); + return $backend->isAllowedVisibleFor(IStoragesBackendService::VISIBILITY_PERSONAL); }); ?> getDeprecateTo()): ?> - isVisibleFor(BackendService::VISIBILITY_PERSONAL)) print_unescaped(' checked="checked"'); ?> /> + isVisibleFor(IStoragesBackendService::VISIBILITY_PERSONAL)) print_unescaped(' checked="checked"'); ?> />
diff --git a/apps/files_external/tests/Backend/LegacyBackendTest.php b/apps/files_external/tests/Backend/LegacyBackendTest.php deleted file mode 100644 index f2df4183333f..000000000000 --- a/apps/files_external/tests/Backend/LegacyBackendTest.php +++ /dev/null @@ -1,113 +0,0 @@ - - * - * @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 - * - */ - -namespace OCA\Files_External\Tests\Backend; - -use \OCA\Files_External\Lib\Backend\LegacyBackend; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\MissingDependency; - -class LegacyBackendTest extends \Test\TestCase { - - /** - * @return MissingDependency[] - */ - public static function checkDependencies() { - return [ - (new MissingDependency('abc'))->setMessage('foobar') - ]; - } - - public function testConstructor() { - $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin') - ->disableOriginalConstructor() - ->getMock(); - - $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest'; - $definition = [ - 'configuration' => [ - 'textfield' => 'Text field', - 'passwordfield' => '*Password field', - 'checkbox' => '!Checkbox', - 'hiddenfield' => '#Hidden field', - 'optionaltext' => '&Optional text field', - 'optionalpassword' => '&*Optional password field', - ], - 'backend' => 'Backend text', - 'priority' => 123, - 'custom' => 'foo/bar.js', - 'has_dependencies' => true, - ]; - - $backend = new LegacyBackend($class, $definition, $auth); - - $this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass()); - $this->assertEquals('Backend text', $backend->getText()); - $this->assertEquals(123, $backend->getPriority()); - $this->assertContains('foo/bar.js', $backend->getCustomJs()); - $this->assertArrayHasKey('builtin', $backend->getAuthSchemes()); - $this->assertEquals($auth, $backend->getLegacyAuthMechanism()); - - $dependencies = $backend->checkDependencies(); - $this->assertCount(1, $dependencies); - $this->assertEquals('abc', $dependencies[0]->getDependency()); - $this->assertEquals('foobar', $dependencies[0]->getMessage()); - - $parameters = $backend->getParameters(); - $this->assertEquals('Text field', $parameters['textfield']->getText()); - $this->assertEquals(DefinitionParameter::VALUE_TEXT, $parameters['textfield']->getType()); - $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['textfield']->getFlags()); - $this->assertEquals('Password field', $parameters['passwordfield']->getText()); - $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['passwordfield']->getType()); - $this->assertEquals(DefinitionParameter::FLAG_NONE, $parameters['passwordfield']->getFlags()); - $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()); - $this->assertEquals('Optional password field', $parameters['optionalpassword']->getText()); - $this->assertEquals(DefinitionParameter::VALUE_PASSWORD, $parameters['optionalpassword']->getType()); - $this->assertEquals(DefinitionParameter::FLAG_OPTIONAL, $parameters['optionalpassword']->getFlags()); - } - - public function testNoDependencies() { - $auth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Builtin') - ->disableOriginalConstructor() - ->getMock(); - - $class = '\OCA\Files_External\Tests\Backend\LegacyBackendTest'; - $definition = [ - 'configuration' => [ - ], - 'backend' => 'Backend text', - ]; - - $backend = new LegacyBackend($class, $definition, $auth); - - $dependencies = $backend->checkDependencies(); - $this->assertCount(0, $dependencies); - } - -} diff --git a/apps/files_external/tests/Command/CommandTest.php b/apps/files_external/tests/Command/CommandTest.php index 17632074b60f..f5ee80556881 100644 --- a/apps/files_external/tests/Command/CommandTest.php +++ b/apps/files_external/tests/Command/CommandTest.php @@ -22,8 +22,9 @@ namespace OCA\Files_External\Tests\Command; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; +use OC\Files\External\StorageConfig; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\Input; @@ -32,13 +33,11 @@ abstract class CommandTest extends TestCase { /** - * @param StorageConfig[] $mounts - * @return \OCA\Files_External\Service\GlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject + * @param IStorageConfig[] $mounts + * @return \OCP\Files\External\Service\IGlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject */ protected function getGlobalStorageService(array $mounts = []) { - $mock = $this->getMockBuilder('OCA\Files_External\Service\GlobalStoragesService') - ->disableOriginalConstructor() - ->getMock(); + $mock = $this->createMock('OCP\Files\External\Service\IGlobalStoragesService'); $this->bindMounts($mock, $mounts); @@ -47,7 +46,7 @@ protected function getGlobalStorageService(array $mounts = []) { /** * @param \PHPUnit_Framework_MockObject_MockObject $mock - * @param StorageConfig[] $mounts + * @param IStorageConfig[] $mounts */ protected function bindMounts(\PHPUnit_Framework_MockObject_MockObject $mock, array $mounts) { $mock->expects($this->any()) @@ -71,9 +70,10 @@ protected function bindMounts(\PHPUnit_Framework_MockObject_MockObject $mock, ar * @param array $options * @param array $users * @param array $groups - * @return StorageConfig + * @return IStorageConfig */ protected function getMount($id, $mountPoint, $backendClass, $applicableIdentifier = 'password::password', $config = [], $options = [], $users = [], $groups = []) { + // FIXME: use mock $mount = new StorageConfig($id); $mount->setMountPoint($mountPoint); diff --git a/apps/files_external/tests/Command/ListCommandTest.php b/apps/files_external/tests/Command/ListCommandTest.php index a68b3eea092e..44bfca17fc32 100644 --- a/apps/files_external/tests/Command/ListCommandTest.php +++ b/apps/files_external/tests/Command/ListCommandTest.php @@ -23,11 +23,12 @@ namespace OCA\Files_External\Tests\Command; use OCA\Files_External\Command\ListCommand; -use OCA\Files_External\Lib\Auth\NullMechanism; -use OCA\Files_External\Lib\Auth\Password\Password; -use OCA\Files_External\Lib\Auth\Password\SessionCredentials; +use OC\Files\External\Auth\NullMechanism; +use OC\Files\External\Auth\Password\Password; +use OC\Files\External\Auth\Password\SessionCredentials; use OCA\Files_External\Lib\Backend\Local; -use OCA\Files_External\Lib\StorageConfig; +use OC\Files\External\StorageConfig; +use OCP\Files\External\IStorageConfig; use Symfony\Component\Console\Output\BufferedOutput; class ListCommandTest extends CommandTest { @@ -35,10 +36,10 @@ class ListCommandTest extends CommandTest { * @return \OCA\Files_External\Command\ListCommand|\PHPUnit_Framework_MockObject_MockObject */ private function getInstance() { - /** @var \OCA\Files_External\Service\GlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject $globalService */ - $globalService = $this->createMock('\OCA\Files_External\Service\GlobalStoragesService', null, [], '', false); - /** @var \OCA\Files_External\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */ - $userService = $this->createMock('\OCA\Files_External\Service\UserStoragesService', null, [], '', false); + /** @var \OCP\Files\External\Service\IGlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject $globalService */ + $globalService = $this->createMock('\OCP\Files\External\Service\IGlobalStoragesService'); + /** @var \OC\Files\External\Service\IUserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */ + $userService = $this->createMock('\OCP\Files\External\Service\IUserStoragesService'); /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */ $userManager = $this->createMock('\OCP\IUserManager'); /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */ @@ -52,12 +53,13 @@ public function testListAuthIdentifier() { $session = $this->createMock('\OCP\ISession'); $crypto = $this->createMock('\OCP\Security\ICrypto'); $instance = $this->getInstance(); + // FIXME: use mock of IStorageConfig $mount1 = new StorageConfig(); - $mount1->setAuthMechanism(new Password($l10n)); - $mount1->setBackend(new Local($l10n, new NullMechanism($l10n))); + $mount1->setAuthMechanism(new Password()); + $mount1->setBackend(new Local($l10n, new NullMechanism())); $mount2 = new StorageConfig(); - $mount2->setAuthMechanism(new SessionCredentials($l10n, $session, $crypto)); - $mount2->setBackend(new Local($l10n, new NullMechanism($l10n))); + $mount2->setAuthMechanism(new SessionCredentials($session, $crypto)); + $mount2->setBackend(new Local($l10n, new NullMechanism())); $input = $this->getInput($instance, [], [ 'output' => 'json' ]); diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php index 5fac7f03dc08..6de783626a7a 100644 --- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php @@ -24,18 +24,16 @@ namespace OCA\Files_External\Tests\Controller; use OCA\Files_External\Controller\GlobalStoragesController; -use \OCP\AppFramework\Http; -use \OCA\Files_External\Service\BackendService; +use OCP\AppFramework\Http; +use OCP\Files\External\IStoragesBackendService; class GlobalStoragesControllerTest extends StoragesControllerTest { public function setUp() { parent::setUp(); - $this->service = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService') - ->disableOriginalConstructor() - ->getMock(); + $this->service = $this->createMock('\OCP\Files\External\Service\IGlobalStoragesService'); $this->service->method('getVisibilityType') - ->willReturn(BackendService::VISIBILITY_ADMIN); + ->willReturn(IStoragesBackendService::VISIBILITY_ADMIN); $this->controller = new GlobalStoragesController( 'files_external', diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTest.php index 6f5b93e40ff7..f7ed51736c5e 100644 --- a/apps/files_external/tests/Controller/StoragesControllerTest.php +++ b/apps/files_external/tests/Controller/StoragesControllerTest.php @@ -24,10 +24,10 @@ use \OCP\AppFramework\Http; -use \OCA\Files_External\Controller\GlobalStoragesController; -use \OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; +use OCA\Files_External\Controller\GlobalStoragesController; +use OCP\Files\External\Service\IGlobalStoragesService; +use OC\Files\External\StorageConfig; +use OCP\Files\External\NotFoundException; abstract class StoragesControllerTest extends \Test\TestCase { @@ -37,7 +37,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { protected $controller; /** - * @var GlobalStoragesService + * @var IGlobalStoragesService */ protected $service; @@ -50,10 +50,10 @@ public function tearDown() { } /** - * @return \OCA\Files_External\Lib\Backend\Backend + * @return \OCP\Files\External\Backend\Backend */ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backend->method('getStorageClass') @@ -64,10 +64,10 @@ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB' } /** - * @return \OCA\Files_External\Lib\Auth\AuthMechanism + * @return \OCP\Files\External\Auth\AuthMechanism */ protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') { - $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + $authMech = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->disableOriginalConstructor() ->getMock(); $authMech->method('getScheme') diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php index 39924044efa0..d9f987344ee8 100644 --- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php @@ -23,10 +23,10 @@ */ namespace OCA\Files_External\Tests\Controller; -use \OCA\Files_External\Controller\UserStoragesController; -use OCA\Files_External\Lib\StorageConfig; -use \OCP\AppFramework\Http; -use \OCA\Files_External\Service\BackendService; +use OCA\Files_External\Controller\UserStoragesController; +use OC\Files\External\StorageConfig; +use OCP\AppFramework\Http; +use OCP\Files\External\IStoragesBackendService; class UserStoragesControllerTest extends StoragesControllerTest { @@ -37,12 +37,10 @@ class UserStoragesControllerTest extends StoragesControllerTest { public function setUp() { parent::setUp(); - $this->service = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService') - ->disableOriginalConstructor() - ->getMock(); + $this->service = $this->createMock('\OCP\Files\External\Service\IUserStoragesService'); $this->service->method('getVisibilityType') - ->willReturn(BackendService::VISIBILITY_PERSONAL); + ->willReturn(IStoragesBackendService::VISIBILITY_PERSONAL); $this->controller = new UserStoragesController( 'files_external', @@ -57,7 +55,7 @@ public function setUp() { public function testAddOrUpdateStorageDisallowedBackend() { $backend = $this->getBackendMock(); $backend->method('isVisibleFor') - ->with(BackendService::VISIBILITY_PERSONAL) + ->with(IStoragesBackendService::VISIBILITY_PERSONAL) ->willReturn(false); $authMech = $this->getAuthMechMock(); diff --git a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php index 966bffe03315..844e39683120 100644 --- a/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php +++ b/apps/files_external/tests/LegacyDependencyCheckPolyfillTest.php @@ -21,7 +21,7 @@ namespace OCA\Files_External\Tests; -use \OCA\Files_External\Lib\MissingDependency; +use \OC\Files\External\MissingDependency; class LegacyDependencyCheckPolyfillTest extends \Test\TestCase { diff --git a/db_structure.xml b/db_structure.xml index 6b91c3c4c5d0..40f51daa3b44 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -1884,4 +1884,225 @@ + + + *dbprefix*external_mounts + + + mount_id + integer + 0 + true + 1 + 6 + + + mount_point + text + 128 + true + + + storage_backend + text + 64 + true + + + auth_backend + text + 64 + true + + + priority + integer + 100 + 4 + true + + + + type + integer + 4 + true + + +
+ + *dbprefix*external_applicable + + + applicable_id + integer + 0 + true + 1 + 6 + + + + mount_id + integer + true + 6 + + + + type + integer + 4 + true + + + + value + text + 64 + + + + applicable_mount + + mount_id + ascending + + + + applicable_type_value + + type + ascending + + + value + ascending + + + + applicable_type_value_mount + true + + type + ascending + + + value + ascending + + + mount_id + ascending + + + +
+ + + *dbprefix*external_config + + + config_id + integer + 0 + true + 1 + 6 + + + + mount_id + integer + true + 6 + + + key + text + true + 64 + + + value + text + true + 4096 + + + + config_mount + + mount_id + ascending + + + + config_mount_key + true + + mount_id + ascending + + + key + ascending + + + +
+ + + *dbprefix*external_options + + + option_id + integer + 0 + true + 1 + 6 + + + + mount_id + integer + true + 6 + + + key + text + true + 64 + + + value + text + true + 256 + + + + option_mount + + mount_id + ascending + + + + option_mount_key + true + + mount_id + ascending + + + key + ascending + + + +
+ diff --git a/lib/private/Encryption/File.php b/lib/private/Encryption/File.php index 608899666d82..e7f97a5c6a12 100644 --- a/lib/private/Encryption/File.php +++ b/lib/private/Encryption/File.php @@ -85,7 +85,7 @@ public function getAccessList($path) { // check if it is a group mount if (\OCP\App::isEnabled("files_external")) { - $mounts = \OC_Mount_Config::getSystemMountPoints(); + $mounts = \OC\Files\External\LegacyUtil::getSystemMountPoints(); foreach ($mounts as $mount) { if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index 006ca315200b..9428578b5c4d 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -290,7 +290,7 @@ public function getUserWithAccessToMountPoint($users, $groups) { */ public function isSystemWideMountPoint($path, $uid) { if (\OCP\App::isEnabled("files_external")) { - $mounts = \OC_Mount_Config::getSystemMountPoints(); + $mounts = \OC\Files\External\LegacyUtil::getSystemMountPoints(); foreach ($mounts as $mount) { if (strpos($path, '/files/' . $mount['mountpoint']) === 0) { if ($this->isMountPointApplicableToUser($mount, $uid)) { diff --git a/apps/files_external/lib/Lib/Auth/Builtin.php b/lib/private/Files/External/Auth/Builtin.php similarity index 87% rename from apps/files_external/lib/Lib/Auth/Builtin.php rename to lib/private/Files/External/Auth/Builtin.php index 98a7453e5c69..0018fc76e059 100644 --- a/apps/files_external/lib/Lib/Auth/Builtin.php +++ b/lib/private/Files/External/Auth/Builtin.php @@ -19,16 +19,18 @@ * */ -namespace OCA\Files_External\Lib\Auth; +namespace OC\Files\External\Auth; use \OCP\IL10N; +use \OCP\Files\External\Auth\AuthMechanism; /** * Builtin authentication mechanism, for legacy backends */ class Builtin extends AuthMechanism { - public function __construct(IL10N $l) { + public function __construct() { + $l = \OC::$server->getL10N('lib'); $this ->setIdentifier('builtin::builtin') ->setScheme(self::SCHEME_BUILTIN) diff --git a/lib/private/Files/External/Auth/CoreAuthMechanismProvider.php b/lib/private/Files/External/Auth/CoreAuthMechanismProvider.php new file mode 100644 index 000000000000..8bf26a7ad042 --- /dev/null +++ b/lib/private/Files/External/Auth/CoreAuthMechanismProvider.php @@ -0,0 +1,57 @@ + + * + * @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 + * + */ + +namespace OC\Files\External\Auth; + +use OC\ServerContainer; +use OCP\Files\External\Config\IAuthMechanismProvider; + +/** + * @package OC\Files\External + */ +class CoreAuthMechanismProvider implements IAuthMechanismProvider { + + /** @var ServerContainer */ + private $server; + + /** @var array class names */ + private $classNames; + + /** + * Constructs a new provider + * + * @param array array of auth mechanism class names to provide + */ + public function __construct(ServerContainer $server, array $classNames = []) { + $this->server = $server; + $this->classNames = $classNames; + } + + /** + * @{inheritdoc} + */ + public function getAuthMechanisms() { + return array_map(function($className) { + return $this->server->query($className); + }, $this->classNames); + } +} + diff --git a/apps/files_external/lib/Lib/Auth/NullMechanism.php b/lib/private/Files/External/Auth/NullMechanism.php similarity index 86% rename from apps/files_external/lib/Lib/Auth/NullMechanism.php rename to lib/private/Files/External/Auth/NullMechanism.php index ebe016babdf8..2b10ffa12c78 100644 --- a/apps/files_external/lib/Lib/Auth/NullMechanism.php +++ b/lib/private/Files/External/Auth/NullMechanism.php @@ -19,16 +19,19 @@ * */ -namespace OCA\Files_External\Lib\Auth; +namespace OC\Files\External\Auth; use \OCP\IL10N; +use \OCP\Files\External\Auth\AuthMechanism; + /** * Null authentication mechanism */ class NullMechanism extends AuthMechanism { - public function __construct(IL10N $l) { + public function __construct() { + $l = \OC::$server->getL10N('lib'); $this ->setIdentifier('null::null') ->setScheme(self::SCHEME_NULL) diff --git a/apps/files_external/lib/Lib/Auth/Password/Password.php b/lib/private/Files/External/Auth/Password/Password.php similarity index 84% rename from apps/files_external/lib/Lib/Auth/Password/Password.php rename to lib/private/Files/External/Auth/Password/Password.php index d99dd560eca0..40f3536e57e0 100644 --- a/apps/files_external/lib/Lib/Auth/Password/Password.php +++ b/lib/private/Files/External/Auth/Password/Password.php @@ -19,18 +19,19 @@ * */ -namespace OCA\Files_External\Lib\Auth\Password; +namespace OC\Files\External\Auth\Password; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; /** * Basic password authentication mechanism */ class Password extends AuthMechanism { - public function __construct(IL10N $l) { + public function __construct() { + $l = \OC::$server->getL10N('lib'); $this ->setIdentifier('password::password') ->setScheme(self::SCHEME_PASSWORD) diff --git a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php b/lib/private/Files/External/Auth/Password/SessionCredentials.php similarity index 77% rename from apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php rename to lib/private/Files/External/Auth/Password/SessionCredentials.php index 09c3fccca159..5ae7d1843f09 100644 --- a/apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php +++ b/lib/private/Files/External/Auth/Password/SessionCredentials.php @@ -20,18 +20,18 @@ * */ -namespace OCA\Files_External\Lib\Auth\Password; +namespace OC\Files\External\Auth\Password; -use \OCP\IUser; -use \OCP\IL10N; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Lib\StorageConfig; -use \OCP\ISession; -use \OCP\Security\ICrypto; -use \OCP\Files\Storage; -use \OCA\Files_External\Lib\SessionStorageWrapper; -use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; +use OCP\IUser; +use OCP\IL10N; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStorageConfig; +use OCP\ISession; +use OCP\Security\ICrypto; +use OCP\Files\Storage; +use OC\Files\External\SessionStorageWrapper; +use OCP\Files\External\InsufficientDataForMeaningfulAnswerException; /** * Username and password from login credentials, saved in session @@ -44,7 +44,8 @@ class SessionCredentials extends AuthMechanism { /** @var ICrypto */ protected $crypto; - public function __construct(IL10N $l, ISession $session, ICrypto $crypto) { + public function __construct(ISession $session, ICrypto $crypto) { + $l = \OC::$server->getL10N('lib'); $this->session = $session; $this->crypto = $crypto; @@ -56,6 +57,7 @@ public function __construct(IL10N $l, ISession $session, ICrypto $crypto) { ]) ; + // FIXME: use password from DB \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); } @@ -68,7 +70,7 @@ public function authenticate(array $params) { $this->session->set('password::sessioncredentials/credentials', $this->crypto->encrypt(json_encode($params))); } - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { $encrypted = $this->session->get('password::sessioncredentials/credentials'); if (!isset($encrypted)) { throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved'); diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/lib/private/Files/External/ConfigAdapter.php similarity index 79% rename from apps/files_external/lib/Config/ConfigAdapter.php rename to lib/private/Files/External/ConfigAdapter.php index 5cc6a8a0a4f3..15c572b6edb9 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/lib/private/Files/External/ConfigAdapter.php @@ -23,19 +23,17 @@ * */ -namespace OCA\Files_External\Config; +namespace OC\Files\External; use OC\Files\Storage\Wrapper\Availability; -use OCA\Files_External\Migration\StorageMigrator; use OCP\Files\Storage; use OC\Files\Mount\MountPoint; use OCP\Files\Storage\IStorageFactory; -use OCA\Files_External\Lib\PersonalMount; use OCP\Files\Config\IMountProvider; use OCP\IUser; -use OCA\Files_External\Service\UserStoragesService; -use OCA\Files_External\Service\UserGlobalStoragesService; -use OCA\Files_External\Lib\StorageConfig; +use OCP\Files\External\Service\IUserStoragesService; +use OCP\Files\External\Service\IUserGlobalStoragesService; +use OCP\Files\External\IStorageConfig; use OC\Files\Storage\FailedStorage; use OCP\Files\StorageNotAvailableException; @@ -44,38 +42,33 @@ */ class ConfigAdapter implements IMountProvider { - /** @var UserStoragesService */ + /** @var IUserStoragesService */ private $userStoragesService; - /** @var UserGlobalStoragesService */ + /** @var IUserGlobalStoragesService */ private $userGlobalStoragesService; - /** @var StorageMigrator */ - private $migrator; /** - * @param UserStoragesService $userStoragesService - * @param UserGlobalStoragesService $userGlobalStoragesService - * @param StorageMigrator $migrator + * @param IUserStoragesService $userStoragesService + * @param IUserGlobalStoragesService $userGlobalStoragesService */ public function __construct( - UserStoragesService $userStoragesService, - UserGlobalStoragesService $userGlobalStoragesService, - StorageMigrator $migrator + IUserStoragesService $userStoragesService, + IUserGlobalStoragesService $userGlobalStoragesService ) { $this->userStoragesService = $userStoragesService; $this->userGlobalStoragesService = $userGlobalStoragesService; - $this->migrator = $migrator; } /** * Process storage ready for mounting * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @param IUser $user */ - private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { + private function prepareStorageConfig(IStorageConfig &$storage, IUser $user) { foreach ($storage->getBackendOptions() as $option => $value) { - $storage->setBackendOption($option, \OC_Mount_Config::setUserVars( + $storage->setBackendOption($option, $this->setUserVars( $user->getUID(), $value )); } @@ -96,10 +89,10 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { /** * Construct the storage implementation * - * @param StorageConfig $storageConfig + * @param IStorageConfig $storageConfig * @return Storage */ - private function constructStorage(StorageConfig $storageConfig) { + private function constructStorage(IStorageConfig $storageConfig) { $class = $storageConfig->getBackend()->getStorageClass(); $storage = new $class($storageConfig->getBackendOptions()); @@ -118,8 +111,6 @@ private function constructStorage(StorageConfig $storageConfig) { * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { - $this->migrator->migrateUser($user); - $mounts = []; $this->userStoragesService->setUser($user); @@ -182,4 +173,26 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { return $mounts; } + + /** + * fill in the correct values for $user + * + * @param string $user user value + * @param string|array $input + * @return string + */ + private function setUserVars($user, $input) { + if (is_array($input)) { + foreach ($input as $key => $value) { + if (is_string($value)) { + $input[$key] = str_replace('$user', $user, $value); + } + } + } else { + if (is_string($input)) { + $input = str_replace('$user', $user, $input); + } + } + return $input; + } } diff --git a/apps/files_external/lib/Lib/DependencyTrait.php b/lib/private/Files/External/DependencyTrait.php similarity index 92% rename from apps/files_external/lib/Lib/DependencyTrait.php rename to lib/private/Files/External/DependencyTrait.php index b28c49308e66..326a91c33901 100644 --- a/apps/files_external/lib/Lib/DependencyTrait.php +++ b/lib/private/Files/External/DependencyTrait.php @@ -19,9 +19,9 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use \OCA\Files_External\Lib\MissingDependency; +use OC\Files\External\MissingDependency; /** * Trait for objects that have dependencies for use diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/lib/private/Files/External/FrontendDefinitionTrait.php similarity index 92% rename from apps/files_external/lib/Lib/FrontendDefinitionTrait.php rename to lib/private/Files/External/FrontendDefinitionTrait.php index 1bdd4a0010c1..87f1f90b2a6a 100644 --- a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php +++ b/lib/private/Files/External/FrontendDefinitionTrait.php @@ -20,10 +20,10 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\StorageConfig; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\IStorageConfig; /** * Trait for objects that have a frontend representation @@ -137,12 +137,12 @@ public function jsonSerializeDefinition() { } /** - * Check if parameters are satisfied in a StorageConfig + * Check if parameters are satisfied in a IStorageConfig * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @return bool */ - public function validateStorageDefinition(StorageConfig $storage) { + public function validateStorageDefinition(IStorageConfig $storage) { foreach ($this->getParameters() as $name => $parameter) { $value = $storage->getBackendOption($name); if (!is_null($value) || !$parameter->isOptional()) { diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/lib/private/Files/External/IdentifierTrait.php similarity index 98% rename from apps/files_external/lib/Lib/IdentifierTrait.php rename to lib/private/Files/External/IdentifierTrait.php index d869ab3be4b5..2f31f9dd0090 100644 --- a/apps/files_external/lib/Lib/IdentifierTrait.php +++ b/lib/private/Files/External/IdentifierTrait.php @@ -19,7 +19,7 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; /** * Trait for objects requiring an identifier (and/or identifier aliases) diff --git a/lib/private/Files/External/LegacyUtil.php b/lib/private/Files/External/LegacyUtil.php new file mode 100644 index 000000000000..09478a4e5a97 --- /dev/null +++ b/lib/private/Files/External/LegacyUtil.php @@ -0,0 +1,325 @@ + + * @author Bart Visscher + * @author Björn Schießle + * @author Frank Karlitschek + * @author Jesús Macias + * @author Joas Schilling + * @author Juan Pablo Villafáñez + * @author Lukas Reschke + * @author Michael Gapczynski + * @author Morris Jobke + * @author Philipp Kapfer + * @author Robin Appelman + * @author Robin McCorkell + * @author Thomas Müller + * @author Vincent Petry + * + * @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 + * + */ + +namespace OC\Files\External; + +use phpseclib\Crypt\AES; +use \OCP\Files\External\IStorageConfig; +use \OCP\Files\External\Backend\Backend; +use \OCP\Files\StorageNotAvailableException; + +/** + * Utility class with legacy implementation that used to be + * in OC_Mount_Config. + * + * Can be removed once all consumers of this private APIs are moved + * to the public ones. + */ +class LegacyUtil { + const MOUNT_TYPE_GLOBAL = 'global'; + const MOUNT_TYPE_GROUP = 'group'; + const MOUNT_TYPE_USER = 'user'; + const MOUNT_TYPE_PERSONAL = 'personal'; + + // whether to skip backend test (for unit tests, as this static class is not mockable) + public static $skipTest = false; + + /** + * Returns the mount points for the given user. + * The mount point is relative to the data directory. + * + * @param string $uid user + * @return array of mount point string as key, mountpoint config as value + * + * @deprecated 8.2.0 use IUserGlobalStoragesService::getStorages() and IUserStoragesService::getStorages() + */ + public static function getAbsoluteMountPoints($uid) { + $mountPoints = []; + + $userGlobalStoragesService = \OC::$server->getUserGlobalStoragesService(); + $userStoragesService = \OC::$server->getUserStoragesService(); + $user = \OC::$server->getUserManager()->get($uid); + + $userGlobalStoragesService->setUser($user); + $userStoragesService->setUser($user); + + foreach ($userGlobalStoragesService->getStorages() as $storage) { + /** @var IStorageConfig $storage */ + $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); + $mountEntry = self::prepareMountPointEntry($storage, false); + foreach ($mountEntry['options'] as &$option) { + $option = self::setUserVars($uid, $option); + } + $mountPoints[$mountPoint] = $mountEntry; + } + + foreach ($userStoragesService->getStorages() as $storage) { + $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); + $mountEntry = self::prepareMountPointEntry($storage, true); + foreach ($mountEntry['options'] as &$option) { + $option = self::setUserVars($uid, $option); + } + $mountPoints[$mountPoint] = $mountEntry; + } + + $userGlobalStoragesService->resetUser(); + $userStoragesService->resetUser(); + + return $mountPoints; + } + + /** + * Get the system mount points + * + * @return array + * + * @deprecated 8.2.0 use IGlobalStoragesService::getStorages() + */ + public static function getSystemMountPoints() { + $mountPoints = []; + $service = \OC::$server->getGlobalStoragesService(); + + foreach ($service->getStorages() as $storage) { + $mountPoints[] = self::prepareMountPointEntry($storage, false); + } + + return $mountPoints; + } + + /** + * Get the personal mount points of the current user + * + * @return array + * + * @deprecated 8.2.0 use IUserStoragesService::getStorages() + */ + public static function getPersonalMountPoints() { + $mountPoints = []; + $service = \OC::$server->getUserStoragesService(); + + foreach ($service->getStorages() as $storage) { + $mountPoints[] = self::prepareMountPointEntry($storage, true); + } + + return $mountPoints; + } + + /** + * Convert a IStorageConfig to the legacy mountPoints array format + * There's a lot of extra information in here, to satisfy all of the legacy functions + * + * @param IStorageConfig $storage + * @param bool $isPersonal + * @return array + */ + private static function prepareMountPointEntry(IStorageConfig $storage, $isPersonal) { + $mountEntry = []; + + $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash + $mountEntry['class'] = $storage->getBackend()->getIdentifier(); + $mountEntry['backend'] = $storage->getBackend()->getText(); + $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier(); + $mountEntry['personal'] = $isPersonal; + $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions()); + $mountEntry['mountOptions'] = $storage->getMountOptions(); + $mountEntry['priority'] = $storage->getPriority(); + $mountEntry['applicable'] = [ + 'groups' => $storage->getApplicableGroups(), + 'users' => $storage->getApplicableUsers(), + ]; + // if mountpoint is applicable to all users the old API expects ['all'] + if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) { + $mountEntry['applicable']['users'] = ['all']; + } + + $mountEntry['id'] = $storage->getId(); + + return $mountEntry; + } + + /** + * fill in the correct values for $user + * + * @param string $user user value + * @param string|array $input + * @return string + */ + public static function setUserVars($user, $input) { + if (is_array($input)) { + foreach ($input as $key => $value) { + if (is_string($value)) { + $input[$key] = str_replace('$user', $user, $value); + } + } + } else { + if (is_string($input)) { + $input = str_replace('$user', $user, $input); + } + } + return $input; + } + + /** + * Test connecting using the given backend configuration + * + * @param string $class backend class name + * @param array $options backend configuration options + * @param boolean $isPersonal + * @return int see self::STATUS_* + * @throws Exception + */ + public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) { + if (self::$skipTest) { + return StorageNotAvailableException::STATUS_SUCCESS; + } + foreach ($options as $key => $option) { + $options[$key] = self::setUserVars(\OCP\User::getUser(), $option); + } + if (class_exists($class)) { + try { + /** @var \OC\Files\Storage\Common $storage */ + $storage = new $class($options); + + try { + $result = $storage->test($isPersonal, $testOnly); + $storage->setAvailability($result); + if ($result) { + return StorageNotAvailableException::STATUS_SUCCESS; + } + } catch (\Exception $e) { + $storage->setAvailability(false); + throw $e; + } + } catch (Exception $exception) { + \OCP\Util::logException('files_external', $exception); + throw $exception; + } + } + return StorageNotAvailableException::STATUS_ERROR; + } + + /** + * Read the mount points in the config file into an array + * + * @param string|null $user If not null, personal for $user, otherwise system + * @return array + */ + public function readData($user = null) { + if (isset($user)) { + $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json'; + } else { + $config = \OC::$server->getConfig(); + $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); + $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json'); + } + if (is_file($jsonFile)) { + $mountPoints = json_decode(file_get_contents($jsonFile), true); + if (is_array($mountPoints)) { + return $mountPoints; + } + } + return []; + } + + /** + * Encrypt passwords in the given config options + * + * @param array $options mount options + * @return array updated options + */ + public static function encryptPasswords($options) { + if (isset($options['password'])) { + $options['password_encrypted'] = self::encryptPassword($options['password']); + // do not unset the password, we want to keep the keys order + // on load... because that's how the UI currently works + $options['password'] = ''; + } + return $options; + } + + /** + * Decrypt passwords in the given config options + * + * @param array $options mount options + * @return array updated options + */ + public static function decryptPasswords($options) { + // note: legacy options might still have the unencrypted password in the "password" field + if (isset($options['password_encrypted'])) { + $options['password'] = self::decryptPassword($options['password_encrypted']); + unset($options['password_encrypted']); + } + return $options; + } + + /** + * Encrypt a single password + * + * @param string $password plain text password + * @return string encrypted password + */ + private static function encryptPassword($password) { + $cipher = self::getCipher(); + $iv = \OCP\Util::generateRandomBytes(16); + $cipher->setIV($iv); + return base64_encode($iv . $cipher->encrypt($password)); + } + + /** + * Decrypts a single password + * + * @param string $encryptedPassword encrypted password + * @return string plain text password + */ + private static function decryptPassword($encryptedPassword) { + $cipher = self::getCipher(); + $binaryPassword = base64_decode($encryptedPassword); + $iv = substr($binaryPassword, 0, 16); + $cipher->setIV($iv); + $binaryPassword = substr($binaryPassword, 16); + return $cipher->decrypt($binaryPassword); + } + + /** + * Returns the encryption cipher + * + * @return AES + */ + private static function getCipher() { + $cipher = new AES(AES::MODE_CBC); + $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); + return $cipher; + } +} diff --git a/apps/files_external/lib/Lib/MissingDependency.php b/lib/private/Files/External/MissingDependency.php similarity index 97% rename from apps/files_external/lib/Lib/MissingDependency.php rename to lib/private/Files/External/MissingDependency.php index f0e8e3400704..878ec0349c1c 100644 --- a/apps/files_external/lib/Lib/MissingDependency.php +++ b/lib/private/Files/External/MissingDependency.php @@ -19,7 +19,7 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; /** * External storage backend dependency diff --git a/apps/files_external/lib/Lib/PersonalMount.php b/lib/private/Files/External/PersonalMount.php similarity index 91% rename from apps/files_external/lib/Lib/PersonalMount.php rename to lib/private/Files/External/PersonalMount.php index d2e8e3ab6c91..5fa2cc5b725d 100644 --- a/apps/files_external/lib/Lib/PersonalMount.php +++ b/lib/private/Files/External/PersonalMount.php @@ -21,24 +21,24 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; use OC\Files\Mount\MountPoint; use OC\Files\Mount\MoveableMount; -use OCA\Files_External\Service\UserStoragesService; +use OCP\Files\External\Service\IUserStoragesService; /** * Person mount points can be moved by the user */ class PersonalMount extends MountPoint implements MoveableMount { - /** @var UserStoragesService */ + /** @var IUserStoragesService */ protected $storagesService; /** @var int */ protected $numericStorageId; /** - * @param UserStoragesService $storagesService + * @param IUserStoragesService $storagesService * @param int $storageId * @param \OCP\Files\Storage $storage * @param string $mountpoint @@ -47,7 +47,7 @@ class PersonalMount extends MountPoint implements MoveableMount { * @param array $mountOptions mount specific options */ public function __construct( - UserStoragesService $storagesService, + IUserStoragesService $storagesService, $storageId, $storage, $mountpoint, diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/lib/private/Files/External/PriorityTrait.php similarity index 90% rename from apps/files_external/lib/Lib/PriorityTrait.php rename to lib/private/Files/External/PriorityTrait.php index 47f16c349dfd..2c3cdf5e9d52 100644 --- a/apps/files_external/lib/Lib/PriorityTrait.php +++ b/lib/private/Files/External/PriorityTrait.php @@ -19,9 +19,9 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use \OCA\Files_External\Service\BackendService; +use OCP\Files\External\IStoragesBackendService; /** * Trait to implement priority mechanics for a configuration class @@ -29,7 +29,7 @@ trait PriorityTrait { /** @var int initial priority */ - protected $priority = BackendService::PRIORITY_DEFAULT; + protected $priority = IStoragesBackendService::PRIORITY_DEFAULT; /** * @return int diff --git a/apps/files_external/lib/Service/DBConfigService.php b/lib/private/Files/External/Service/DBConfigService.php similarity index 99% rename from apps/files_external/lib/Service/DBConfigService.php rename to lib/private/Files/External/Service/DBConfigService.php index 3ca25eaea44d..8e80cb6bd422 100644 --- a/apps/files_external/lib/Service/DBConfigService.php +++ b/lib/private/Files/External/Service/DBConfigService.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; diff --git a/apps/files_external/lib/Service/GlobalStoragesService.php b/lib/private/Files/External/Service/GlobalStoragesService.php similarity index 79% rename from apps/files_external/lib/Service/GlobalStoragesService.php rename to lib/private/Files/External/Service/GlobalStoragesService.php index d28391de944d..5fc840012f0e 100644 --- a/apps/files_external/lib/Service/GlobalStoragesService.php +++ b/lib/private/Files/External/Service/GlobalStoragesService.php @@ -24,24 +24,27 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; -use \OC\Files\Filesystem; -use OCA\Files_External\Lib\StorageConfig; +use OC\Files\Filesystem; + +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\Service\IGlobalStoragesService; /** * Service class to manage global external storages */ -class GlobalStoragesService extends StoragesService { +class GlobalStoragesService extends StoragesService implements IGlobalStoragesService { /** * Triggers $signal for all applicable users of the given * storage * - * @param StorageConfig $storage storage data + * @param IStorageConfig $storage storage data * @param string $signal signal to trigger */ - protected function triggerHooks(StorageConfig $storage, $signal) { + protected function triggerHooks(IStorageConfig $storage, $signal) { // FIXME: Use as expression in empty once PHP 5.4 support is dropped $applicableUsers = $storage->getApplicableUsers(); $applicableGroups = $storage->getApplicableGroups(); @@ -50,7 +53,7 @@ protected function triggerHooks(StorageConfig $storage, $signal) { $this->triggerApplicableHooks( $signal, $storage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, ['all'] ); return; @@ -59,13 +62,13 @@ protected function triggerHooks(StorageConfig $storage, $signal) { $this->triggerApplicableHooks( $signal, $storage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $applicableUsers ); $this->triggerApplicableHooks( $signal, $storage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, $applicableGroups ); } @@ -75,10 +78,10 @@ protected function triggerHooks(StorageConfig $storage, $signal) { * accommodate for additions/deletions in applicableUsers * and applicableGroups fields. * - * @param StorageConfig $oldStorage old storage config - * @param StorageConfig $newStorage new storage config + * @param IStorageConfig $oldStorage old storage config + * @param IStorageConfig $newStorage new storage config */ - protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { + protected function triggerChangeHooks(IStorageConfig $oldStorage, IStorageConfig $newStorage) { // if mount point changed, it's like a deletion + creation if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); @@ -99,7 +102,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_delete_mount, $oldStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, ['all'] ); } @@ -108,7 +111,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_delete_mount, $oldStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $userDeletions ); @@ -116,7 +119,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_delete_mount, $oldStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, $groupDeletions ); @@ -124,7 +127,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_create_mount, $newStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $userAdditions ); @@ -132,7 +135,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_create_mount, $newStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, $groupAdditions ); @@ -144,7 +147,7 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ $this->triggerApplicableHooks( Filesystem::signal_create_mount, $newStorage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, ['all'] ); } @@ -153,13 +156,13 @@ protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $ /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return string IStoragesBackendService::VISIBILITY_* constants */ public function getVisibilityType() { - return BackendService::VISIBILITY_ADMIN; + return IStoragesBackendService::VISIBILITY_ADMIN; } - protected function isApplicable(StorageConfig $config) { + protected function isApplicable(IStorageConfig $config) { return true; } @@ -172,10 +175,10 @@ public function getStorageForAllUsers() { $mounts = $this->dbConfig->getAllMounts(); $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); $configs = array_filter($configs, function ($config) { - return $config instanceof StorageConfig; + return $config instanceof IStorageConfig; }); - $keys = array_map(function (StorageConfig $config) { + $keys = array_map(function (IStorageConfig $config) { return $config->getId(); }, $configs); diff --git a/apps/files_external/lib/Service/StoragesService.php b/lib/private/Files/External/Service/StoragesService.php similarity index 87% rename from apps/files_external/lib/Service/StoragesService.php rename to lib/private/Files/External/Service/StoragesService.php index d0a4eebe162d..dd87e1dcb70d 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/lib/private/Files/External/Service/StoragesService.php @@ -25,22 +25,26 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; -use \OC\Files\Filesystem; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OC\Files\Filesystem; +use OC\Files\External\StorageConfig; + +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\Auth\AuthMechanism; use OCP\Files\Config\IUserMountCache; -use \OCP\Files\StorageNotAvailableException; +use OCP\Files\StorageNotAvailableException; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\Service\IStoragesService; /** * Service class to manage external storages */ -abstract class StoragesService { +abstract class StoragesService implements IStoragesService { - /** @var BackendService */ + /** @var IStoragesBackendService */ protected $backendService; /** @@ -54,11 +58,11 @@ abstract class StoragesService { protected $userMountCache; /** - * @param BackendService $backendService + * @param IStoragesBackendService $backendService * @param DBConfigService $dbConfigService * @param IUserMountCache $userMountCache */ - public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { + public function __construct(IStoragesBackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) { $this->backendService = $backendService; $this->dbConfig = $dbConfigService; $this->userMountCache = $userMountCache; @@ -124,10 +128,10 @@ protected function readConfig() { $mounts = $this->readDBConfig(); $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); $configs = array_filter($configs, function ($config) { - return $config instanceof StorageConfig; + return $config instanceof IStorageConfig; }); - $keys = array_map(function (StorageConfig $config) { + $keys = array_map(function (IStorageConfig $config) { return $config->getId(); }, $configs); @@ -139,7 +143,7 @@ protected function readConfig() { * * @param int $id storage id * - * @return StorageConfig + * @return IStorageConfig * @throws NotFoundException if the storage with the given id was not found */ public function getStorage($id) { @@ -163,12 +167,12 @@ public function getStorage($id) { * @param StorageConfig $config * @return bool */ - abstract protected function isApplicable(StorageConfig $config); + abstract protected function isApplicable(IStorageConfig $config); /** * Gets all storages, valid or not * - * @return StorageConfig[] array of storage configs + * @return IStorageConfig[] array of storage configs */ public function getAllStorages() { return $this->readConfig(); @@ -177,7 +181,7 @@ public function getAllStorages() { /** * Gets all valid storages * - * @return StorageConfig[] + * @return IStorageConfig[] */ public function getStorages() { return array_filter($this->getAllStorages(), [$this, 'validateStorage']); @@ -187,10 +191,10 @@ public function getStorages() { * Validate storage * FIXME: De-duplicate with StoragesController::validate() * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @return bool */ - protected function validateStorage(StorageConfig $storage) { + protected function validateStorage(IStorageConfig $storage) { /** @var Backend */ $backend = $storage->getBackend(); /** @var AuthMechanism */ @@ -211,7 +215,7 @@ protected function validateStorage(StorageConfig $storage) { /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return string IStoragesBackendService::VISIBILITY_* constants */ abstract public function getVisibilityType(); @@ -222,14 +226,24 @@ protected function getType() { return DBConfigService::MOUNT_TYPE_ADMIN; } + /** + * Creates a new storage configuration + * + * @return IStorageConfig + * @since 9.2.0 + */ + public function createConfig() { + return new StorageConfig(); + } + /** * Add new storage to the configuration * - * @param StorageConfig $newStorage storage attributes + * @param IStorageConfig $newStorage storage attributes * - * @return StorageConfig storage config, with added id + * @return IStorageConfig storage config, with added id */ - public function addStorage(StorageConfig $newStorage) { + public function addStorage(IStorageConfig $newStorage) { $allStorages = $this->readConfig(); $configId = $this->dbConfig->addMount( @@ -280,7 +294,7 @@ public function addStorage(StorageConfig $newStorage) { * @param array|null $applicableGroups groups for which to mount the storage * @param int|null $priority priority * - * @return StorageConfig + * @return IStorageConfig */ public function createStorage( $mountPoint, @@ -300,7 +314,7 @@ public function createStorage( if (!$authMechanism) { throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier); } - $newStorage = new StorageConfig(); + $newStorage = $this->createConfig(); $newStorage->setMountPoint($mountPoint); $newStorage->setBackend($backend); $newStorage->setAuthMechanism($authMechanism); @@ -350,27 +364,27 @@ protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $app * @param StorageConfig $storage storage data * @param string $signal signal to trigger */ - abstract protected function triggerHooks(StorageConfig $storage, $signal); + abstract protected function triggerHooks(IStorageConfig $storage, $signal); /** * Triggers signal_create_mount or signal_delete_mount to * accommodate for additions/deletions in applicableUsers * and applicableGroups fields. * - * @param StorageConfig $oldStorage old storage data - * @param StorageConfig $newStorage new storage data + * @param IStorageConfig $oldStorage old storage data + * @param IStorageConfig $newStorage new storage data */ - abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); + abstract protected function triggerChangeHooks(IStorageConfig $oldStorage, IStorageConfig $newStorage); /** * Update storage to the configuration * - * @param StorageConfig $updatedStorage storage attributes + * @param IStorageConfig $updatedStorage storage attributes * - * @return StorageConfig storage config + * @return IStorageConfig storage config * @throws NotFoundException if the given storage does not exist in the config */ - public function updateStorage(StorageConfig $updatedStorage) { + public function updateStorage(IStorageConfig $updatedStorage) { $id = $updatedStorage->getId(); $existingMount = $this->dbConfig->getMountById($id); @@ -482,10 +496,10 @@ public function removeStorage($id) { /** * Returns the rusty storage id from oc_storages from the given storage config. * - * @param StorageConfig $storageConfig + * @param IStorageConfig $storageConfig * @return string rusty storage id */ - private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) { + private function getRustyStorageIdFromConfig(IStorageConfig $storageConfig) { // if any of the storage options contains $user, it is not possible // to compute the possible storage id as we don't know which users // mounted it already (and we certainly don't want to iterate over ALL users) @@ -508,10 +522,10 @@ private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) { /** * Construct the storage implementation * - * @param StorageConfig $storageConfig + * @param IStorageConfig $storageConfig * @return int */ - private function getStorageId(StorageConfig $storageConfig) { + private function getStorageId(IStorageConfig $storageConfig) { try { $class = $storageConfig->getBackend()->getStorageClass(); /** @var \OC\Files\Storage\Storage $storage */ diff --git a/apps/files_external/lib/Service/UserGlobalStoragesService.php b/lib/private/Files/External/Service/UserGlobalStoragesService.php similarity index 84% rename from apps/files_external/lib/Service/UserGlobalStoragesService.php rename to lib/private/Files/External/Service/UserGlobalStoragesService.php index 03e6131ddeb2..754729f98159 100644 --- a/apps/files_external/lib/Service/UserGlobalStoragesService.php +++ b/lib/private/Files/External/Service/UserGlobalStoragesService.php @@ -20,18 +20,20 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; use OCP\Files\Config\IUserMountCache; -use \OCP\IUserSession; -use \OCP\IGroupManager; -use \OCA\Files_External\Lib\StorageConfig; +use OCP\IUserSession; +use OCP\IGroupManager; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\Service\IUserGlobalStoragesService; /** * Service class to read global storages applicable to the user * Read-only access available, attempting to write will throw DomainException */ -class UserGlobalStoragesService extends GlobalStoragesService { +class UserGlobalStoragesService extends GlobalStoragesService implements IUserGlobalStoragesService { use UserTrait; @@ -39,14 +41,14 @@ class UserGlobalStoragesService extends GlobalStoragesService { protected $groupManager; /** - * @param BackendService $backendService + * @param IStoragesBackendService $backendService * @param DBConfigService $dbConfig * @param IUserSession $userSession * @param IGroupManager $groupManager * @param IUserMountCache $userMountCache */ public function __construct( - BackendService $backendService, + IStoragesBackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, IGroupManager $groupManager, @@ -60,8 +62,8 @@ public function __construct( /** * Replace config hash ID with real IDs, for migrating legacy storages * - * @param StorageConfig[] $storages Storages with real IDs - * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs + * @param IStorageConfig[] $storages Storages with real IDs + * @param IStorageConfig[] $storagesWithConfigHash Storages with config hash IDs */ protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { // as a read-only view, storage IDs don't need to be real @@ -82,11 +84,11 @@ protected function readDBConfig() { return array_merge($userMounts, $groupMounts, $globalMounts); } - public function addStorage(StorageConfig $newStorage) { + public function addStorage(IStorageConfig $newStorage) { throw new \DomainException('UserGlobalStoragesService writing disallowed'); } - public function updateStorage(StorageConfig $updatedStorage) { + public function updateStorage(IStorageConfig $updatedStorage) { throw new \DomainException('UserGlobalStoragesService writing disallowed'); } @@ -101,7 +103,7 @@ public function removeStorage($id) { * Get unique storages, in case two are defined with the same mountpoint * Higher priority storages take precedence * - * @return StorageConfig[] + * @return IStorageConfig[] */ public function getUniqueStorages() { $storages = $this->getStorages(); @@ -137,10 +139,10 @@ public function getUniqueStorages() { * Get a priority 'type', where a bigger number means higher priority * user applicable > group applicable > 'all' * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @return int */ - protected function getPriorityType(StorageConfig $storage) { + protected function getPriorityType(IStorageConfig $storage) { $applicableUsers = $storage->getApplicableUsers(); $applicableGroups = $storage->getApplicableGroups(); @@ -153,7 +155,7 @@ protected function getPriorityType(StorageConfig $storage) { return 0; } - protected function isApplicable(StorageConfig $config) { + protected function isApplicable(IStorageConfig $config) { $applicableUsers = $config->getApplicableUsers(); $applicableGroups = $config->getApplicableGroups(); diff --git a/apps/files_external/lib/Service/UserStoragesService.php b/lib/private/Files/External/Service/UserStoragesService.php similarity index 68% rename from apps/files_external/lib/Service/UserStoragesService.php rename to lib/private/Files/External/Service/UserStoragesService.php index 6ef236261ab6..5a51dfe3274e 100644 --- a/apps/files_external/lib/Service/UserStoragesService.php +++ b/lib/private/Files/External/Service/UserStoragesService.php @@ -23,34 +23,36 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; + +use OC\Files\Filesystem; +use OC\Files\External\Service\UserTrait; use OCP\Files\Config\IUserMountCache; -use \OCP\IUserSession; -use \OC\Files\Filesystem; +use OCP\IUserSession; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use \OCA\Files_External\Service\BackendService; -use \OCA\Files_External\Service\UserTrait; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; +use OCP\Files\External\IStoragesBackendService; +use OCP\Files\External\Service\IUserStoragesService; /** * Service class to manage user external storages * (aka personal storages) */ -class UserStoragesService extends StoragesService { +class UserStoragesService extends StoragesService implements IUserStoragesService { use UserTrait; /** * Create a user storages service * - * @param BackendService $backendService + * @param IStoragesBackendService $backendService * @param DBConfigService $dbConfig * @param IUserSession $userSession user session * @param IUserMountCache $userMountCache */ public function __construct( - BackendService $backendService, + IStoragesBackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, IUserMountCache $userMountCache @@ -67,17 +69,17 @@ protected function readDBConfig() { * Triggers $signal for all applicable users of the given * storage * - * @param StorageConfig $storage storage data + * @param IStorageConfig $storage storage data * @param string $signal signal to trigger */ - protected function triggerHooks(StorageConfig $storage, $signal) { + protected function triggerHooks(IStorageConfig $storage, $signal) { $user = $this->getUser()->getUID(); // trigger hook for the current user $this->triggerApplicableHooks( $signal, $storage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, [$user] ); } @@ -87,10 +89,10 @@ protected function triggerHooks(StorageConfig $storage, $signal) { * accommodate for additions/deletions in applicableUsers * and applicableGroups fields. * - * @param StorageConfig $oldStorage old storage data - * @param StorageConfig $newStorage new storage data + * @param IStorageConfig $oldStorage old storage data + * @param IStorageConfig $newStorage new storage data */ - protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { + protected function triggerChangeHooks(IStorageConfig $oldStorage, IStorageConfig $newStorage) { // if mount point changed, it's like a deletion + creation if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); @@ -105,11 +107,11 @@ protected function getType() { /** * Add new storage to the configuration * - * @param StorageConfig $newStorage storage attributes + * @param IStorageConfig $newStorage storage attributes * - * @return StorageConfig storage config, with added id + * @return IStorageConfig storage config, with added id */ - public function addStorage(StorageConfig $newStorage) { + public function addStorage(IStorageConfig $newStorage) { $newStorage->setApplicableUsers([$this->getUser()->getUID()]); $config = parent::addStorage($newStorage); return $config; @@ -118,12 +120,12 @@ public function addStorage(StorageConfig $newStorage) { /** * Update storage to the configuration * - * @param StorageConfig $updatedStorage storage attributes + * @param IStorageConfig $updatedStorage storage attributes * - * @return StorageConfig storage config + * @return IStorageConfig storage config * @throws NotFoundException if the given storage does not exist in the config */ - public function updateStorage(StorageConfig $updatedStorage) { + public function updateStorage(IStorageConfig $updatedStorage) { $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]); return parent::updateStorage($updatedStorage); } @@ -131,13 +133,13 @@ public function updateStorage(StorageConfig $updatedStorage) { /** * Get the visibility type for this controller, used in validation * - * @return string BackendService::VISIBILITY_* constants + * @return string IStoragesBackendService::VISIBILITY_* constants */ public function getVisibilityType() { - return BackendService::VISIBILITY_PERSONAL; + return IStoragesBackendService::VISIBILITY_PERSONAL; } - protected function isApplicable(StorageConfig $config) { - return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl; + protected function isApplicable(IStorageConfig $config) { + return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === IStorageConfig::MOUNT_TYPE_PERSONAl; } } diff --git a/apps/files_external/lib/Service/UserTrait.php b/lib/private/Files/External/Service/UserTrait.php similarity index 97% rename from apps/files_external/lib/Service/UserTrait.php rename to lib/private/Files/External/Service/UserTrait.php index 9a867d04ab75..acb241b0dfa1 100644 --- a/apps/files_external/lib/Service/UserTrait.php +++ b/lib/private/Files/External/Service/UserTrait.php @@ -19,7 +19,7 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External\Service; use \OCP\IUserSession; use \OCP\IUser; diff --git a/apps/files_external/lib/Lib/SessionStorageWrapper.php b/lib/private/Files/External/SessionStorageWrapper.php similarity index 97% rename from apps/files_external/lib/Lib/SessionStorageWrapper.php rename to lib/private/Files/External/SessionStorageWrapper.php index 86d738344a36..2704ef4dfa41 100644 --- a/apps/files_external/lib/Lib/SessionStorageWrapper.php +++ b/lib/private/Files/External/SessionStorageWrapper.php @@ -19,7 +19,7 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; use \OCP\Files\Storage; use \OC\Files\Storage\Wrapper\PermissionsMask; diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/lib/private/Files/External/StorageConfig.php similarity index 94% rename from apps/files_external/lib/Lib/StorageConfig.php rename to lib/private/Files/External/StorageConfig.php index 92cc3fcbb8c0..485f106f2533 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/lib/private/Files/External/StorageConfig.php @@ -1,13 +1,13 @@ - * @author Joas Schilling + * @author Joas Schilling * @author Lukas Reschke * @author Robin Appelman * @author Robin McCorkell * @author Vincent Petry * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -24,19 +24,17 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use OCA\Files_External\Lib\Auth\IUserProvided; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Auth\IUserProvided; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Backend\Backend; /** * External storage configuration */ -class StorageConfig implements \JsonSerializable { - const MOUNT_TYPE_ADMIN = 1; - const MOUNT_TYPE_PERSONAl = 2; - +class StorageConfig implements IStorageConfig { /** * Storage config id * @@ -218,7 +216,7 @@ public function setBackendOptions($backendOptions) { foreach($backendOptions as $key => $value) { if(isset($parameters[$key])) { switch ($parameters[$key]->getType()) { - case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: + case \OCP\Files\External\DefinitionParameter::VALUE_BOOLEAN: $value = (bool)$value; break; } diff --git a/apps/files_external/lib/Lib/StorageModifierTrait.php b/lib/private/Files/External/StorageModifierTrait.php similarity index 78% rename from apps/files_external/lib/Lib/StorageModifierTrait.php rename to lib/private/Files/External/StorageModifierTrait.php index 431998896e08..1b2a28e091cd 100644 --- a/apps/files_external/lib/Lib/StorageModifierTrait.php +++ b/lib/private/Files/External/StorageModifierTrait.php @@ -19,18 +19,18 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use \OCP\IUser; -use \OCP\Files\Storage; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; -use \OCP\Files\StorageNotAvailableException; +use OCP\IUser; +use OCP\Files\Storage; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\InsufficientDataForMeaningfulAnswerException; +use OCP\Files\StorageNotAvailableException; /** - * Trait for objects that can modify StorageConfigs and wrap Storages + * Trait for objects that can modify IStorageConfigs and wrap Storages * - * When a storage implementation is being prepared for use, the StorageConfig + * When a storage implementation is being prepared for use, the IStorageConfig * is passed through manipulateStorageConfig() to update any parameters as * necessary. After the storage implementation has been constructed, it is * passed through wrapStorage(), potentially replacing the implementation with @@ -43,14 +43,14 @@ trait StorageModifierTrait { /** - * Modify a StorageConfig parameters + * Modify a IStorageConfig parameters * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @param IUser $user User the storage is being used as * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException */ - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { } /** diff --git a/apps/files_external/lib/Service/BackendService.php b/lib/private/Files/External/StoragesBackendService.php similarity index 89% rename from apps/files_external/lib/Service/BackendService.php rename to lib/private/Files/External/StoragesBackendService.php index a56bf451d351..2b466208189c 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/lib/private/Files/External/StoragesBackendService.php @@ -20,30 +20,20 @@ * */ -namespace OCA\Files_External\Service; +namespace OC\Files\External; -use \OCP\IConfig; +use OCP\IConfig; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_External\Lib\Config\IBackendProvider; -use \OCA\Files_External\Lib\Config\IAuthMechanismProvider; +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Config\IBackendProvider; +use OCP\Files\External\Config\IAuthMechanismProvider; +use OCP\Files\External\IStoragesBackendService; /** * Service class to manage backend definitions */ -class BackendService { - - /** Visibility constants for VisibilityTrait */ - const VISIBILITY_NONE = 0; - const VISIBILITY_PERSONAL = 1; - const VISIBILITY_ADMIN = 2; - //const VISIBILITY_ALIENS = 4; - - const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN - - /** Priority constants for PriorityTrait */ - const PRIORITY_DEFAULT = 100; +class StoragesBackendService implements IStoragesBackendService { /** @var IConfig */ protected $config; @@ -130,7 +120,7 @@ private function loadAuthMechanismProviders() { */ public function registerBackend(Backend $backend) { if (!$this->isAllowedUserBackend($backend)) { - $backend->removeVisibility(BackendService::VISIBILITY_PERSONAL); + $backend->removeVisibility(IStoragesBackendService::VISIBILITY_PERSONAL); } foreach ($backend->getIdentifierAliases() as $alias) { $this->backends[$alias] = $backend; @@ -154,7 +144,7 @@ public function registerBackends(array $backends) { */ public function registerAuthMechanism(AuthMechanism $authMech) { if (!$this->isAllowedAuthMechanism($authMech)) { - $authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL); + $authMech->removeVisibility(IStoragesBackendService::VISIBILITY_PERSONAL); } foreach ($authMech->getIdentifierAliases() as $alias) { $this->authMechanisms[$alias] = $authMech; diff --git a/apps/files_external/lib/Lib/VisibilityTrait.php b/lib/private/Files/External/VisibilityTrait.php similarity index 93% rename from apps/files_external/lib/Lib/VisibilityTrait.php rename to lib/private/Files/External/VisibilityTrait.php index 6f2849980454..64192acfa02d 100644 --- a/apps/files_external/lib/Lib/VisibilityTrait.php +++ b/lib/private/Files/External/VisibilityTrait.php @@ -19,9 +19,9 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\External; -use \OCA\Files_External\Service\BackendService; +use OCP\Files\External\IStoragesBackendService; /** * Trait to implement visibility mechanics for a configuration class @@ -36,10 +36,10 @@ trait VisibilityTrait { /** @var int visibility */ - protected $visibility = BackendService::VISIBILITY_DEFAULT; + protected $visibility = IStoragesBackendService::VISIBILITY_DEFAULT; /** @var int allowed visibilities */ - protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT; + protected $allowedVisibility = IStoragesBackendService::VISIBILITY_DEFAULT; /** * @return int diff --git a/lib/private/Server.php b/lib/private/Server.php index f37ba6924166..5ed99aafa350 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -86,6 +86,11 @@ use OCP\Security\IContentSecurityPolicyManager; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use OC\Files\External\StoragesBackendService; +use OC\Files\External\Service\UserStoragesService; +use OC\Files\External\Service\UserGlobalStoragesService; +use OC\Files\External\Service\GlobalStoragesService; +use OC\Files\External\Service\DBConfigService; /** * Class Server @@ -398,6 +403,7 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerService('Crypto', function (Server $c) { return new Crypto($c->getConfig(), $c->getSecureRandom()); }); + $this->registerAlias('OCP\Security\ICrypto', 'Crypto'); $this->registerService('Hasher', function (Server $c) { return new Hasher($c->getConfig()); }); @@ -495,6 +501,12 @@ public function __construct($webRoot, \OC\Config $config) { $manager->registerHomeProvider(new LocalHomeMountProvider()); $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); + // external storage + $manager->registerProvider(new \OC\Files\External\ConfigAdapter( + $c->query('UserStoragesService'), + $c->query('UserGlobalStoragesService') + )); + return $manager; }); $this->registerService('IniWrapper', function ($c) { @@ -663,6 +675,67 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerService('ContentSecurityPolicyManager', function (Server $c) { return new ContentSecurityPolicyManager(); }); + $this->registerService('StoragesDBConfigService', function (Server $c) { + return new DBConfigService( + $c->getDatabaseConnection(), + $c->getCrypto() + ); + }); + $this->registerService('StoragesBackendService', function (Server $c) { + $service = new StoragesBackendService($c->query('AllConfig')); + + // register auth mechanisms provided by core + $provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [ + // AuthMechanism::SCHEME_NULL mechanism + 'OC\Files\External\Auth\NullMechanism', + + // AuthMechanism::SCHEME_BUILTIN mechanism + 'OC\Files\External\Auth\Builtin', + + // AuthMechanism::SCHEME_PASSWORD mechanisms + 'OC\Files\External\Auth\Password\Password', + ]); + + $service->registerAuthMechanismProvider($provider); + + // force-load the session one as it will register hooks... + // TODO: obsolete it and use the TokenProvider to get the user's password from the session + $sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials( + $c->getSession(), + $c->getCrypto() + ); + $service->registerAuthMechanism($sessionCreds); + + return $service; + }); + $this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService'); + $this->registerService('GlobalStoragesService', function (Server $c) { + return new GlobalStoragesService( + $c->query('StoragesBackendService'), + $c->query('StoragesDBConfigService'), + $c->query('UserMountCache') + ); + }); + $this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService'); + $this->registerService('UserGlobalStoragesService', function (Server $c) { + return new UserGlobalStoragesService( + $c->query('StoragesBackendService'), + $c->query('StoragesDBConfigService'), + $c->query('UserSession'), + $c->query('GroupManager'), + $c->query('UserMountCache') + ); + }); + $this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService'); + $this->registerService('UserStoragesService', function (Server $c) { + return new UserStoragesService( + $c->query('StoragesBackendService'), + $c->query('StoragesDBConfigService'), + $c->query('UserSession'), + $c->query('UserMountCache') + ); + }); + $this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService'); $this->registerService('ShareManager', function(Server $c) { $config = $c->getConfig(); $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); @@ -688,6 +761,8 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerService('ThemeService', function ($c) { return new ThemeService($this->getSystemConfig()->getValue('theme')); }); + $this->registerAlias('OCP\IUserSession', 'UserSession'); + $this->registerAlias('OCP\Security\ICrypto', 'Crypto'); } /** @@ -1326,39 +1401,31 @@ public function getContentSecurityPolicyManager() { } /** - * Not a public API as of 8.2, wait for 9.0 - * - * @return \OCA\Files_External\Service\BackendService + * @return \OCP\Files\External\IStoragesBackendService */ public function getStoragesBackendService() { - return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\BackendService'); + return $this->query('StoragesBackendService'); } /** - * Not a public API as of 8.2, wait for 9.0 - * - * @return \OCA\Files_External\Service\GlobalStoragesService + * @return \OCP\Files\External\Service\IGlobalStoragesService */ public function getGlobalStoragesService() { - return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\GlobalStoragesService'); + return $this->query('GlobalStoragesService'); } /** - * Not a public API as of 8.2, wait for 9.0 - * - * @return \OCA\Files_External\Service\UserGlobalStoragesService + * @return \OCP\Files\External\Service\IUserGlobalStoragesService */ public function getUserGlobalStoragesService() { - return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); + return $this->query('UserGlobalStoragesService'); } /** - * Not a public API as of 8.2, wait for 9.0 - * - * @return \OCA\Files_External\Service\UserStoragesService + * @return \OCP\Files\External\Service\IUserStoragesService */ public function getUserStoragesService() { - return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserStoragesService'); + return $this->query('UserStoragesService'); } /** diff --git a/apps/files_external/lib/Lib/Auth/AuthMechanism.php b/lib/public/Files/External/Auth/AuthMechanism.php similarity index 81% rename from apps/files_external/lib/Lib/Auth/AuthMechanism.php rename to lib/public/Files/External/Auth/AuthMechanism.php index db90eb93562b..4654236671c3 100644 --- a/apps/files_external/lib/Lib/Auth/AuthMechanism.php +++ b/lib/public/Files/External/Auth/AuthMechanism.php @@ -2,8 +2,9 @@ /** * @author Robin Appelman * @author Robin McCorkell + * @author Vincent Petry * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -20,13 +21,13 @@ * */ -namespace OCA\Files_External\Lib\Auth; +namespace OCP\Files\External\Auth; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\VisibilityTrait; -use \OCA\Files_External\Lib\IdentifierTrait; -use \OCA\Files_External\Lib\FrontendDefinitionTrait; -use \OCA\Files_External\Lib\StorageModifierTrait; +use OC\Files\External\VisibilityTrait; +use OC\Files\External\IdentifierTrait; +use OC\Files\External\FrontendDefinitionTrait; +use OC\Files\External\StorageModifierTrait; +use OCP\Files\External\IStorageConfig; /** * Authentication mechanism @@ -47,8 +48,10 @@ * Specify configuration parameters and other definitions * - StorageModifierTrait * Object can affect storage mounting + * + * @since 9.2.0 */ -class AuthMechanism implements \JsonSerializable { +abstract class AuthMechanism implements \JsonSerializable { /** Standard authentication schemes */ const SCHEME_NULL = 'null'; @@ -72,6 +75,7 @@ class AuthMechanism implements \JsonSerializable { * See self::SCHEME_* constants * * @return string + * @since 9.2.0 */ public function getScheme() { return $this->scheme; @@ -80,6 +84,7 @@ public function getScheme() { /** * @param string $scheme * @return self + * @since 9.2.0 */ public function setScheme($scheme) { $this->scheme = $scheme; @@ -90,6 +95,7 @@ public function setScheme($scheme) { * Serialize into JSON for client-side JS * * @return array + * @since 9.2.0 */ public function jsonSerialize() { $data = $this->jsonSerializeDefinition(); @@ -102,12 +108,13 @@ public function jsonSerialize() { } /** - * Check if parameters are satisfied in a StorageConfig + * Check if parameters are satisfied in a IStorageConfig * - * @param StorageConfig $storage + * @param IStorageConfig $storage * @return bool + * @since 9.2.0 */ - public function validateStorage(StorageConfig $storage) { + public function validateStorage(IStorageConfig $storage) { // does the backend actually support this scheme $supportedSchemes = $storage->getBackend()->getAuthSchemes(); if (!isset($supportedSchemes[$this->getScheme()])) { diff --git a/apps/files_external/lib/Lib/Auth/IUserProvided.php b/lib/public/Files/External/Auth/IUserProvided.php similarity index 90% rename from apps/files_external/lib/Lib/Auth/IUserProvided.php rename to lib/public/Files/External/Auth/IUserProvided.php index 9ad726e1fa96..fbb70c0941f1 100644 --- a/apps/files_external/lib/Lib/Auth/IUserProvided.php +++ b/lib/public/Files/External/Auth/IUserProvided.php @@ -2,7 +2,7 @@ /** * @author Robin Appelman * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -19,18 +19,21 @@ * */ -namespace OCA\Files_External\Lib\Auth; +namespace OCP\Files\External\Auth; use OCP\IUser; /** * For auth mechanisms where the user needs to provide credentials + * + * @since 9.2.0 */ interface IUserProvided { /** * @param IUser $user the user for which to save the user provided options * @param int $mountId the mount id to save the options for * @param array $options the user provided options + * @since 9.2.0 */ public function saveBackendOptions(IUser $user, $mountId, array $options); } diff --git a/lib/public/Files/External/Backend/Backend.php b/lib/public/Files/External/Backend/Backend.php new file mode 100644 index 000000000000..52ab8be48ab8 --- /dev/null +++ b/lib/public/Files/External/Backend/Backend.php @@ -0,0 +1,146 @@ + + * @author Vincent Petry + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ + +namespace OCP\Files\External\Backend; + +use OC\Files\External\VisibilityTrait; +use OC\Files\External\FrontendDefinitionTrait; +use OC\Files\External\PriorityTrait; +use OC\Files\External\DependencyTrait; +use OC\Files\External\StorageModifierTrait; +use OC\Files\External\IdentifierTrait; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\IStorageConfig; + +/** + * Storage backend + * + * A backend can have services injected during construction, + * such as \OCP\IDB for database operations. This allows a backend + * to perform advanced operations based on provided information. + * + * An authenication scheme defines the parameter interface, common to the + * storage implementation, the backend and the authentication mechanism. + * A storage implementation expects parameters according to the authentication + * scheme, which are provided from the authentication mechanism. + * + * This class uses the following traits: + * - VisibilityTrait + * Restrict usage to admin-only/none + * - FrontendDefinitionTrait + * Specify configuration parameters and other definitions + * - PriorityTrait + * Allow objects to prioritize over others with the same mountpoint + * - DependencyTrait + * The object requires certain dependencies to be met + * - StorageModifierTrait + * Object can affect storage mounting + * + * @since 9.2.0 + */ +abstract class Backend implements \JsonSerializable { + + use VisibilityTrait; + use FrontendDefinitionTrait; + use PriorityTrait; + use DependencyTrait; + use StorageModifierTrait; + use IdentifierTrait; + + /** @var string storage class */ + private $storageClass; + + /** @var array 'scheme' => true, supported authentication schemes */ + private $authSchemes = []; + + /** @var AuthMechanism|callable authentication mechanism fallback */ + private $legacyAuthMechanism; + + /** + * @return string + * @since 9.2.0 + */ + public function getStorageClass() { + return $this->storageClass; + } + + /** + * @param string $class + * @return self + * @since 9.2.0 + */ + public function setStorageClass($class) { + $this->storageClass = $class; + return $this; + } + + /** + * @return array + * @since 9.2.0 + */ + public function getAuthSchemes() { + if (empty($this->authSchemes)) { + return [AuthMechanism::SCHEME_NULL => true]; + } + return $this->authSchemes; + } + + /** + * @param string $scheme + * @return self + * @since 9.2.0 + */ + public function addAuthScheme($scheme) { + $this->authSchemes[$scheme] = true; + return $this; + } + + /** + * Serialize into JSON for client-side JS + * + * @return array + * @since 9.2.0 + */ + public function jsonSerialize() { + $data = $this->jsonSerializeDefinition(); + $data += $this->jsonSerializeIdentifier(); + + $data['backend'] = $data['name']; // legacy compat + $data['priority'] = $this->getPriority(); + $data['authSchemes'] = $this->getAuthSchemes(); + + return $data; + } + + /** + * Check if parameters are satisfied in a IStorageConfig + * + * @param IStorageConfig $storage + * @return bool + * @since 9.2.0 + */ + public function validateStorage(IStorageConfig $storage) { + return $this->validateStorageDefinition($storage); + } + +} + diff --git a/apps/files_external/lib/Lib/Config/IAuthMechanismProvider.php b/lib/public/Files/External/Config/IAuthMechanismProvider.php similarity index 81% rename from apps/files_external/lib/Lib/Config/IAuthMechanismProvider.php rename to lib/public/Files/External/Config/IAuthMechanismProvider.php index 2e73b5295818..2920a0c3cf47 100644 --- a/apps/files_external/lib/Lib/Config/IAuthMechanismProvider.php +++ b/lib/public/Files/External/Config/IAuthMechanismProvider.php @@ -1,8 +1,9 @@ + * @author Vincent Petry * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -19,13 +20,14 @@ * */ -namespace OCA\Files_External\Lib\Config; +namespace OCP\Files\External\Config; -use \OCA\Files_External\Lib\Auth\AuthMechanism; +use OCP\Files\External\Auth\AuthMechanism; /** * Provider of external storage auth mechanisms - * @since 9.1.0 + * + * @since 9.2.0 */ interface IAuthMechanismProvider { diff --git a/apps/files_external/lib/Lib/Config/IBackendProvider.php b/lib/public/Files/External/Config/IBackendProvider.php similarity index 81% rename from apps/files_external/lib/Lib/Config/IBackendProvider.php rename to lib/public/Files/External/Config/IBackendProvider.php index f6cc274ef878..abb278be057a 100644 --- a/apps/files_external/lib/Lib/Config/IBackendProvider.php +++ b/lib/public/Files/External/Config/IBackendProvider.php @@ -1,8 +1,9 @@ + * @author Vincent Petry * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -19,13 +20,14 @@ * */ -namespace OCA\Files_External\Lib\Config; +namespace OCP\Files\External\Config; -use \OCA\Files_External\Lib\Backend\Backend; +use OCP\Files\External\Backend\Backend; /** * Provider of external storage backends - * @since 9.1.0 + * + * @since 9.2.0 */ interface IBackendProvider { diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/lib/public/Files/External/DefinitionParameter.php similarity index 89% rename from apps/files_external/lib/Lib/DefinitionParameter.php rename to lib/public/Files/External/DefinitionParameter.php index e504da17ee57..a9e297c5e9b2 100644 --- a/apps/files_external/lib/Lib/DefinitionParameter.php +++ b/lib/public/Files/External/DefinitionParameter.php @@ -3,7 +3,7 @@ * @author Robin Appelman * @author Robin McCorkell * - * @copyright Copyright (c) 2016, ownCloud GmbH. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -20,10 +20,12 @@ * */ -namespace OCA\Files_External\Lib; +namespace OCP\Files\External; /** * Parameter for an external storage definition + * + * @since 9.2.0 */ class DefinitionParameter implements \JsonSerializable { @@ -53,6 +55,7 @@ class DefinitionParameter implements \JsonSerializable { /** * @param string $name * @param string $text + * @since 9.2.0 */ public function __construct($name, $text) { $this->name = $name; @@ -61,6 +64,7 @@ public function __construct($name, $text) { /** * @return string + * @since 9.2.0 */ public function getName() { return $this->name; @@ -68,6 +72,7 @@ public function getName() { /** * @return string + * @since 9.2.0 */ public function getText() { return $this->text; @@ -77,6 +82,7 @@ public function getText() { * Get value type * * @return int + * @since 9.2.0 */ public function getType() { return $this->type; @@ -87,6 +93,7 @@ public function getType() { * * @param int $type * @return self + * @since 9.2.0 */ public function setType($type) { $this->type = $type; @@ -95,6 +102,7 @@ public function setType($type) { /** * @return string + * @since 9.2.0 */ public function getTypeName() { switch ($this->type) { @@ -111,6 +119,7 @@ public function getTypeName() { /** * @return int + * @since 9.2.0 */ public function getFlags() { return $this->flags; @@ -119,6 +128,7 @@ public function getFlags() { /** * @param int $flags * @return self + * @since 9.2.0 */ public function setFlags($flags) { $this->flags = $flags; @@ -128,6 +138,7 @@ public function setFlags($flags) { /** * @param int $flag * @return self + * @since 9.2.0 */ public function setFlag($flag) { $this->flags |= $flag; @@ -137,6 +148,7 @@ public function setFlag($flag) { /** * @param int $flag * @return bool + * @since 9.2.0 */ public function isFlagSet($flag) { return (bool)($this->flags & $flag); @@ -146,6 +158,7 @@ public function isFlagSet($flag) { * Serialize into JSON for client-side JS * * @return string + * @since 9.2.0 */ public function jsonSerialize() { return [ @@ -155,6 +168,12 @@ public function jsonSerialize() { ]; } + /** + * Returns whether the parameter is optional + * + * @return bool true if optional, false otherwise + * @since 9.2.0 + */ public function isOptional() { return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED); } @@ -165,6 +184,7 @@ public function isOptional() { * * @param mixed $value Value to check * @return bool success + * @since 9.2.0 */ public function validateValue(&$value) { switch ($this->getType()) { diff --git a/lib/public/Files/External/IStorageConfig.php b/lib/public/Files/External/IStorageConfig.php new file mode 100644 index 000000000000..18650a288f3c --- /dev/null +++ b/lib/public/Files/External/IStorageConfig.php @@ -0,0 +1,258 @@ + + * @author Joas Schilling + * @author Lukas Reschke + * @author Robin Appelman + * @author Robin McCorkell + * @author Vincent Petry + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ + +namespace OCP\Files\External; + +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\Auth\AuthMechanism; +use OCP\Files\External\Auth\IUserProvided; + +/** + * External storage configuration + * + * @since 9.2.0 + */ +interface IStorageConfig extends \JsonSerializable { + const MOUNT_TYPE_ADMIN = 1; + const MOUNT_TYPE_PERSONAl = 2; + + const MOUNT_TYPE_GLOBAL = 'global'; + const MOUNT_TYPE_GROUP = 'group'; + const MOUNT_TYPE_USER = 'user'; + const MOUNT_TYPE_PERSONAL = 'personal'; + + /** + * Returns the configuration id + * + * @return int + * @since 9.2.0 + */ + public function getId(); + + /** + * Sets the configuration id + * + * @param int $id configuration id + * @since 9.2.0 + */ + public function setId($id); + + /** + * Returns mount point path relative to the user's + * "files" folder. + * + * @return string path + * @since 9.2.0 + */ + public function getMountPoint(); + + /** + * Sets mount point path relative to the user's + * "files" folder. + * The path will be normalized. + * + * @param string $mountPoint path + * @since 9.2.0 + */ + public function setMountPoint($mountPoint); + + /** + * @return Backend + * @since 9.2.0 + */ + public function getBackend(); + + /** + * @param Backend $backend + * @since 9.2.0 + */ + public function setBackend(Backend $backend); + + /** + * @return AuthMechanism + * @since 9.2.0 + */ + public function getAuthMechanism(); + + /** + * @param AuthMechanism $authMechanism + * @since 9.2.0 + */ + public function setAuthMechanism(AuthMechanism $authMechanism); + + /** + * Returns the external storage backend-specific options + * + * @return array backend options + * @since 9.2.0 + */ + public function getBackendOptions(); + + /** + * Sets the external storage backend-specific options + * + * @param array $backendOptions backend options + * @since 9.2.0 + */ + public function setBackendOptions($backendOptions); + + /** + * @param string $key + * @return mixed + * @since 9.2.0 + */ + public function getBackendOption($key); + + /** + * @param string $key + * @param mixed $value + * @since 9.2.0 + */ + public function setBackendOption($key, $value); + + /** + * Returns the mount priority + * + * @return int priority + * @since 9.2.0 + */ + public function getPriority(); + + /** + * Sets the mount priotity + * + * @param int $priority priority + * @since 9.2.0 + */ + public function setPriority($priority); + + /** + * Returns the users for which to mount this storage + * + * @return array applicable users + * @since 9.2.0 + */ + public function getApplicableUsers(); + + /** + * Sets the users for which to mount this storage + * + * @param array|null $applicableUsers applicable users + * @since 9.2.0 + */ + public function setApplicableUsers($applicableUsers); + + /** + * Returns the groups for which to mount this storage + * + * @return array applicable groups + * @since 9.2.0 + */ + public function getApplicableGroups(); + + /** + * Sets the groups for which to mount this storage + * + * @param array|null $applicableGroups applicable groups + * @since 9.2.0 + */ + public function setApplicableGroups($applicableGroups); + + /** + * Returns the mount-specific options + * + * @return array mount specific options + * @since 9.2.0 + */ + public function getMountOptions(); + + /** + * Sets the mount-specific options + * + * @param array $mountOptions applicable groups + * @since 9.2.0 + */ + public function setMountOptions($mountOptions); + + /** + * @param string $key + * @return mixed + * @since 9.2.0 + */ + public function getMountOption($key); + + /** + * @param string $key + * @param mixed $value + * @since 9.2.0 + */ + public function setMountOption($key, $value); + + /** + * Gets the storage status, whether the config worked last time + * + * @return int $status status + * @since 9.2.0 + */ + public function getStatus(); + + /** + * Gets the message describing the storage status + * + * @return string|null + * @since 9.2.0 + */ + public function getStatusMessage(); + + /** + * Sets the storage status, whether the config worked last time + * + * @param int $status status + * @param string|null $message optional message + * @since 9.2.0 + */ + public function setStatus($status, $message = null); + + /** + * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + * @since 9.2.0 + */ + public function getType(); + + /** + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + * @since 9.2.0 + */ + public function setType($type); + + /** + * Serialize config to JSON + * + * @return array + * @since 9.2.0 + */ + public function jsonSerialize(); +} diff --git a/lib/public/Files/External/IStoragesBackendService.php b/lib/public/Files/External/IStoragesBackendService.php new file mode 100644 index 000000000000..d49528371017 --- /dev/null +++ b/lib/public/Files/External/IStoragesBackendService.php @@ -0,0 +1,149 @@ + + * @author Robin McCorkell + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ + +namespace OCP\Files\External; + +use \OCP\IConfig; + +use \OCP\Files\External\Backend\Backend; +use \OCP\Files\External\Auth\AuthMechanism; +use \OCP\Files\External\Config\IBackendProvider; +use \OCP\Files\External\Config\IAuthMechanismProvider; + +/** + * Service to manage external storage backend definitions + * + * @since 9.2.0 + */ +interface IStoragesBackendService { + + /** Visibility constants for VisibilityTrait */ + const VISIBILITY_NONE = 0; + const VISIBILITY_PERSONAL = 1; + const VISIBILITY_ADMIN = 2; + //const VISIBILITY_ALIENS = 4; + + const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN + + /** Priority constants for PriorityTrait */ + const PRIORITY_DEFAULT = 100; + + /** + * Register a backend provider + * + * @since 9.1.0 + * @param IBackendProvider $provider + */ + public function registerBackendProvider(IBackendProvider $provider); + + /** + * Register an auth mechanism provider + * + * @since 9.1.0 + * @param IAuthMechanismProvider $provider + */ + public function registerAuthMechanismProvider(IAuthMechanismProvider $provider); + + /** + * Register a backend + * + * @deprecated 9.1.0 use registerBackendProvider() + * @param Backend $backend + */ + public function registerBackend(Backend $backend); + + /** + * @deprecated 9.1.0 use registerBackendProvider() + * @param Backend[] $backends + */ + public function registerBackends(array $backends); + + /** + * Register an authentication mechanism + * + * @deprecated 9.1.0 use registerAuthMechanismProvider() + * @param AuthMechanism $authMech + */ + public function registerAuthMechanism(AuthMechanism $authMech); + + /** + * @deprecated 9.1.0 use registerAuthMechanismProvider() + * @param AuthMechanism[] $mechanisms + */ + public function registerAuthMechanisms(array $mechanisms); + + /** + * Get all backends + * + * @return Backend[] + * @since 9.1.0 + */ + public function getBackends(); + + /** + * Get all available backends + * + * @return Backend[] + * @since 9.1.0 + */ + public function getAvailableBackends(); + + /** + * @param string $identifier + * @return Backend|null + * @since 9.1.0 + */ + public function getBackend($identifier); + + /** + * Get all authentication mechanisms + * + * @return AuthMechanism[] + * @since 9.1.0 + */ + public function getAuthMechanisms(); + + /** + * Get all authentication mechanisms for schemes + * + * @param string[] $schemes + * @return AuthMechanism[] + * @since 9.1.0 + */ + public function getAuthMechanismsByScheme(array $schemes); + + /** + * Get authentication mechanism by id + * + * @param string $identifier + * @return AuthMechanism|null + * @since 9.1.0 + */ + public function getAuthMechanism($identifier); + + /** + * Returns whether user mounting is allowed + * @return bool + * @since 9.1.0 + */ + public function isUserMountingAllowed(); +} diff --git a/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php b/lib/public/Files/External/InsufficientDataForMeaningfulAnswerException.php similarity index 96% rename from apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php rename to lib/public/Files/External/InsufficientDataForMeaningfulAnswerException.php index 2738972a5bfa..43660c18f96f 100644 --- a/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php +++ b/lib/public/Files/External/InsufficientDataForMeaningfulAnswerException.php @@ -20,12 +20,14 @@ * */ -namespace OCA\Files_External\Lib; +namespace OCP\Files\External; use \OCP\Files\StorageNotAvailableException; /** * Authentication mechanism or backend has insufficient data + * + * @since 9.2.0 */ class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException { /** diff --git a/apps/files_external/lib/NotFoundException.php b/lib/public/Files/External/NotFoundException.php similarity index 94% rename from apps/files_external/lib/NotFoundException.php rename to lib/public/Files/External/NotFoundException.php index b34914953761..c87c41e624d6 100644 --- a/apps/files_external/lib/NotFoundException.php +++ b/lib/public/Files/External/NotFoundException.php @@ -20,10 +20,12 @@ * */ -namespace OCA\Files_External; +namespace OCP\Files\External; /** * Storage is not found + * + * @since 9.2 */ class NotFoundException extends \Exception { } diff --git a/apps/files_external/lib/Migration/DummyUserSession.php b/lib/public/Files/External/Service/IGlobalStoragesService.php similarity index 58% rename from apps/files_external/lib/Migration/DummyUserSession.php rename to lib/public/Files/External/Service/IGlobalStoragesService.php index 8a5cd32639e8..764ce745baeb 100644 --- a/apps/files_external/lib/Migration/DummyUserSession.php +++ b/lib/public/Files/External/Service/IGlobalStoragesService.php @@ -1,7 +1,6 @@ - * @author Robin Appelman + * @author Vincent Petry * * @copyright Copyright (c) 2016, ownCloud GmbH. * @license AGPL-3.0 @@ -20,33 +19,20 @@ * */ -namespace OCA\Files_External\Migration; - -use OCP\IUser; -use OCP\IUserSession; - -class DummyUserSession implements IUserSession { +namespace OCP\Files\External\Service; +/** + * Service class to manage global external storages + * + * @since 9.2 + */ +interface IGlobalStoragesService extends IStoragesService { /** - * @var IUser + * Get all configured admin and personal mounts + * + * @return array map of storage id to storage config + * + * @since 9.2.0 */ - private $user; - - public function login($user, $password) { - } - - public function logout() { - } - - public function setUser($user) { - $this->user = $user; - } - - public function getUser() { - return $this->user; - } - - public function isLoggedIn() { - return !is_null($this->user); - } + public function getStorageForAllUsers(); } diff --git a/lib/public/Files/External/Service/IStoragesService.php b/lib/public/Files/External/Service/IStoragesService.php new file mode 100644 index 000000000000..ce3bfee8773c --- /dev/null +++ b/lib/public/Files/External/Service/IStoragesService.php @@ -0,0 +1,142 @@ + + * + * @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 + * + */ + +namespace OCP\Files\External\Service; + +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\NotFoundException; + +/** + * Service interface to manage external storages + * + * @since 9.2 + */ +interface IStoragesService { + /** + * Get a storage with status + * + * @param int $id storage mount numeric id + * + * @return IStorageConfig + * @throws NotFoundException if the storage with the given id was not found + * + * @since 9.2 + */ + public function getStorage($id); + + /** + * Gets all storages, valid or not + * + * @return IStorageConfig[] array of storage configs + * + * @since 9.2 + */ + public function getAllStorages(); + + /** + * Gets all valid storages + * + * @return IStorageConfig[] + * + * @since 9.2 + */ + public function getStorages(); + + /** + * Get the visibility type for this service, used in validation + * + * @return string IStoragesBackendService::VISIBILITY_* constants + * + * @since 9.2 + */ + public function getVisibilityType(); + + /** + * Creates a new storage configuration + * + * @return IStorageConfig + * + * @since 9.2.0 + */ + public function createConfig(); + + /** + * Add new storage to the configuration + * + * @param IStorageConfig $newStorage storage attributes + * + * @return IStorageConfig storage config, with added id + * + * @since 9.2.0 + */ + public function addStorage(IStorageConfig $newStorage); + + /** + * Create a storage from its parameters + * + * @param string $mountPoint storage mount point + * @param string $backendIdentifier backend identifier + * @param string $authMechanismIdentifier authentication mechanism identifier + * @param array $backendOptions backend-specific options + * @param array|null $mountOptions mount-specific options + * @param array|null $applicableUsers users for which to mount the storage + * @param array|null $applicableGroups groups for which to mount the storage + * @param int|null $priority priority + * + * @return IStorageConfig + * + * @since 9.2.0 + */ + public function createStorage( + $mountPoint, + $backendIdentifier, + $authMechanismIdentifier, + $backendOptions, + $mountOptions = null, + $applicableUsers = null, + $applicableGroups = null, + $priority = null + ); + + /** + * Update storage to the configuration + * + * @param IStorageConfig $updatedStorage storage attributes + * + * @return IStorageConfig storage config + * @throws NotFoundException if the given storage does not exist in the config + * + * @since 9.2.0 + */ + public function updateStorage(IStorageConfig $updatedStorage); + + /** + * Delete the storage with the given id. + * + * @param int $id storage id + * + * @throws NotFoundException if no storage was found with the given id + * + * @since 9.2.0 + */ + public function removeStorage($id); + +} diff --git a/apps/files_external/lib/Service/GlobalLegacyStoragesService.php b/lib/public/Files/External/Service/IUserGlobalStoragesService.php similarity index 58% rename from apps/files_external/lib/Service/GlobalLegacyStoragesService.php rename to lib/public/Files/External/Service/IUserGlobalStoragesService.php index 8f22d6bb498f..245d0c8829e9 100644 --- a/apps/files_external/lib/Service/GlobalLegacyStoragesService.php +++ b/lib/public/Files/External/Service/IUserGlobalStoragesService.php @@ -1,7 +1,7 @@ * @author Robin Appelman + * @author Robin McCorkell * * @copyright Copyright (c) 2016, ownCloud GmbH. * @license AGPL-3.0 @@ -20,26 +20,24 @@ * */ -namespace OCA\Files_External\Service; +namespace OCP\Files\External\Service; + +use OCP\Files\External\IStorageConfig; /** - * Read admin defined mounts from the legacy mount.json + * Service class to read global storages applicable to the user + * Read-only access available, attempting to write will throw DomainException + * + * @since 9.2 */ -class GlobalLegacyStoragesService extends LegacyStoragesService { - /** - * @param BackendService $backendService - */ - public function __construct(BackendService $backendService) { - $this->backendService = $backendService; - } - +interface IUserGlobalStoragesService extends IGlobalStoragesService { /** - * Read legacy config data + * Get unique storages, in case two are defined with the same mountpoint + * Higher priority storages take precedence + * + * @return IStorageConfig[] * - * @return array list of mount configs + * @since 9.2.0 */ - protected function readLegacyConfig() { - // read global config - return \OC_Mount_Config::readData(); - } + public function getUniqueStorages(); } diff --git a/apps/files_external/appinfo/update.php b/lib/public/Files/External/Service/IUserStoragesService.php similarity index 69% rename from apps/files_external/appinfo/update.php rename to lib/public/Files/External/Service/IUserStoragesService.php index 7458715cd1fb..a387c61e9fbf 100644 --- a/apps/files_external/appinfo/update.php +++ b/lib/public/Files/External/Service/IUserStoragesService.php @@ -2,6 +2,9 @@ /** * @author Joas Schilling * @author Robin Appelman + * @author Robin McCorkell + * @author Stefan Weil + * @author Vincent Petry * * @copyright Copyright (c) 2016, ownCloud GmbH. * @license AGPL-3.0 @@ -20,12 +23,14 @@ * */ -$installedVersion = \OC::$server->getConfig()->getAppValue('files_external', 'installed_version'); +namespace OCP\Files\External\Service; -$app = new \OCA\Files_External\AppInfo\Application(); +/** + * Service class to manage user external storages + * (aka personal storages) + * + * @since 9.2 + */ +interface IUserStoragesService extends IStoragesService { -// Migration to db config -if (version_compare($installedVersion, '0.5.0', '<')) { - $migrator = $app->getContainer()->query('OCA\Files_External\Migration\StorageMigrator'); - $migrator->migrateGlobal(); } diff --git a/settings/Controller/CertificateController.php b/settings/Controller/CertificateController.php index cb001bc1eb4f..148c7e7c5970 100644 --- a/settings/Controller/CertificateController.php +++ b/settings/Controller/CertificateController.php @@ -147,8 +147,8 @@ public function removePersonalRootCertificate($certificateIdentifier) { protected function isCertificateImportAllowed() { $externalStorageEnabled = $this->appManager->isEnabledForUser('files_external'); if ($externalStorageEnabled) { - /** @var \OCA\Files_External\Service\BackendService $backendService */ - $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService'); + /** @var \OCP\Files\External\IStoragesBackendService $backendService */ + $backendService = \OC::$server->query('StoragesBackendService'); if ($backendService->isUserMountingAllowed()) { return true; } diff --git a/settings/personal.php b/settings/personal.php index 4b4086cb7140..88e78e2f8115 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -137,8 +137,8 @@ $enableCertImport = false; $externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external'); if ($externalStorageEnabled) { - /** @var \OCA\Files_External\Service\BackendService $backendService */ - $backendService = \OC_Mount_Config::$app->getContainer()->query('\OCA\Files_External\Service\BackendService'); + /** @var \OCP\Files\External\IStoragesBackendService $backendService */ + $backendService = \OC::$server->query('StoragesBackendService'); $enableCertImport = $backendService->isUserMountingAllowed(); } diff --git a/apps/files_external/tests/Auth/AuthMechanismTest.php b/tests/lib/Files/External/Auth/AuthMechanismTest.php similarity index 85% rename from apps/files_external/tests/Auth/AuthMechanismTest.php rename to tests/lib/Files/External/Auth/AuthMechanismTest.php index d5149ccdb948..9c17f6eb6704 100644 --- a/apps/files_external/tests/Auth/AuthMechanismTest.php +++ b/tests/lib/Files/External/Auth/AuthMechanismTest.php @@ -19,12 +19,12 @@ * */ -namespace OCA\Files_External\Tests\Auth; +namespace Test\Files\External\Auth; class AuthMechanismTest extends \Test\TestCase { public function testJsonSerialization() { - $mechanism = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + $mechanism = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->setMethods(['jsonSerializeDefinition']) ->getMock(); $mechanism->expects($this->once()) @@ -51,7 +51,7 @@ public function validateStorageProvider() { * @dataProvider validateStorageProvider */ public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) { - $mechanism = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + $mechanism = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->setMethods(['validateStorageDefinition']) ->getMock(); $mechanism->expects($this->atMost(1)) @@ -60,14 +60,14 @@ public function testValidateStorage($expectedSuccess, $scheme, $definitionSucces $mechanism->setScheme($scheme); - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backend->expects($this->once()) ->method('getAuthSchemes') ->willReturn(['scheme' => true, 'foobar' => true]); - $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig') + $storageConfig = $this->getMockBuilder('\OCP\Files\External\IStorageConfig') ->disableOriginalConstructor() ->getMock(); $storageConfig->expects($this->once()) diff --git a/apps/files_external/tests/Backend/BackendTest.php b/tests/lib/Files/External/Backend/BackendTest.php similarity index 71% rename from apps/files_external/tests/Backend/BackendTest.php rename to tests/lib/Files/External/Backend/BackendTest.php index aa5fae72684e..279235d8e768 100644 --- a/apps/files_external/tests/Backend/BackendTest.php +++ b/tests/lib/Files/External/Backend/BackendTest.php @@ -19,14 +19,14 @@ * */ -namespace OCA\Files_External\Tests\Backend; +namespace Test\Files\External\Backend; -use \OCA\Files_External\Lib\Backend\Backend; +use \OCP\Files\External\Backend\Backend; class BackendTest extends \Test\TestCase { public function testJsonSerialization() { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->setMethods(['jsonSerializeDefinition']) ->getMock(); $backend->expects($this->once()) @@ -58,32 +58,17 @@ public function validateStorageProvider() { * @dataProvider validateStorageProvider */ public function testValidateStorage($expectedSuccess, $definitionSuccess) { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->setMethods(['validateStorageDefinition']) ->getMock(); $backend->expects($this->atMost(1)) ->method('validateStorageDefinition') ->willReturn($definitionSuccess); - $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig') + $storageConfig = $this->getMockBuilder('\OCP\Files\External\IStorageConfig') ->disableOriginalConstructor() ->getMock(); $this->assertEquals($expectedSuccess, $backend->validateStorage($storageConfig)); } - - public function testLegacyAuthMechanismCallback() { - $backend = new Backend(); - $backend->setLegacyAuthMechanismCallback(function(array $params) { - if (isset($params['ping'])) { - return 'pong'; - } - return 'foobar'; - }); - - $this->assertEquals('pong', $backend->getLegacyAuthMechanism(['ping' => true])); - $this->assertEquals('foobar', $backend->getLegacyAuthMechanism(['other' => true])); - $this->assertEquals('foobar', $backend->getLegacyAuthMechanism()); - } - } diff --git a/tests/lib/Files/External/Backend/DummyBackend.php b/tests/lib/Files/External/Backend/DummyBackend.php new file mode 100644 index 000000000000..e55bbc7a9579 --- /dev/null +++ b/tests/lib/Files/External/Backend/DummyBackend.php @@ -0,0 +1,44 @@ + + * + * @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 + * + */ + +namespace Test\Files\External\Backend; + +use OCP\Files\External\Backend\Backend; +use OCP\Files\External\DefinitionParameter; +use OCP\Files\External\Auth\AuthMechanism; + +class DummyBackend extends Backend { + + public function __construct() { + $this + ->setIdentifier('dummy') + ->addIdentifierAlias('\Test\Files\External\Backend\DummyBackend') // legacy compat + ->setStorageClass('\Test\Files\External\Backend\DummyStorage') + ->setText('Dummy') + ->addParameters([ + (new DefinitionParameter('param1', 'Param One')), + (new DefinitionParameter('param2', 'Param Two')) + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), + ]) + ->addAuthScheme(AuthMechanism::SCHEME_NULL) + ; + } +} diff --git a/apps/files_external/lib/Service/ImportLegacyStoragesService.php b/tests/lib/Files/External/Backend/DummyStorage.php similarity index 55% rename from apps/files_external/lib/Service/ImportLegacyStoragesService.php rename to tests/lib/Files/External/Backend/DummyStorage.php index 2feb12250556..cfaff1fc732a 100644 --- a/apps/files_external/lib/Service/ImportLegacyStoragesService.php +++ b/tests/lib/Files/External/Backend/DummyStorage.php @@ -1,7 +1,6 @@ - * @author Robin Appelman + * @author Vincent Petry * * @copyright Copyright (c) 2016, ownCloud GmbH. * @license AGPL-3.0 @@ -20,28 +19,19 @@ * */ -namespace OCA\Files_External\Service; +namespace Test\Files\External\Backend; -class ImportLegacyStoragesService extends LegacyStoragesService { - private $data; +use OC\Files\Storage\Temporary; - /** - * @param BackendService $backendService - */ - public function __construct(BackendService $backendService) { - $this->backendService = $backendService; - } +class DummyStorage extends Temporary { + private $args; - public function setData($data) { - $this->data = $data; + public function __construct($arguments = null) { + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); + $this->args = $arguments; } - /** - * Read legacy config data - * - * @return array list of mount configs - */ - protected function readLegacyConfig() { - return $this->data; + public function getId() { + return 'smb::' . $this->args['user'] . '@' . $this->args['host'] . '/' . $this->args['share'] . '/' . $this->args['root']; } } diff --git a/apps/files_external/tests/DefinitionParameterTest.php b/tests/lib/Files/External/DefinitionParameterTest.php similarity index 96% rename from apps/files_external/tests/DefinitionParameterTest.php rename to tests/lib/Files/External/DefinitionParameterTest.php index 38ab591757ff..a24a852dc8c8 100644 --- a/apps/files_external/tests/DefinitionParameterTest.php +++ b/tests/lib/Files/External/DefinitionParameterTest.php @@ -20,9 +20,9 @@ * */ -namespace OCA\Files_External\Tests; +namespace Test\Files\External; -use \OCA\Files_External\Lib\DefinitionParameter as Param; +use \OCP\Files\External\DefinitionParameter as Param; class DefinitionParameterTest extends \Test\TestCase { diff --git a/apps/files_external/tests/FrontendDefinitionTraitTest.php b/tests/lib/Files/External/FrontendDefinitionTraitTest.php similarity index 82% rename from apps/files_external/tests/FrontendDefinitionTraitTest.php rename to tests/lib/Files/External/FrontendDefinitionTraitTest.php index fde8b4e7393c..680c16cf112f 100644 --- a/apps/files_external/tests/FrontendDefinitionTraitTest.php +++ b/tests/lib/Files/External/FrontendDefinitionTraitTest.php @@ -20,17 +20,17 @@ * */ -namespace OCA\Files_External\Tests; +namespace Test\Files\External; class FrontendDefinitionTraitTest extends \Test\TestCase { public function testJsonSerialization() { - $param = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter') + $param = $this->getMockBuilder('\OCP\Files\External\DefinitionParameter') ->disableOriginalConstructor() ->getMock(); $param->method('getName')->willReturn('foo'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait('\OC\Files\External\FrontendDefinitionTrait'); $trait->setText('test'); $trait->addParameters([$param]); $trait->addCustomJs('foo/bar.js'); @@ -59,7 +59,7 @@ public function validateStorageProvider() { public function testValidateStorage($expectedSuccess, $params) { $backendParams = []; foreach ($params as $name => $valid) { - $param = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter') + $param = $this->getMockBuilder('\OCP\Files\External\DefinitionParameter') ->disableOriginalConstructor() ->getMock(); $param->method('getName') @@ -72,7 +72,7 @@ public function testValidateStorage($expectedSuccess, $params) { $backendParams[] = $param; } - $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig') + $storageConfig = $this->getMockBuilder('\OCP\Files\External\IStorageConfig') ->disableOriginalConstructor() ->getMock(); $storageConfig->expects($this->any()) @@ -81,7 +81,7 @@ public function testValidateStorage($expectedSuccess, $params) { $storageConfig->expects($this->any()) ->method('setBackendOption'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait('\OC\Files\External\FrontendDefinitionTrait'); $trait->setText('test'); $trait->addParameters($backendParams); @@ -89,7 +89,7 @@ public function testValidateStorage($expectedSuccess, $params) { } public function testValidateStorageSet() { - $param = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter') + $param = $this->getMockBuilder('\OCP\Files\External\DefinitionParameter') ->disableOriginalConstructor() ->getMock(); $param->method('getName') @@ -101,7 +101,7 @@ public function testValidateStorageSet() { return true; })); - $storageConfig = $this->getMockBuilder('\OCA\Files_External\Lib\StorageConfig') + $storageConfig = $this->getMockBuilder('\OCP\Files\External\IStorageConfig') ->disableOriginalConstructor() ->getMock(); $storageConfig->expects($this->once()) @@ -112,7 +112,7 @@ public function testValidateStorageSet() { ->method('setBackendOption') ->with('param', 'foobar'); - $trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait'); + $trait = $this->getMockForTrait('\OC\Files\External\FrontendDefinitionTrait'); $trait->setText('test'); $trait->addParameter($param); diff --git a/apps/files_external/tests/PersonalMountTest.php b/tests/lib/Files/External/PersonalMountTest.php similarity index 82% rename from apps/files_external/tests/PersonalMountTest.php rename to tests/lib/Files/External/PersonalMountTest.php index 263429c807b0..a1ef287b494a 100644 --- a/apps/files_external/tests/PersonalMountTest.php +++ b/tests/lib/Files/External/PersonalMountTest.php @@ -20,18 +20,16 @@ * */ -namespace OCA\Files_External\Tests; +namespace Test\Files\External; use OC\Files\Mount\Manager; -use OCA\Files_External\Lib\PersonalMount; +use OC\Files\External\PersonalMount; use Test\TestCase; class PersonalMountTest extends TestCase { public function testFindByStorageId() { - /** @var \OCA\Files_External\Service\UserStoragesService $storageService */ - $storageService = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService') - ->disableOriginalConstructor() - ->getMock(); + /** @var \OCP\Files\External\Service\IUserStoragesService $storageService */ + $storageService = $this->createMock('\OCP\Files\External\Service\IUserStoragesService'); $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() diff --git a/tests/lib/Files/External/Service/CleaningDBConfig.php b/tests/lib/Files/External/Service/CleaningDBConfig.php new file mode 100644 index 000000000000..e447e9327115 --- /dev/null +++ b/tests/lib/Files/External/Service/CleaningDBConfig.php @@ -0,0 +1,39 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ +namespace Test\Files\External\Service; + +use OC\Files\External\Service\DBConfigService; + +class CleaningDBConfig extends DBConfigService { + private $mountIds = []; + + public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { + $id = parent::addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); // TODO: Change the autogenerated stub + $this->mountIds[] = $id; + return $id; + } + + public function clean() { + foreach ($this->mountIds as $id) { + $this->removeMount($id); + } + } +} diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/tests/lib/Files/External/Service/DBConfigServiceTest.php similarity index 98% rename from apps/files_external/tests/Service/DBConfigServiceTest.php rename to tests/lib/Files/External/Service/DBConfigServiceTest.php index 23ebddd399f5..00fcb179cdc9 100644 --- a/apps/files_external/tests/Service/DBConfigServiceTest.php +++ b/tests/lib/Files/External/Service/DBConfigServiceTest.php @@ -20,10 +20,10 @@ * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External\Service; -use OCA\Files_External\Service\DBConfigService; +use OC\Files\External\Service\DBConfigService; use OCP\IDBConnection; use Test\TestCase; @@ -89,10 +89,14 @@ public function testAddApplicable() { $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); $mount = $this->dbConfig->getMountById($id); + usort($mount['applicable'], function($m1, $m2) { + return $m1['type'] - $m2['type']; + }); + $this->assertEquals([ - ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id], + ['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id], ['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id], - ['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id] + ['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id], ], $mount['applicable']); } diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/tests/lib/Files/External/Service/GlobalStoragesServiceTest.php similarity index 86% rename from apps/files_external/tests/Service/GlobalStoragesServiceTest.php rename to tests/lib/Files/External/Service/GlobalStoragesServiceTest.php index bdc2085a94d4..50672571675d 100644 --- a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php +++ b/tests/lib/Files/External/Service/GlobalStoragesServiceTest.php @@ -21,11 +21,11 @@ * along with this program. If not, see * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External\Service; use \OC\Files\Filesystem; - -use \OCA\Files_External\Service\GlobalStoragesService; +use \OC\Files\External\Service\GlobalStoragesService; +use OCP\Files\External\IStorageConfig; /** * @group DB @@ -44,7 +44,7 @@ public function tearDown() { protected function makeTestStorageData() { return $this->makeStorageConfig([ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -66,7 +66,7 @@ function storageDataProvider() { [ [ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -82,7 +82,7 @@ function storageDataProvider() { [ [ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -98,7 +98,7 @@ function storageDataProvider() { [ [ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -114,7 +114,7 @@ function storageDataProvider() { [ [ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -160,7 +160,7 @@ public function testUpdateStorage($updatedStorageParams) { $updatedStorage = $this->makeStorageConfig($updatedStorageParams); $storage = $this->makeStorageConfig([ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -198,7 +198,7 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'all' ], ], @@ -211,7 +211,7 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], ], @@ -224,7 +224,7 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1', ], ], @@ -236,12 +236,12 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], ], @@ -254,12 +254,12 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1' ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -272,22 +272,22 @@ function hooksAddStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1' ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -330,27 +330,27 @@ function hooksUpdateStorageDataProvider() { // delete the "all entry" [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'all', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1' ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -365,12 +365,12 @@ function hooksUpdateStorageDataProvider() { [ [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -385,12 +385,12 @@ function hooksUpdateStorageDataProvider() { [ [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -405,18 +405,18 @@ function hooksUpdateStorageDataProvider() { [ [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1' ], // create the "all" entry [ Filesystem::signal_create_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'all' ], ], @@ -489,50 +489,50 @@ public function testHooksRenameMountPoint() { [ Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1', ], [ Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2', ], // creates new one [ Filesystem::signal_create_mount, '/renamedMountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_create_mount, '/renamedMountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_create_mount, '/renamedMountpoint', - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1', ], [ Filesystem::signal_create_mount, '/renamedMountpoint', - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2', ], ]; @@ -559,22 +559,22 @@ function hooksDeleteStorageDataProvider() { [ [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user1', ], [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'user2', ], [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group1' ], [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_GROUP, + IStorageConfig::MOUNT_TYPE_GROUP, 'group2' ], ], @@ -586,7 +586,7 @@ function hooksDeleteStorageDataProvider() { [ [ Filesystem::signal_delete_mount, - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, 'all', ], ], diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/tests/lib/Files/External/Service/StoragesServiceTest.php similarity index 86% rename from apps/files_external/tests/Service/StoragesServiceTest.php rename to tests/lib/Files/External/Service/StoragesServiceTest.php index 2408ee33ceeb..71873aeb7c17 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/tests/lib/Files/External/Service/StoragesServiceTest.php @@ -21,43 +21,27 @@ * along with this program. If not, see * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External\Service; -use \OC\Files\Filesystem; +use OC\Files\Filesystem; +use OC\Files\External\StorageConfig; +use OC\Files\External\Service\StoragesService; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\BackendService; -use OCA\Files_External\Service\DBConfigService; -use OCA\Files_External\Service\StoragesService; - -class CleaningDBConfig extends DBConfigService { - private $mountIds = []; - - public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { - $id = parent::addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); // TODO: Change the autogenerated stub - $this->mountIds[] = $id; - return $id; - } - - public function clean() { - foreach ($this->mountIds as $id) { - $this->removeMount($id); - } - } -} +use OCP\Files\External\NotFoundException; +use OCP\Files\External\IStoragesBackendService; +use Test\TestCase; /** * @group DB */ -abstract class StoragesServiceTest extends \Test\TestCase { +abstract class StoragesServiceTest extends TestCase { /** * @var StoragesService */ protected $service; - /** @var BackendService */ + /** @var IStoragesBackendService */ protected $backendService; /** @@ -78,7 +62,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { protected static $hookCalls; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\OCP\Files\Config\IUserMountCache + * @var \PHPUnit_Framework_MockObject_MockObject | \OCP\Files\Config\IUserMountCache */ protected $mountCache; @@ -91,20 +75,19 @@ public function setUp() { 'datadirectory', \OC::$SERVERROOT . '/data/' ); - \OC_Mount_Config::$skipTest = true; $this->mountCache = $this->createMock('OCP\Files\Config\IUserMountCache'); - // prepare BackendService mock + // prepare IStoragesBackendService mock $this->backendService = - $this->getMockBuilder('\OCA\Files_External\Service\BackendService') + $this->getMockBuilder('\OCP\Files\External\IStoragesBackendService') ->disableOriginalConstructor() ->getMock(); $authMechanisms = [ 'identifier:\Auth\Mechanism' => $this->getAuthMechMock('null', '\Auth\Mechanism'), 'identifier:\Other\Auth\Mechanism' => $this->getAuthMechMock('null', '\Other\Auth\Mechanism'), - 'identifier:\OCA\Files_External\Lib\Auth\NullMechanism' => $this->getAuthMechMock(), + 'identifier:\OC\Files\External\Auth\NullMechanism' => $this->getAuthMechMock(), ]; $this->backendService->method('getAuthMechanism') ->will($this->returnCallback(function ($class) use ($authMechanisms) { @@ -123,13 +106,13 @@ public function setUp() { ->will($this->returnValue($authMechanisms)); $sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OCA\Files_External\Lib\Storage\SFTP'); + $dummyBackend = $this->getBackendMock('\Test\Files\External\Backend\DummyBackend', '\Test\Files\External\Backend\DummyStorage'); $backends = [ 'identifier:\OCA\Files_External\Lib\Backend\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OCA\Files_External\Lib\Storage\SMB'), 'identifier:\OCA\Files_External\Lib\Backend\SFTP' => $sftpBackend, + 'identifier:\Test\Files\External\Backend\DummyBackend' => $dummyBackend, 'identifier:sftp_alias' => $sftpBackend, ]; - $backends['identifier:\OCA\Files_External\Lib\Backend\SFTP']->method('getLegacyAuthMechanism') - ->willReturn($authMechanisms['identifier:\Other\Auth\Mechanism']); $this->backendService->method('getBackend') ->will($this->returnCallback(function ($backendClass) use ($backends) { if (isset($backends[$backendClass])) { @@ -152,20 +135,13 @@ public function setUp() { $containerMock = $this->createMock('\OCP\AppFramework\IAppContainer'); $containerMock->method('query') ->will($this->returnCallback(function ($name) { - if ($name === 'OCA\Files_External\Service\BackendService') { + if ($name === 'OCP\Files\External\IStoragesBackendService') { return $this->backendService; } })); - - \OC_Mount_Config::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application') - ->disableOriginalConstructor() - ->getMock(); - \OC_Mount_Config::$app->method('getContainer') - ->willReturn($containerMock); } public function tearDown() { - \OC_Mount_Config::$skipTest = false; self::$hookCalls = []; if ($this->dbConfig) { $this->dbConfig->clean(); @@ -173,24 +149,28 @@ public function tearDown() { } protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backend->method('getStorageClass') ->willReturn($storageClass); $backend->method('getIdentifier') ->willReturn('identifier:' . $class); + $backend->method('wrapStorage') + ->will($this->returnArgument(0)); return $backend; } - protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') { - $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + protected function getAuthMechMock($scheme = 'null', $class = '\OC\Files\External\Auth\NullMechanism') { + $authMech = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->disableOriginalConstructor() ->getMock(); $authMech->method('getScheme') ->willReturn($scheme); $authMech->method('getIdentifier') ->willReturn('identifier:' . $class); + $authMech->method('wrapStorage') + ->will($this->returnArgument(0)); return $authMech; } @@ -198,7 +178,7 @@ protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_Extern /** * Creates a StorageConfig instance based on array data * - * @param array data + * @param array $data * * @return StorageConfig storage config instance */ @@ -242,7 +222,7 @@ protected function makeStorageConfig($data) { /** - * @expectedException \OCA\Files_External\NotFoundException + * @expectedException \OCP\Files\External\NotFoundException */ public function testNonExistingStorage() { $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); @@ -265,7 +245,7 @@ public function deleteStorageDataProvider() { 'password' => 'testPassword', 'root' => 'someroot', ], - 'smb::test@example.com//share//someroot/', + 'smb::test@example.com/share/someroot', 0 ], // special case with $user vars, cannot auto-remove the oc_storages entry @@ -277,7 +257,7 @@ public function deleteStorageDataProvider() { 'password' => 'testPassword', 'root' => 'someroot', ], - 'smb::someone@example.com//share//someroot/', + 'smb::someone@example.com/share/someroot', 1 ], ]; @@ -287,7 +267,7 @@ public function deleteStorageDataProvider() { * @dataProvider deleteStorageDataProvider */ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); $storage->setMountPoint('mountpoint'); @@ -325,7 +305,7 @@ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCou } /** - * @expectedException \OCA\Files_External\NotFoundException + * @expectedException \OCP\Files\External\NotFoundException */ public function testDeleteUnexistingStorage() { $this->service->removeStorage(255); @@ -476,7 +456,7 @@ protected function assertHookCall($callData, $signal, $mountPath, $mountType, $a } public function testUpdateStorageMountPoint() { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(); diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/tests/lib/Files/External/Service/UserGlobalStoragesServiceTest.php similarity index 91% rename from apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php rename to tests/lib/Files/External/Service/UserGlobalStoragesServiceTest.php index a1769d12717b..2f4d3f475db1 100644 --- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php +++ b/tests/lib/Files/External/Service/UserGlobalStoragesServiceTest.php @@ -21,13 +21,17 @@ * along with this program. If not, see * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External\Service; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\NotFoundException; -use OCA\Files_External\Service\StoragesService; -use OCA\Files_External\Service\UserGlobalStoragesService; +use OC\Files\External\StorageConfig; +use OC\Files\External\Service\StoragesService; +use OC\Files\External\Service\UserGlobalStoragesService; +use OCP\Files\External\Service\IStoragesService; +use OCP\Files\External\Service\IUserGlobalStoragesService; + +use OCP\Files\External\NotFoundException; use OCP\IUser; + use Test\Traits\UserTrait; /** @@ -40,12 +44,12 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { protected $groupManager; /** - * @var StoragesService + * @var IStoragesService */ protected $globalStoragesService; /** - * @var UserGlobalStoragesService + * @var IUserGlobalStoragesService */ protected $service; @@ -122,7 +126,7 @@ public function applicableStorageProvider() { * @dataProvider applicableStorageProvider */ public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(); @@ -157,7 +161,7 @@ public function testGetStorageWithApplicable($applicableUsers, $applicableGroups * @expectedException \DomainException */ public function testAddStorage($storageParams = null) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); @@ -173,7 +177,7 @@ public function testAddStorage($storageParams = null) { * @expectedException \DomainException */ public function testUpdateStorage($storageParams = null) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); @@ -201,7 +205,7 @@ public function testNonExistingStorage() { * @dataProvider deleteStorageDataProvider */ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); @@ -259,7 +263,7 @@ public function testGetUniqueStorages( $priority2, $applicableUsers2, $applicableGroups2, $expectedPrecedence ) { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $backend->method('isVisibleFor') ->willReturn(true); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/tests/lib/Files/External/Service/UserStoragesServiceTest.php similarity index 85% rename from apps/files_external/tests/Service/UserStoragesServiceTest.php rename to tests/lib/Files/External/Service/UserStoragesServiceTest.php index e0405ab245d1..ffca37e78f57 100644 --- a/apps/files_external/tests/Service/UserStoragesServiceTest.php +++ b/tests/lib/Files/External/Service/UserStoragesServiceTest.php @@ -21,15 +21,17 @@ * along with this program. If not, see * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External\Service; -use \OC\Files\Filesystem; +use OC\Files\Filesystem; -use OCA\Files_External\Service\GlobalStoragesService; -use OCA\Files_External\Service\StoragesService; -use OCA\Files_External\Service\UserStoragesService; -use OCA\Files_External\Lib\StorageConfig; +use OC\Files\External\Service\GlobalStoragesService; +use OC\Files\External\Service\StoragesService; +use OC\Files\External\Service\UserStoragesService; +use OC\Files\External\StorageConfig; use Test\Traits\UserTrait; +use OCP\Files\External\IStorageConfig; +use OCP\Files\External\Service\IStoragesService; /** * @group DB @@ -42,7 +44,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { private $userId; /** - * @var StoragesService + * @var IStoragesService */ protected $globalStoragesService; @@ -68,7 +70,7 @@ public function setUp() { private function makeTestStorageData() { return $this->makeStorageConfig([ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -101,7 +103,7 @@ public function testAddStorage() { current(self::$hookCalls), Filesystem::signal_create_mount, $storage->getMountPoint(), - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $this->userId ); @@ -112,7 +114,7 @@ public function testAddStorage() { public function testUpdateStorage() { $storage = $this->makeStorageConfig([ 'mountPoint' => 'mountpoint', - 'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB', + 'backendIdentifier' => 'identifier:\Test\Files\External\Backend\DummyBackend', 'authMechanismIdentifier' => 'identifier:\Auth\Mechanism', 'backendOptions' => [ 'option1' => 'value1', @@ -152,7 +154,7 @@ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCou self::$hookCalls[1], Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $this->userId ); } @@ -173,23 +175,23 @@ public function testHooksRenameMountPoint() { self::$hookCalls[0], Filesystem::signal_delete_mount, '/mountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $this->userId ); $this->assertHookCall( self::$hookCalls[1], Filesystem::signal_create_mount, '/renamedMountpoint', - \OC_Mount_Config::MOUNT_TYPE_USER, + IStorageConfig::MOUNT_TYPE_USER, $this->userId ); } /** - * @expectedException \OCA\Files_External\NotFoundException + * @expectedException \OCP\Files\External\NotFoundException */ public function testGetAdminStorage() { - $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); + $backend = $this->backendService->getBackend('identifier:\Test\Files\External\Backend\DummyBackend'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(); @@ -201,7 +203,7 @@ public function testGetAdminStorage() { $newStorage = $this->globalStoragesService->addStorage($storage); - $this->assertInstanceOf('\OCA\Files_External\Lib\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId())); + $this->assertInstanceOf('\OC\Files\External\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId())); $this->service->getStorage($newStorage->getId()); } diff --git a/apps/files_external/tests/StorageConfigTest.php b/tests/lib/Files/External/StorageConfigTest.php similarity index 89% rename from apps/files_external/tests/StorageConfigTest.php rename to tests/lib/Files/External/StorageConfigTest.php index 48affdd57c50..5e3c26e64619 100644 --- a/apps/files_external/tests/StorageConfigTest.php +++ b/tests/lib/Files/External/StorageConfigTest.php @@ -22,17 +22,17 @@ * */ -namespace OCA\Files_External\Tests; +namespace Test\Files\External; -use OCA\Files_External\Lib\StorageConfig; +use OC\Files\External\StorageConfig; class StorageConfigTest extends \Test\TestCase { public function testJsonSerialization() { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); - $parameter = $this->getMockBuilder('\OCA\Files_External\Lib\DefinitionParameter') + $parameter = $this->getMockBuilder('\OCP\Files\External\DefinitionParameter') ->disableOriginalConstructor() ->getMock(); $parameter @@ -46,7 +46,7 @@ public function testJsonSerialization() { $backend->method('getIdentifier') ->willReturn('storage::identifier'); - $authMech = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + $authMech = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->disableOriginalConstructor() ->getMock(); $authMech->method('getIdentifier') diff --git a/apps/files_external/tests/Service/BackendServiceTest.php b/tests/lib/Files/External/StoragesBackendServiceTest.php similarity index 80% rename from apps/files_external/tests/Service/BackendServiceTest.php rename to tests/lib/Files/External/StoragesBackendServiceTest.php index e204db72a695..1f799fd1cc83 100644 --- a/apps/files_external/tests/Service/BackendServiceTest.php +++ b/tests/lib/Files/External/StoragesBackendServiceTest.php @@ -18,30 +18,27 @@ * along with this program. If not, see * */ -namespace OCA\Files_External\Tests\Service; +namespace Test\Files\External; -use \OCA\Files_External\Service\BackendService; +use OCP\Files\External\IStoragesBackendService; +use OC\Files\External\StoragesBackendService; -class BackendServiceTest extends \Test\TestCase { +class StoragesBackendServiceTest extends \Test\TestCase { /** @var \OCP\IConfig */ protected $config; - /** @var \OCP\IL10N */ - protected $l10n; - protected function setUp() { $this->config = $this->createMock('\OCP\IConfig'); - $this->l10n = $this->createMock('\OCP\IL10N'); } /** * @param string $class * - * @return \OCA\Files_External\Lib\Backend\Backend + * @return \OCP\Files\External\Backend\Backend */ protected function getBackendMock($class) { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backend->method('getIdentifier')->will($this->returnValue('identifier:'.$class)); @@ -52,10 +49,10 @@ protected function getBackendMock($class) { /** * @param string $class * - * @return \OCA\Files_External\Lib\Auth\AuthMechanism + * @return \OCP\Files\External\Auth\AuthMechanism */ protected function getAuthMechanismMock($class) { - $backend = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\AuthMechanism') + $backend = $this->getMockBuilder('\OCP\Files\External\Auth\AuthMechanism') ->disableOriginalConstructor() ->getMock(); $backend->method('getIdentifier')->will($this->returnValue('identifier:'.$class)); @@ -64,11 +61,11 @@ protected function getAuthMechanismMock($class) { } public function testRegisterBackend() { - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backend = $this->getBackendMock('\Foo\Bar'); - $backendAlias = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backendAlias = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backendAlias->method('getIdentifierAliases') @@ -91,12 +88,12 @@ public function testRegisterBackend() { } public function testBackendProvider() { - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backend1 = $this->getBackendMock('\Foo\Bar'); $backend2 = $this->getBackendMock('\Bar\Foo'); - $providerMock = $this->createMock('\OCA\Files_External\Lib\Config\IBackendProvider'); + $providerMock = $this->createMock('\OCP\Files\External\Config\IBackendProvider'); $providerMock->expects($this->once()) ->method('getBackends') ->willReturn([$backend1, $backend2]); @@ -109,12 +106,12 @@ public function testBackendProvider() { } public function testAuthMechanismProvider() { - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backend1 = $this->getAuthMechanismMock('\Foo\Bar'); $backend2 = $this->getAuthMechanismMock('\Bar\Foo'); - $providerMock = $this->createMock('\OCA\Files_External\Lib\Config\IAuthMechanismProvider'); + $providerMock = $this->createMock('\OCP\Files\External\Config\IAuthMechanismProvider'); $providerMock->expects($this->once()) ->method('getAuthMechanisms') ->willReturn([$backend1, $backend2]); @@ -127,19 +124,19 @@ public function testAuthMechanismProvider() { } public function testMultipleBackendProviders() { - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backend1a = $this->getBackendMock('\Foo\Bar'); $backend1b = $this->getBackendMock('\Bar\Foo'); $backend2 = $this->getBackendMock('\Dead\Beef'); - $provider1Mock = $this->createMock('\OCA\Files_External\Lib\Config\IBackendProvider'); + $provider1Mock = $this->createMock('\OCP\Files\External\Config\IBackendProvider'); $provider1Mock->expects($this->once()) ->method('getBackends') ->willReturn([$backend1a, $backend1b]); $service->registerBackendProvider($provider1Mock); - $provider2Mock = $this->createMock('\OCA\Files_External\Lib\Config\IBackendProvider'); + $provider2Mock = $this->createMock('\OCP\Files\External\Config\IBackendProvider'); $provider2Mock->expects($this->once()) ->method('getBackends') ->willReturn([$backend2]); @@ -160,7 +157,7 @@ public function testUserMountingBackends() { ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias'] ])); - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backendAllowed = $this->getBackendMock('\User\Mount\Allowed'); $backendAllowed->expects($this->never()) @@ -168,9 +165,9 @@ public function testUserMountingBackends() { $backendNotAllowed = $this->getBackendMock('\User\Mount\NotAllowed'); $backendNotAllowed->expects($this->once()) ->method('removeVisibility') - ->with(BackendService::VISIBILITY_PERSONAL); + ->with(IStoragesBackendService::VISIBILITY_PERSONAL); - $backendAlias = $this->getMockBuilder('\OCA\Files_External\Lib\Backend\Backend') + $backendAlias = $this->getMockBuilder('\OCP\Files\External\Backend\Backend') ->disableOriginalConstructor() ->getMock(); $backendAlias->method('getIdentifierAliases') @@ -184,7 +181,7 @@ public function testUserMountingBackends() { } public function testGetAvailableBackends() { - $service = new BackendService($this->config, $this->l10n); + $service = new StoragesBackendService($this->config); $backendAvailable = $this->getBackendMock('\Backend\Available'); $backendAvailable->expects($this->once()) @@ -194,7 +191,7 @@ public function testGetAvailableBackends() { $backendNotAvailable->expects($this->once()) ->method('checkDependencies') ->will($this->returnValue([ - $this->getMockBuilder('\OCA\Files_External\Lib\MissingDependency') + $this->getMockBuilder('\OC\Files\External\MissingDependency') ->disableOriginalConstructor() ->getMock() ]));