From f14dff680d5e1e0fe10065ed25c524d9b5078cae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 May 2016 11:56:47 +0200 Subject: Move remaining classes to PSR-4 --- apps/files_external/lib/Command/Applicable.php | 4 +- apps/files_external/lib/Command/Config.php | 4 +- apps/files_external/lib/Command/Create.php | 2 +- apps/files_external/lib/Command/Delete.php | 2 +- apps/files_external/lib/Command/Import.php | 2 +- apps/files_external/lib/Command/ListCommand.php | 2 +- apps/files_external/lib/Command/Option.php | 2 +- apps/files_external/lib/Command/Verify.php | 4 +- .../lib/Controller/GlobalStoragesController.php | 2 +- .../lib/Controller/StoragesController.php | 4 +- .../Controller/UserGlobalStoragesController.php | 4 +- .../lib/Controller/UserStoragesController.php | 4 +- apps/files_external/lib/Lib/Api.php | 87 +++++ apps/files_external/lib/Lib/Auth/Builtin.php | 2 - apps/files_external/lib/Lib/Auth/NullMechanism.php | 1 - .../files_external/lib/Lib/DefinitionParameter.php | 193 +++++++++ apps/files_external/lib/Lib/DependencyTrait.php | 41 ++ .../lib/Lib/FrontendDefinitionTrait.php | 158 ++++++++ apps/files_external/lib/Lib/IdentifierTrait.php | 102 +++++ ...nsufficientDataForMeaningfulAnswerException.php | 42 ++ .../lib/Lib/LegacyDependencyCheckPolyfill.php | 70 ++++ apps/files_external/lib/Lib/MissingDependency.php | 64 +++ apps/files_external/lib/Lib/PersonalMount.php | 88 +++++ apps/files_external/lib/Lib/PriorityTrait.php | 60 +++ .../lib/Lib/SessionStorageWrapper.php | 43 +++ apps/files_external/lib/Lib/StorageConfig.php | 430 +++++++++++++++++++++ .../lib/Lib/StorageModifierTrait.php | 69 ++++ apps/files_external/lib/Lib/VisibilityTrait.php | 136 +++++++ apps/files_external/lib/NotFoundException.php | 28 ++ .../lib/Service/GlobalStoragesService.php | 6 +- .../lib/Service/LegacyStoragesService.php | 2 +- .../files_external/lib/Service/StoragesService.php | 4 +- .../lib/Service/UserStoragesService.php | 4 +- apps/files_external/lib/api.php | 87 ----- apps/files_external/lib/config.php | 4 +- apps/files_external/lib/definitionparameter.php | 193 --------- apps/files_external/lib/dependencytrait.php | 41 -- .../files_external/lib/frontenddefinitiontrait.php | 158 -------- apps/files_external/lib/identifiertrait.php | 102 ----- ...nsufficientdataformeaningfulanswerexception.php | 42 -- .../lib/legacydependencycheckpolyfill.php | 70 ---- apps/files_external/lib/missingdependency.php | 64 --- apps/files_external/lib/notfoundexception.php | 28 -- apps/files_external/lib/personalmount.php | 88 ----- apps/files_external/lib/prioritytrait.php | 60 --- apps/files_external/lib/sessionstoragewrapper.php | 43 --- apps/files_external/lib/storageconfig.php | 430 --------------------- apps/files_external/lib/storagemodifiertrait.php | 69 ---- apps/files_external/lib/visibilitytrait.php | 136 ------- 49 files changed, 1638 insertions(+), 1643 deletions(-) create mode 100644 apps/files_external/lib/Lib/Api.php create mode 100644 apps/files_external/lib/Lib/DefinitionParameter.php create mode 100644 apps/files_external/lib/Lib/DependencyTrait.php create mode 100644 apps/files_external/lib/Lib/FrontendDefinitionTrait.php create mode 100644 apps/files_external/lib/Lib/IdentifierTrait.php create mode 100644 apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php create mode 100644 apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php create mode 100644 apps/files_external/lib/Lib/MissingDependency.php create mode 100644 apps/files_external/lib/Lib/PersonalMount.php create mode 100644 apps/files_external/lib/Lib/PriorityTrait.php create mode 100644 apps/files_external/lib/Lib/SessionStorageWrapper.php create mode 100644 apps/files_external/lib/Lib/StorageConfig.php create mode 100644 apps/files_external/lib/Lib/StorageModifierTrait.php create mode 100644 apps/files_external/lib/Lib/VisibilityTrait.php create mode 100644 apps/files_external/lib/NotFoundException.php delete mode 100644 apps/files_external/lib/api.php delete mode 100644 apps/files_external/lib/definitionparameter.php delete mode 100644 apps/files_external/lib/dependencytrait.php delete mode 100644 apps/files_external/lib/frontenddefinitiontrait.php delete mode 100644 apps/files_external/lib/identifiertrait.php delete mode 100644 apps/files_external/lib/insufficientdataformeaningfulanswerexception.php delete mode 100644 apps/files_external/lib/legacydependencycheckpolyfill.php delete mode 100644 apps/files_external/lib/missingdependency.php delete mode 100644 apps/files_external/lib/notfoundexception.php delete mode 100644 apps/files_external/lib/personalmount.php delete mode 100644 apps/files_external/lib/prioritytrait.php delete mode 100644 apps/files_external/lib/sessionstoragewrapper.php delete mode 100644 apps/files_external/lib/storageconfig.php delete mode 100644 apps/files_external/lib/storagemodifiertrait.php delete mode 100644 apps/files_external/lib/visibilitytrait.php (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/Command/Applicable.php b/apps/files_external/lib/Command/Applicable.php index 902e76cb4cb..4e178edbbae 100644 --- a/apps/files_external/lib/Command/Applicable.php +++ b/apps/files_external/lib/Command/Applicable.php @@ -22,8 +22,8 @@ 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\Lib\StorageConfig; +use OCA\Files_External\NotFoundException; use OCA\Files_External\Service\GlobalStoragesService; use OCP\IGroupManager; use OCP\IUserManager; diff --git a/apps/files_external/lib/Command/Config.php b/apps/files_external/lib/Command/Config.php index 873fece86d7..909b130f17b 100644 --- a/apps/files_external/lib/Command/Config.php +++ b/apps/files_external/lib/Command/Config.php @@ -22,8 +22,8 @@ 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\Lib\StorageConfig; +use OCA\Files_External\NotFoundException; use OCA\Files_External\Service\GlobalStoragesService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; diff --git a/apps/files_external/lib/Command/Create.php b/apps/files_external/lib/Command/Create.php index 17ad7ef1a16..e5fd095d6f2 100644 --- a/apps/files_external/lib/Command/Create.php +++ b/apps/files_external/lib/Command/Create.php @@ -27,7 +27,7 @@ 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\Lib\StorageConfig; use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; diff --git a/apps/files_external/lib/Command/Delete.php b/apps/files_external/lib/Command/Delete.php index a3aef7f3303..64228b2033b 100644 --- a/apps/files_external/lib/Command/Delete.php +++ b/apps/files_external/lib/Command/Delete.php @@ -22,7 +22,7 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; -use OCA\Files_external\NotFoundException; +use OCA\Files_External\NotFoundException; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\IUserManager; diff --git a/apps/files_external/lib/Command/Import.php b/apps/files_external/lib/Command/Import.php index 55528b66472..4f881acb500 100644 --- a/apps/files_external/lib/Command/Import.php +++ b/apps/files_external/lib/Command/Import.php @@ -23,7 +23,7 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; use OC\User\NoUserException; -use OCA\Files_external\Lib\StorageConfig; +use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\ImportLegacyStoragesService; diff --git a/apps/files_external/lib/Command/ListCommand.php b/apps/files_external/lib/Command/ListCommand.php index cbe1913ccfc..c1fb18b3bc2 100644 --- a/apps/files_external/lib/Command/ListCommand.php +++ b/apps/files_external/lib/Command/ListCommand.php @@ -23,7 +23,7 @@ namespace OCA\Files_External\Command; use OC\Core\Command\Base; use OC\User\NoUserException; -use OCA\Files_external\Lib\StorageConfig; +use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\IUserManager; diff --git a/apps/files_external/lib/Command/Option.php b/apps/files_external/lib/Command/Option.php index 109ca26c31f..4f7733b25d8 100644 --- a/apps/files_external/lib/Command/Option.php +++ b/apps/files_external/lib/Command/Option.php @@ -21,7 +21,7 @@ namespace OCA\Files_External\Command; -use OCA\Files_external\Lib\StorageConfig; +use OCA\Files_External\Lib\StorageConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; diff --git a/apps/files_external/lib/Command/Verify.php b/apps/files_external/lib/Command/Verify.php index 6ff871a6094..dfc536530bb 100644 --- a/apps/files_external/lib/Command/Verify.php +++ b/apps/files_external/lib/Command/Verify.php @@ -25,8 +25,8 @@ 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\Lib\StorageConfig; +use OCA\Files_External\NotFoundException; use OCA\Files_External\Service\GlobalStoragesService; use OCP\Files\StorageNotAvailableException; use Symfony\Component\Console\Input\InputArgument; diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index 2471ac861de..0ae9e1fd5e0 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -30,7 +30,7 @@ use \OCP\IL10N; use \OCP\AppFramework\Http\DataResponse; use \OCP\AppFramework\Http; use OCA\Files_External\Service\GlobalStoragesService; -use \OCA\Files_external\NotFoundException; +use OCA\Files_External\NotFoundException; /** * Global storages controller diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index da26f24b6b8..a368169944e 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -32,8 +32,8 @@ 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\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; diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index c420d9ad59f..ee4cd640018 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -31,8 +31,8 @@ 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\NotFoundException; +use OCA\Files_External\Lib\StorageConfig; use \OCA\Files_External\Lib\Backend\Backend; use OCP\IUserSession; diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index e20a41e0cc4..1850d0087b3 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -32,8 +32,8 @@ 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\NotFoundException; +use OCA\Files_External\Lib\StorageConfig; use \OCA\Files_External\Lib\Backend\Backend; /** diff --git a/apps/files_external/lib/Lib/Api.php b/apps/files_external/lib/Lib/Api.php new file mode 100644 index 00000000000..589317dcf98 --- /dev/null +++ b/apps/files_external/lib/Lib/Api.php @@ -0,0 +1,87 @@ + + * @author Joas Schilling + * @author Morris Jobke + * @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 OCA\Files_External\Lib; + +class Api { + + /** + * Formats the given mount config to a mount entry. + * + * @param string $mountPoint mount point name, relative to the data dir + * @param array $mountConfig mount config to format + * + * @return array entry + */ + private static function formatMount($mountPoint, $mountConfig) { + // strip "/$user/files" from mount point + $mountPoint = explode('/', trim($mountPoint, '/'), 3); + $mountPoint = $mountPoint[2]; + + // split path from mount point + $path = dirname($mountPoint); + if ($path === '.') { + $path = ''; + } + + $isSystemMount = !$mountConfig['personal']; + + $permissions = \OCP\Constants::PERMISSION_READ; + // personal mounts can be deleted + if (!$isSystemMount) { + $permissions |= \OCP\Constants::PERMISSION_DELETE; + } + + $entry = array( + 'name' => basename($mountPoint), + 'path' => $path, + 'type' => 'dir', + 'backend' => $mountConfig['backend'], + 'scope' => ( $isSystemMount ? 'system' : 'personal' ), + 'permissions' => $permissions, + 'id' => $mountConfig['id'], + 'class' => $mountConfig['class'] + ); + return $entry; + } + + /** + * Returns the mount points visible for this user. + * + * @param array $params + * @return \OC_OCS_Result share information + */ + public static function getUserMounts($params) { + $entries = array(); + $user = \OC::$server->getUserSession()->getUser()->getUID(); + + $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user); + foreach($mounts as $mountPoint => $mount) { + $entries[] = self::formatMount($mountPoint, $mount); + } + + return new \OC_OCS_Result($entries); + } +} diff --git a/apps/files_external/lib/Lib/Auth/Builtin.php b/apps/files_external/lib/Lib/Auth/Builtin.php index 8b43cb459cc..c5c3a19e54f 100644 --- a/apps/files_external/lib/Lib/Auth/Builtin.php +++ b/apps/files_external/lib/Lib/Auth/Builtin.php @@ -22,8 +22,6 @@ namespace OCA\Files_External\Lib\Auth; use \OCP\IL10N; -use \OCA\Files_External\Lib\Auth\AuthMechanism; -use \OCA\Files_external\Lib\StorageConfig; /** * Builtin authentication mechanism, for legacy backends diff --git a/apps/files_external/lib/Lib/Auth/NullMechanism.php b/apps/files_external/lib/Lib/Auth/NullMechanism.php index c0a8f4f119b..671a5ff66c5 100644 --- a/apps/files_external/lib/Lib/Auth/NullMechanism.php +++ b/apps/files_external/lib/Lib/Auth/NullMechanism.php @@ -22,7 +22,6 @@ namespace OCA\Files_External\Lib\Auth; use \OCP\IL10N; -use \OCA\Files_external\Lib\StorageConfig; /** * Null authentication mechanism diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/apps/files_external/lib/Lib/DefinitionParameter.php new file mode 100644 index 00000000000..16c07f4b8cc --- /dev/null +++ b/apps/files_external/lib/Lib/DefinitionParameter.php @@ -0,0 +1,193 @@ + + * @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 OCA\Files_External\Lib; + +/** + * Parameter for an external storage definition + */ +class DefinitionParameter implements \JsonSerializable { + + /** Value constants */ + const VALUE_TEXT = 0; + const VALUE_BOOLEAN = 1; + const VALUE_PASSWORD = 2; + const VALUE_HIDDEN = 3; + + /** Flag constants */ + const FLAG_NONE = 0; + const FLAG_OPTIONAL = 1; + const FLAG_USER_PROVIDED = 2; + + /** @var string name of parameter */ + private $name; + + /** @var string human-readable parameter text */ + private $text; + + /** @var int value type, see self::VALUE_* constants */ + private $type = self::VALUE_TEXT; + + /** @var int flags, see self::FLAG_* constants */ + private $flags = self::FLAG_NONE; + + /** + * @param string $name + * @param string $text + */ + public function __construct($name, $text) { + $this->name = $name; + $this->text = $text; + } + + /** + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * @return string + */ + public function getText() { + return $this->text; + } + + /** + * Get value type + * + * @return int + */ + public function getType() { + return $this->type; + } + + /** + * Set value type + * + * @param int $type + * @return self + */ + public function setType($type) { + $this->type = $type; + return $this; + } + + /** + * @return string + */ + public function getTypeName() { + switch ($this->type) { + case self::VALUE_BOOLEAN: + return 'boolean'; + case self::VALUE_TEXT: + return 'text'; + case self::VALUE_PASSWORD: + return 'password'; + default: + return 'unknown'; + } + } + + /** + * @return int + */ + public function getFlags() { + return $this->flags; + } + + /** + * @param int $flags + * @return self + */ + public function setFlags($flags) { + $this->flags = $flags; + return $this; + } + + /** + * @param int $flag + * @return self + */ + public function setFlag($flag) { + $this->flags |= $flag; + return $this; + } + + /** + * @param int $flag + * @return bool + */ + public function isFlagSet($flag) { + return (bool)($this->flags & $flag); + } + + /** + * Serialize into JSON for client-side JS + * + * @return string + */ + public function jsonSerialize() { + return [ + 'value' => $this->getText(), + 'flags' => $this->getFlags(), + 'type' => $this->getType() + ]; + } + + public function isOptional() { + return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED); + } + + /** + * Validate a parameter value against this + * Convert type as necessary + * + * @param mixed $value Value to check + * @return bool success + */ + public function validateValue(&$value) { + switch ($this->getType()) { + case self::VALUE_BOOLEAN: + if (!is_bool($value)) { + switch ($value) { + case 'true': + $value = true; + break; + case 'false': + $value = false; + break; + default: + return false; + } + } + break; + default: + if (!$value && !$this->isOptional()) { + return false; + } + break; + } + return true; + } +} diff --git a/apps/files_external/lib/Lib/DependencyTrait.php b/apps/files_external/lib/Lib/DependencyTrait.php new file mode 100644 index 00000000000..eed3ba1b327 --- /dev/null +++ b/apps/files_external/lib/Lib/DependencyTrait.php @@ -0,0 +1,41 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCA\Files_External\Lib\MissingDependency; + +/** + * Trait for objects that have dependencies for use + */ +trait DependencyTrait { + + /** + * Check if object is valid for use + * + * @return MissingDependency[] Unsatisfied dependencies + */ + public function checkDependencies() { + return []; // no dependencies by default + } + +} + diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php new file mode 100644 index 00000000000..ccc2a75fd1b --- /dev/null +++ b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php @@ -0,0 +1,158 @@ + + * @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 OCA\Files_External\Lib; + +use \OCA\Files_External\Lib\DefinitionParameter; +use \OCA\Files_External\Lib\StorageConfig; + +/** + * Trait for objects that have a frontend representation + */ +trait FrontendDefinitionTrait { + + /** @var string human-readable mechanism name */ + private $text; + + /** @var DefinitionParameter[] parameters for mechanism */ + private $parameters = []; + + /** @var string[] custom JS */ + private $customJs = []; + + /** + * @return string + */ + public function getText() { + return $this->text; + } + + /** + * @param string $text + * @return self + */ + public function setText($text) { + $this->text = $text; + return $this; + } + + /** + * @param FrontendDefinitionTrait $a + * @param FrontendDefinitionTrait $b + * @return int + */ + public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) { + return strcmp($a->getText(), $b->getText()); + } + + /** + * @return DefinitionParameter[] + */ + public function getParameters() { + return $this->parameters; + } + + /** + * @param DefinitionParameter[] $parameters + * @return self + */ + public function addParameters(array $parameters) { + foreach ($parameters as $parameter) { + $this->addParameter($parameter); + } + return $this; + } + + /** + * @param DefinitionParameter $parameter + * @return self + */ + public function addParameter(DefinitionParameter $parameter) { + $this->parameters[$parameter->getName()] = $parameter; + return $this; + } + + /** + * @return string[] + */ + public function getCustomJs() { + return $this->customJs; + } + + /** + * @param string $custom + * @return self + */ + public function addCustomJs($custom) { + $this->customJs[] = $custom; + return $this; + } + + /** + * @param string $custom + * @return self + * @deprecated 9.1.0, use addCustomJs() instead + */ + public function setCustomJs($custom) { + $this->customJs = [$custom]; + return $this; + } + + /** + * Serialize into JSON for client-side JS + * + * @return array + */ + public function jsonSerializeDefinition() { + $configuration = []; + foreach ($this->getParameters() as $parameter) { + $configuration[$parameter->getName()] = $parameter; + } + + $data = [ + 'name' => $this->getText(), + 'configuration' => $configuration, + 'custom' => $this->getCustomJs(), + ]; + return $data; + } + + /** + * Check if parameters are satisfied in a StorageConfig + * + * @param StorageConfig $storage + * @return bool + */ + public function validateStorageDefinition(StorageConfig $storage) { + foreach ($this->getParameters() as $name => $parameter) { + $value = $storage->getBackendOption($name); + if (!is_null($value) || !$parameter->isOptional()) { + if (!$parameter->validateValue($value)) { + return false; + } + $storage->setBackendOption($name, $value); + } + } + return true; + } + +} diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/apps/files_external/lib/Lib/IdentifierTrait.php new file mode 100644 index 00000000000..c49f4fcbc8d --- /dev/null +++ b/apps/files_external/lib/Lib/IdentifierTrait.php @@ -0,0 +1,102 @@ + + * + * @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 OCA\Files_External\Lib; + +/** + * Trait for objects requiring an identifier (and/or identifier aliases) + * Also supports deprecation to a different object, linking the objects + */ +trait IdentifierTrait { + + /** @var string */ + protected $identifier; + + /** @var string[] */ + protected $identifierAliases = []; + + /** @var IdentifierTrait */ + protected $deprecateTo = null; + + /** + * @return string + */ + public function getIdentifier() { + return $this->identifier; + } + + /** + * @param string $identifier + * @return self + */ + public function setIdentifier($identifier) { + $this->identifier = $identifier; + $this->identifierAliases[] = $identifier; + return $this; + } + + /** + * @return string[] + */ + public function getIdentifierAliases() { + return $this->identifierAliases; + } + + /** + * @param string $alias + * @return self + */ + public function addIdentifierAlias($alias) { + $this->identifierAliases[] = $alias; + return $this; + } + + /** + * @return object|null + */ + public function getDeprecateTo() { + return $this->deprecateTo; + } + + /** + * @param object $destinationObject + * @return self + */ + public function deprecateTo($destinationObject) { + $this->deprecateTo = $destinationObject; + return $this; + } + + /** + * @return array + */ + public function jsonSerializeIdentifier() { + $data = [ + 'identifier' => $this->identifier, + 'identifierAliases' => $this->identifierAliases, + ]; + if ($this->deprecateTo) { + $data['deprecateTo'] = $this->deprecateTo->getIdentifier(); + } + return $data; + } + +} diff --git a/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php b/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php new file mode 100644 index 00000000000..1906057eb67 --- /dev/null +++ b/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php @@ -0,0 +1,42 @@ + + * @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 OCA\Files_External\Lib; + +use \OCP\Files\StorageNotAvailableException; + +/** + * Authentication mechanism or backend has insufficient data + */ +class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException { + /** + * StorageNotAvailableException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 6.0.0 + */ + public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { + parent::__construct($message, $code, $previous); + } +} diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php new file mode 100644 index 00000000000..7d6c0c4b45b --- /dev/null +++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php @@ -0,0 +1,70 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCA\Files_External\Lib\MissingDependency; + +/** + * Polyfill for checking dependencies using legacy Storage::checkDependencies() + */ +trait LegacyDependencyCheckPolyfill { + + /** + * @return string + */ + abstract public function getStorageClass(); + + /** + * Check if object is valid for use + * + * @return MissingDependency[] Unsatisfied dependencies + */ + public function checkDependencies() { + $ret = []; + + $result = call_user_func([$this->getStorageClass(), 'checkDependencies']); + if ($result !== true) { + if (!is_array($result)) { + $result = [$result]; + } + foreach ($result as $key => $value) { + if (!($value instanceof MissingDependency)) { + $module = null; + $message = null; + if (is_numeric($key)) { + $module = $value; + } else { + $module = $key; + $message = $value; + } + $value = new MissingDependency($module, $this); + $value->setMessage($message); + } + $ret[] = $value; + } + } + + return $ret; + } + +} + diff --git a/apps/files_external/lib/Lib/MissingDependency.php b/apps/files_external/lib/Lib/MissingDependency.php new file mode 100644 index 00000000000..a4a20dd1128 --- /dev/null +++ b/apps/files_external/lib/Lib/MissingDependency.php @@ -0,0 +1,64 @@ + + * + * @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 OCA\Files_External\Lib; + +/** + * External storage backend dependency + */ +class MissingDependency { + + /** @var string */ + private $dependency; + + /** @var string|null Custom message */ + private $message = null; + + /** + * @param string $dependency + */ + public function __construct($dependency) { + $this->dependency = $dependency; + } + + /** + * @return string + */ + public function getDependency() { + return $this->dependency; + } + + /** + * @return string|null + */ + public function getMessage() { + return $this->message; + } + + /** + * @param string $message + * @return self + */ + public function setMessage($message) { + $this->message = $message; + return $this; + } +} diff --git a/apps/files_external/lib/Lib/PersonalMount.php b/apps/files_external/lib/Lib/PersonalMount.php new file mode 100644 index 00000000000..c3b71fbef32 --- /dev/null +++ b/apps/files_external/lib/Lib/PersonalMount.php @@ -0,0 +1,88 @@ + + * @author Robin Appelman + * @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 OCA\Files_External\Lib; + +use OC\Files\Mount\MountPoint; +use OC\Files\Mount\MoveableMount; +use OCA\Files_External\Service\UserStoragesService; + +/** + * Person mount points can be moved by the user + */ +class PersonalMount extends MountPoint implements MoveableMount { + /** @var UserStoragesService */ + protected $storagesService; + + /** @var int */ + protected $numericStorageId; + + /** + * @param UserStoragesService $storagesService + * @param int $storageId + * @param \OCP\Files\Storage $storage + * @param string $mountpoint + * @param array $arguments (optional) configuration for the storage backend + * @param \OCP\Files\Storage\IStorageFactory $loader + * @param array $mountOptions mount specific options + */ + public function __construct( + UserStoragesService $storagesService, + $storageId, + $storage, + $mountpoint, + $arguments = null, + $loader = null, + $mountOptions = null + ) { + parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions); + $this->storagesService = $storagesService; + $this->numericStorageId = $storageId; + } + + /** + * Move the mount point to $target + * + * @param string $target the target mount point + * @return bool + */ + public function moveMount($target) { + $storage = $this->storagesService->getStorage($this->numericStorageId); + // remove "/$user/files" prefix + $targetParts = explode('/', trim($target, '/'), 3); + $storage->setMountPoint($targetParts[2]); + $this->storagesService->updateStorage($storage); + $this->setMountPoint($target); + return true; + } + + /** + * Remove the mount points + * + * @return bool + */ + public function removeMount() { + $this->storagesService->removeStorage($this->numericStorageId); + return true; + } +} diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/apps/files_external/lib/Lib/PriorityTrait.php new file mode 100644 index 00000000000..9745015bef4 --- /dev/null +++ b/apps/files_external/lib/Lib/PriorityTrait.php @@ -0,0 +1,60 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCA\Files_External\Service\BackendService; + +/** + * Trait to implement priority mechanics for a configuration class + */ +trait PriorityTrait { + + /** @var int initial priority */ + protected $priority = BackendService::PRIORITY_DEFAULT; + + /** + * @return int + */ + public function getPriority() { + return $this->priority; + } + + /** + * @param int $priority + * @return self + */ + public function setPriority($priority) { + $this->priority = $priority; + return $this; + } + + /** + * @param PriorityTrait $a + * @param PriorityTrait $b + * @return int + */ + public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) { + return ($a->getPriority() - $b->getPriority()); + } + +} + diff --git a/apps/files_external/lib/Lib/SessionStorageWrapper.php b/apps/files_external/lib/Lib/SessionStorageWrapper.php new file mode 100644 index 00000000000..c592cb87a34 --- /dev/null +++ b/apps/files_external/lib/Lib/SessionStorageWrapper.php @@ -0,0 +1,43 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCP\Files\Storage; +use \OC\Files\Storage\Wrapper\PermissionsMask; +use \OCP\Constants; + +/** + * Wrap Storage in PermissionsMask for session ephemeral use + */ +class SessionStorageWrapper extends PermissionsMask { + + /** + * @param array $arguments ['storage' => $storage] + */ + public function __construct($arguments) { + // disable sharing permission + $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE; + parent::__construct($arguments); + } + +} + diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php new file mode 100644 index 00000000000..2a22b324ead --- /dev/null +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -0,0 +1,430 @@ + + * @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 OCA\Files_External\Lib; + +use OCA\Files_External\Lib\Auth\IUserProvided; +use \OCA\Files_External\Lib\Backend\Backend; +use \OCA\Files_External\Lib\Auth\AuthMechanism; + +/** + * External storage configuration + */ +class StorageConfig implements \JsonSerializable { + const MOUNT_TYPE_ADMIN = 1; + const MOUNT_TYPE_PERSONAl = 2; + + /** + * Storage config id + * + * @var int + */ + private $id; + + /** + * Backend + * + * @var Backend + */ + private $backend; + + /** + * Authentication mechanism + * + * @var AuthMechanism + */ + private $authMechanism; + + /** + * Backend options + * + * @var array + */ + private $backendOptions = []; + + /** + * Mount point path, relative to the user's "files" folder + * + * @var string + */ + private $mountPoint; + + /** + * Storage status + * + * @var int + */ + private $status; + + /** + * Status message + * + * @var string + */ + private $statusMessage; + + /** + * Priority + * + * @var int + */ + private $priority; + + /** + * List of users who have access to this storage + * + * @var array + */ + private $applicableUsers = []; + + /** + * List of groups that have access to this storage + * + * @var array + */ + private $applicableGroups = []; + + /** + * Mount-specific options + * + * @var array + */ + private $mountOptions = []; + + /** + * Whether it's a personal or admin mount + * + * @var int + */ + private $type; + + /** + * Creates a storage config + * + * @param int|null $id config id or null for a new config + */ + public function __construct($id = null) { + $this->id = $id; + $this->mountOptions['enable_sharing'] = false; + } + + /** + * Returns the configuration id + * + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * Sets the configuration id + * + * @param int $id configuration id + */ + public function setId($id) { + $this->id = $id; + } + + /** + * Returns mount point path relative to the user's + * "files" folder. + * + * @return string path + */ + public function getMountPoint() { + return $this->mountPoint; + } + + /** + * Sets mount point path relative to the user's + * "files" folder. + * The path will be normalized. + * + * @param string $mountPoint path + */ + public function setMountPoint($mountPoint) { + $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); + } + + /** + * @return Backend + */ + public function getBackend() { + return $this->backend; + } + + /** + * @param Backend $backend + */ + public function setBackend(Backend $backend) { + $this->backend= $backend; + } + + /** + * @return AuthMechanism + */ + public function getAuthMechanism() { + return $this->authMechanism; + } + + /** + * @param AuthMechanism $authMechanism + */ + public function setAuthMechanism(AuthMechanism $authMechanism) { + $this->authMechanism = $authMechanism; + } + + /** + * Returns the external storage backend-specific options + * + * @return array backend options + */ + public function getBackendOptions() { + return $this->backendOptions; + } + + /** + * Sets the external storage backend-specific options + * + * @param array $backendOptions backend options + */ + public function setBackendOptions($backendOptions) { + if($this->getBackend() instanceof Backend) { + $parameters = $this->getBackend()->getParameters(); + foreach($backendOptions as $key => $value) { + if(isset($parameters[$key])) { + switch ($parameters[$key]->getType()) { + case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: + $value = (bool)$value; + break; + } + $backendOptions[$key] = $value; + } + } + } + + $this->backendOptions = $backendOptions; + } + + /** + * @param string $key + * @return mixed + */ + public function getBackendOption($key) { + if (isset($this->backendOptions[$key])) { + return $this->backendOptions[$key]; + } + return null; + } + + /** + * @param string $key + * @param mixed $value + */ + public function setBackendOption($key, $value) { + $this->backendOptions[$key] = $value; + } + + /** + * Returns the mount priority + * + * @return int priority + */ + public function getPriority() { + return $this->priority; + } + + /** + * Sets the mount priotity + * + * @param int $priority priority + */ + public function setPriority($priority) { + $this->priority = $priority; + } + + /** + * Returns the users for which to mount this storage + * + * @return array applicable users + */ + public function getApplicableUsers() { + return $this->applicableUsers; + } + + /** + * Sets the users for which to mount this storage + * + * @param array|null $applicableUsers applicable users + */ + public function setApplicableUsers($applicableUsers) { + if (is_null($applicableUsers)) { + $applicableUsers = []; + } + $this->applicableUsers = $applicableUsers; + } + + /** + * Returns the groups for which to mount this storage + * + * @return array applicable groups + */ + public function getApplicableGroups() { + return $this->applicableGroups; + } + + /** + * Sets the groups for which to mount this storage + * + * @param array|null $applicableGroups applicable groups + */ + public function setApplicableGroups($applicableGroups) { + if (is_null($applicableGroups)) { + $applicableGroups = []; + } + $this->applicableGroups = $applicableGroups; + } + + /** + * Returns the mount-specific options + * + * @return array mount specific options + */ + public function getMountOptions() { + return $this->mountOptions; + } + + /** + * Sets the mount-specific options + * + * @param array $mountOptions applicable groups + */ + public function setMountOptions($mountOptions) { + if (is_null($mountOptions)) { + $mountOptions = []; + } + $this->mountOptions = $mountOptions; + } + + /** + * @param string $key + * @return mixed + */ + public function getMountOption($key) { + if (isset($this->mountOptions[$key])) { + return $this->mountOptions[$key]; + } + return null; + } + + /** + * @param string $key + * @param mixed $value + */ + public function setMountOption($key, $value) { + $this->mountOptions[$key] = $value; + } + + /** + * Gets the storage status, whether the config worked last time + * + * @return int $status status + */ + public function getStatus() { + return $this->status; + } + + /** + * Gets the message describing the storage status + * + * @return string|null + */ + public function getStatusMessage() { + return $this->statusMessage; + } + + /** + * Sets the storage status, whether the config worked last time + * + * @param int $status status + * @param string|null $message optional message + */ + public function setStatus($status, $message = null) { + $this->status = $status; + $this->statusMessage = $message; + } + + /** + * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + */ + public function getType() { + return $this->type; + } + + /** + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl + */ + public function setType($type) { + $this->type = $type; + } + + /** + * Serialize config to JSON + * + * @return array + */ + public function jsonSerialize() { + $result = []; + if (!is_null($this->id)) { + $result['id'] = $this->id; + } + $result['mountPoint'] = $this->mountPoint; + $result['backend'] = $this->backend->getIdentifier(); + $result['authMechanism'] = $this->authMechanism->getIdentifier(); + $result['backendOptions'] = $this->backendOptions; + if (!is_null($this->priority)) { + $result['priority'] = $this->priority; + } + if (!empty($this->applicableUsers)) { + $result['applicableUsers'] = $this->applicableUsers; + } + if (!empty($this->applicableGroups)) { + $result['applicableGroups'] = $this->applicableGroups; + } + if (!empty($this->mountOptions)) { + $result['mountOptions'] = $this->mountOptions; + } + if (!is_null($this->status)) { + $result['status'] = $this->status; + } + if (!is_null($this->statusMessage)) { + $result['statusMessage'] = $this->statusMessage; + } + $result['userProvided'] = $this->authMechanism instanceof IUserProvided; + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; + return $result; + } +} diff --git a/apps/files_external/lib/Lib/StorageModifierTrait.php b/apps/files_external/lib/Lib/StorageModifierTrait.php new file mode 100644 index 00000000000..30c2108feec --- /dev/null +++ b/apps/files_external/lib/Lib/StorageModifierTrait.php @@ -0,0 +1,69 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCP\IUser; +use \OCP\Files\Storage; +use \OCA\Files_External\Lib\StorageConfig; +use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; +use \OCP\Files\StorageNotAvailableException; + +/** + * Trait for objects that can modify StorageConfigs and wrap Storages + * + * When a storage implementation is being prepared for use, the StorageConfig + * 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 + * a wrapped storage that changes its behaviour. + * + * Certain configuration options need to be set before the implementation is + * constructed, while others are retrieved directly from the storage + * implementation and so need a wrapper to be modified. + */ +trait StorageModifierTrait { + + /** + * Modify a StorageConfig parameters + * + * @param StorageConfig $storage + * @param IUser $user User the storage is being used as + * @throws InsufficientDataForMeaningfulAnswerException + * @throws StorageNotAvailableException + */ + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { + } + + /** + * Wrap a Storage if necessary + * + * @param Storage $storage + * @return Storage + * @throws InsufficientDataForMeaningfulAnswerException + * @throws StorageNotAvailableException + */ + public function wrapStorage(Storage $storage) { + return $storage; + } + +} + diff --git a/apps/files_external/lib/Lib/VisibilityTrait.php b/apps/files_external/lib/Lib/VisibilityTrait.php new file mode 100644 index 00000000000..916c8e69d9c --- /dev/null +++ b/apps/files_external/lib/Lib/VisibilityTrait.php @@ -0,0 +1,136 @@ + + * + * @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 OCA\Files_External\Lib; + +use \OCA\Files_External\Service\BackendService; + +/** + * Trait to implement visibility mechanics for a configuration class + * + * The standard visibility defines which users/groups can use or see the + * object. The allowed visibility defines the maximum visibility allowed to be + * set on the object. The standard visibility is often set dynamically by + * stored configuration parameters that can be modified by the administrator, + * while the allowed visibility is set directly by the object and cannot be + * modified by the administrator. + */ +trait VisibilityTrait { + + /** @var int visibility */ + protected $visibility = BackendService::VISIBILITY_DEFAULT; + + /** @var int allowed visibilities */ + protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT; + + /** + * @return int + */ + public function getVisibility() { + return $this->visibility; + } + + /** + * Check if the backend is visible for a user type + * + * @param int $visibility + * @return bool + */ + public function isVisibleFor($visibility) { + if ($this->visibility & $visibility) { + return true; + } + return false; + } + + /** + * @param int $visibility + * @return self + */ + public function setVisibility($visibility) { + $this->visibility = $visibility; + $this->allowedVisibility |= $visibility; + return $this; + } + + /** + * @param int $visibility + * @return self + */ + public function addVisibility($visibility) { + return $this->setVisibility($this->visibility | $visibility); + } + + /** + * @param int $visibility + * @return self + */ + public function removeVisibility($visibility) { + return $this->setVisibility($this->visibility & ~$visibility); + } + + /** + * @return int + */ + public function getAllowedVisibility() { + return $this->allowedVisibility; + } + + /** + * Check if the backend is allowed to be visible for a user type + * + * @param int $allowedVisibility + * @return bool + */ + public function isAllowedVisibleFor($allowedVisibility) { + if ($this->allowedVisibility & $allowedVisibility) { + return true; + } + return false; + } + + /** + * @param int $allowedVisibility + * @return self + */ + public function setAllowedVisibility($allowedVisibility) { + $this->allowedVisibility = $allowedVisibility; + $this->visibility &= $allowedVisibility; + return $this; + } + + /** + * @param int $allowedVisibility + * @return self + */ + public function addAllowedVisibility($allowedVisibility) { + return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility); + } + + /** + * @param int $allowedVisibility + * @return self + */ + public function removeAllowedVisibility($allowedVisibility) { + return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility); + } + +} diff --git a/apps/files_external/lib/NotFoundException.php b/apps/files_external/lib/NotFoundException.php new file mode 100644 index 00000000000..80333c103ca --- /dev/null +++ b/apps/files_external/lib/NotFoundException.php @@ -0,0 +1,28 @@ + + * + * @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 OCA\Files_External; + +/** + * Storage is not found + */ +class NotFoundException extends \Exception { +} diff --git a/apps/files_external/lib/Service/GlobalStoragesService.php b/apps/files_external/lib/Service/GlobalStoragesService.php index 6032a827735..592283444d1 100644 --- a/apps/files_external/lib/Service/GlobalStoragesService.php +++ b/apps/files_external/lib/Service/GlobalStoragesService.php @@ -24,11 +24,9 @@ namespace OCA\Files_External\Service; -use \OCP\IUserSession; -use \OC\Files\Filesystem; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_external\NotFoundException; +use \OC\Files\Filesystem; +use OCA\Files_External\Lib\StorageConfig; /** * Service class to manage global external storages diff --git a/apps/files_external/lib/Service/LegacyStoragesService.php b/apps/files_external/lib/Service/LegacyStoragesService.php index 40f57e45506..365181d746c 100644 --- a/apps/files_external/lib/Service/LegacyStoragesService.php +++ b/apps/files_external/lib/Service/LegacyStoragesService.php @@ -21,7 +21,7 @@ namespace OCA\Files_External\Service; -use \OCA\Files_external\Lib\StorageConfig; +use OCA\Files_External\Lib\StorageConfig; /** * Read mount config from legacy mount.json diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index 0999c0a7adf..4fb0f65e760 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -26,8 +26,8 @@ namespace OCA\Files_External\Service; use \OC\Files\Filesystem; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_external\NotFoundException; +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 OCP\Files\Config\IUserMountCache; diff --git a/apps/files_external/lib/Service/UserStoragesService.php b/apps/files_external/lib/Service/UserStoragesService.php index b64f289b3ee..a527acbba3a 100644 --- a/apps/files_external/lib/Service/UserStoragesService.php +++ b/apps/files_external/lib/Service/UserStoragesService.php @@ -27,8 +27,8 @@ use OCP\Files\Config\IUserMountCache; use \OCP\IUserSession; use \OC\Files\Filesystem; -use \OCA\Files_external\Lib\StorageConfig; -use \OCA\Files_external\NotFoundException; +use OCA\Files_External\Lib\StorageConfig; +use OCA\Files_External\NotFoundException; use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Service\UserTrait; diff --git a/apps/files_external/lib/api.php b/apps/files_external/lib/api.php deleted file mode 100644 index 589317dcf98..00000000000 --- a/apps/files_external/lib/api.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @author Joas Schilling - * @author Morris Jobke - * @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 OCA\Files_External\Lib; - -class Api { - - /** - * Formats the given mount config to a mount entry. - * - * @param string $mountPoint mount point name, relative to the data dir - * @param array $mountConfig mount config to format - * - * @return array entry - */ - private static function formatMount($mountPoint, $mountConfig) { - // strip "/$user/files" from mount point - $mountPoint = explode('/', trim($mountPoint, '/'), 3); - $mountPoint = $mountPoint[2]; - - // split path from mount point - $path = dirname($mountPoint); - if ($path === '.') { - $path = ''; - } - - $isSystemMount = !$mountConfig['personal']; - - $permissions = \OCP\Constants::PERMISSION_READ; - // personal mounts can be deleted - if (!$isSystemMount) { - $permissions |= \OCP\Constants::PERMISSION_DELETE; - } - - $entry = array( - 'name' => basename($mountPoint), - 'path' => $path, - 'type' => 'dir', - 'backend' => $mountConfig['backend'], - 'scope' => ( $isSystemMount ? 'system' : 'personal' ), - 'permissions' => $permissions, - 'id' => $mountConfig['id'], - 'class' => $mountConfig['class'] - ); - return $entry; - } - - /** - * Returns the mount points visible for this user. - * - * @param array $params - * @return \OC_OCS_Result share information - */ - public static function getUserMounts($params) { - $entries = array(); - $user = \OC::$server->getUserSession()->getUser()->getUID(); - - $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user); - foreach($mounts as $mountPoint => $mount) { - $entries[] = self::formatMount($mountPoint, $mount); - } - - return new \OC_OCS_Result($entries); - } -} diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 70f8550f39b..d581deab190 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -33,7 +33,7 @@ */ use phpseclib\Crypt\AES; -use \OCA\Files_External\Appinfo\Application; +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; @@ -91,7 +91,7 @@ class OC_Mount_Config { $userStoragesService->setUser($user); foreach ($userGlobalStoragesService->getStorages() as $storage) { - /** @var \OCA\Files_external\Lib\StorageConfig $storage */ + /** @var \OCA\Files_External\Lib\StorageConfig $storage */ $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); $mountEntry = self::prepareMountPointEntry($storage, false); foreach ($mountEntry['options'] as &$option) { diff --git a/apps/files_external/lib/definitionparameter.php b/apps/files_external/lib/definitionparameter.php deleted file mode 100644 index 16c07f4b8cc..00000000000 --- a/apps/files_external/lib/definitionparameter.php +++ /dev/null @@ -1,193 +0,0 @@ - - * @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 OCA\Files_External\Lib; - -/** - * Parameter for an external storage definition - */ -class DefinitionParameter implements \JsonSerializable { - - /** Value constants */ - const VALUE_TEXT = 0; - const VALUE_BOOLEAN = 1; - const VALUE_PASSWORD = 2; - const VALUE_HIDDEN = 3; - - /** Flag constants */ - const FLAG_NONE = 0; - const FLAG_OPTIONAL = 1; - const FLAG_USER_PROVIDED = 2; - - /** @var string name of parameter */ - private $name; - - /** @var string human-readable parameter text */ - private $text; - - /** @var int value type, see self::VALUE_* constants */ - private $type = self::VALUE_TEXT; - - /** @var int flags, see self::FLAG_* constants */ - private $flags = self::FLAG_NONE; - - /** - * @param string $name - * @param string $text - */ - public function __construct($name, $text) { - $this->name = $name; - $this->text = $text; - } - - /** - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * @return string - */ - public function getText() { - return $this->text; - } - - /** - * Get value type - * - * @return int - */ - public function getType() { - return $this->type; - } - - /** - * Set value type - * - * @param int $type - * @return self - */ - public function setType($type) { - $this->type = $type; - return $this; - } - - /** - * @return string - */ - public function getTypeName() { - switch ($this->type) { - case self::VALUE_BOOLEAN: - return 'boolean'; - case self::VALUE_TEXT: - return 'text'; - case self::VALUE_PASSWORD: - return 'password'; - default: - return 'unknown'; - } - } - - /** - * @return int - */ - public function getFlags() { - return $this->flags; - } - - /** - * @param int $flags - * @return self - */ - public function setFlags($flags) { - $this->flags = $flags; - return $this; - } - - /** - * @param int $flag - * @return self - */ - public function setFlag($flag) { - $this->flags |= $flag; - return $this; - } - - /** - * @param int $flag - * @return bool - */ - public function isFlagSet($flag) { - return (bool)($this->flags & $flag); - } - - /** - * Serialize into JSON for client-side JS - * - * @return string - */ - public function jsonSerialize() { - return [ - 'value' => $this->getText(), - 'flags' => $this->getFlags(), - 'type' => $this->getType() - ]; - } - - public function isOptional() { - return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED); - } - - /** - * Validate a parameter value against this - * Convert type as necessary - * - * @param mixed $value Value to check - * @return bool success - */ - public function validateValue(&$value) { - switch ($this->getType()) { - case self::VALUE_BOOLEAN: - if (!is_bool($value)) { - switch ($value) { - case 'true': - $value = true; - break; - case 'false': - $value = false; - break; - default: - return false; - } - } - break; - default: - if (!$value && !$this->isOptional()) { - return false; - } - break; - } - return true; - } -} diff --git a/apps/files_external/lib/dependencytrait.php b/apps/files_external/lib/dependencytrait.php deleted file mode 100644 index eed3ba1b327..00000000000 --- a/apps/files_external/lib/dependencytrait.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCA\Files_External\Lib\MissingDependency; - -/** - * Trait for objects that have dependencies for use - */ -trait DependencyTrait { - - /** - * Check if object is valid for use - * - * @return MissingDependency[] Unsatisfied dependencies - */ - public function checkDependencies() { - return []; // no dependencies by default - } - -} - diff --git a/apps/files_external/lib/frontenddefinitiontrait.php b/apps/files_external/lib/frontenddefinitiontrait.php deleted file mode 100644 index ccc2a75fd1b..00000000000 --- a/apps/files_external/lib/frontenddefinitiontrait.php +++ /dev/null @@ -1,158 +0,0 @@ - - * @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 OCA\Files_External\Lib; - -use \OCA\Files_External\Lib\DefinitionParameter; -use \OCA\Files_External\Lib\StorageConfig; - -/** - * Trait for objects that have a frontend representation - */ -trait FrontendDefinitionTrait { - - /** @var string human-readable mechanism name */ - private $text; - - /** @var DefinitionParameter[] parameters for mechanism */ - private $parameters = []; - - /** @var string[] custom JS */ - private $customJs = []; - - /** - * @return string - */ - public function getText() { - return $this->text; - } - - /** - * @param string $text - * @return self - */ - public function setText($text) { - $this->text = $text; - return $this; - } - - /** - * @param FrontendDefinitionTrait $a - * @param FrontendDefinitionTrait $b - * @return int - */ - public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) { - return strcmp($a->getText(), $b->getText()); - } - - /** - * @return DefinitionParameter[] - */ - public function getParameters() { - return $this->parameters; - } - - /** - * @param DefinitionParameter[] $parameters - * @return self - */ - public function addParameters(array $parameters) { - foreach ($parameters as $parameter) { - $this->addParameter($parameter); - } - return $this; - } - - /** - * @param DefinitionParameter $parameter - * @return self - */ - public function addParameter(DefinitionParameter $parameter) { - $this->parameters[$parameter->getName()] = $parameter; - return $this; - } - - /** - * @return string[] - */ - public function getCustomJs() { - return $this->customJs; - } - - /** - * @param string $custom - * @return self - */ - public function addCustomJs($custom) { - $this->customJs[] = $custom; - return $this; - } - - /** - * @param string $custom - * @return self - * @deprecated 9.1.0, use addCustomJs() instead - */ - public function setCustomJs($custom) { - $this->customJs = [$custom]; - return $this; - } - - /** - * Serialize into JSON for client-side JS - * - * @return array - */ - public function jsonSerializeDefinition() { - $configuration = []; - foreach ($this->getParameters() as $parameter) { - $configuration[$parameter->getName()] = $parameter; - } - - $data = [ - 'name' => $this->getText(), - 'configuration' => $configuration, - 'custom' => $this->getCustomJs(), - ]; - return $data; - } - - /** - * Check if parameters are satisfied in a StorageConfig - * - * @param StorageConfig $storage - * @return bool - */ - public function validateStorageDefinition(StorageConfig $storage) { - foreach ($this->getParameters() as $name => $parameter) { - $value = $storage->getBackendOption($name); - if (!is_null($value) || !$parameter->isOptional()) { - if (!$parameter->validateValue($value)) { - return false; - } - $storage->setBackendOption($name, $value); - } - } - return true; - } - -} diff --git a/apps/files_external/lib/identifiertrait.php b/apps/files_external/lib/identifiertrait.php deleted file mode 100644 index c49f4fcbc8d..00000000000 --- a/apps/files_external/lib/identifiertrait.php +++ /dev/null @@ -1,102 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -/** - * Trait for objects requiring an identifier (and/or identifier aliases) - * Also supports deprecation to a different object, linking the objects - */ -trait IdentifierTrait { - - /** @var string */ - protected $identifier; - - /** @var string[] */ - protected $identifierAliases = []; - - /** @var IdentifierTrait */ - protected $deprecateTo = null; - - /** - * @return string - */ - public function getIdentifier() { - return $this->identifier; - } - - /** - * @param string $identifier - * @return self - */ - public function setIdentifier($identifier) { - $this->identifier = $identifier; - $this->identifierAliases[] = $identifier; - return $this; - } - - /** - * @return string[] - */ - public function getIdentifierAliases() { - return $this->identifierAliases; - } - - /** - * @param string $alias - * @return self - */ - public function addIdentifierAlias($alias) { - $this->identifierAliases[] = $alias; - return $this; - } - - /** - * @return object|null - */ - public function getDeprecateTo() { - return $this->deprecateTo; - } - - /** - * @param object $destinationObject - * @return self - */ - public function deprecateTo($destinationObject) { - $this->deprecateTo = $destinationObject; - return $this; - } - - /** - * @return array - */ - public function jsonSerializeIdentifier() { - $data = [ - 'identifier' => $this->identifier, - 'identifierAliases' => $this->identifierAliases, - ]; - if ($this->deprecateTo) { - $data['deprecateTo'] = $this->deprecateTo->getIdentifier(); - } - return $data; - } - -} diff --git a/apps/files_external/lib/insufficientdataformeaningfulanswerexception.php b/apps/files_external/lib/insufficientdataformeaningfulanswerexception.php deleted file mode 100644 index 1906057eb67..00000000000 --- a/apps/files_external/lib/insufficientdataformeaningfulanswerexception.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @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 OCA\Files_External\Lib; - -use \OCP\Files\StorageNotAvailableException; - -/** - * Authentication mechanism or backend has insufficient data - */ -class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException { - /** - * StorageNotAvailableException constructor. - * - * @param string $message - * @param int $code - * @param \Exception $previous - * @since 6.0.0 - */ - public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { - parent::__construct($message, $code, $previous); - } -} diff --git a/apps/files_external/lib/legacydependencycheckpolyfill.php b/apps/files_external/lib/legacydependencycheckpolyfill.php deleted file mode 100644 index 7d6c0c4b45b..00000000000 --- a/apps/files_external/lib/legacydependencycheckpolyfill.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCA\Files_External\Lib\MissingDependency; - -/** - * Polyfill for checking dependencies using legacy Storage::checkDependencies() - */ -trait LegacyDependencyCheckPolyfill { - - /** - * @return string - */ - abstract public function getStorageClass(); - - /** - * Check if object is valid for use - * - * @return MissingDependency[] Unsatisfied dependencies - */ - public function checkDependencies() { - $ret = []; - - $result = call_user_func([$this->getStorageClass(), 'checkDependencies']); - if ($result !== true) { - if (!is_array($result)) { - $result = [$result]; - } - foreach ($result as $key => $value) { - if (!($value instanceof MissingDependency)) { - $module = null; - $message = null; - if (is_numeric($key)) { - $module = $value; - } else { - $module = $key; - $message = $value; - } - $value = new MissingDependency($module, $this); - $value->setMessage($message); - } - $ret[] = $value; - } - } - - return $ret; - } - -} - diff --git a/apps/files_external/lib/missingdependency.php b/apps/files_external/lib/missingdependency.php deleted file mode 100644 index a4a20dd1128..00000000000 --- a/apps/files_external/lib/missingdependency.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -/** - * External storage backend dependency - */ -class MissingDependency { - - /** @var string */ - private $dependency; - - /** @var string|null Custom message */ - private $message = null; - - /** - * @param string $dependency - */ - public function __construct($dependency) { - $this->dependency = $dependency; - } - - /** - * @return string - */ - public function getDependency() { - return $this->dependency; - } - - /** - * @return string|null - */ - public function getMessage() { - return $this->message; - } - - /** - * @param string $message - * @return self - */ - public function setMessage($message) { - $this->message = $message; - return $this; - } -} diff --git a/apps/files_external/lib/notfoundexception.php b/apps/files_external/lib/notfoundexception.php deleted file mode 100644 index dd3dd1907a5..00000000000 --- a/apps/files_external/lib/notfoundexception.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * @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 OCA\Files_external; - -/** - * Storage is not found - */ -class NotFoundException extends \Exception { -} diff --git a/apps/files_external/lib/personalmount.php b/apps/files_external/lib/personalmount.php deleted file mode 100644 index c3b71fbef32..00000000000 --- a/apps/files_external/lib/personalmount.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @author Robin Appelman - * @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 OCA\Files_External\Lib; - -use OC\Files\Mount\MountPoint; -use OC\Files\Mount\MoveableMount; -use OCA\Files_External\Service\UserStoragesService; - -/** - * Person mount points can be moved by the user - */ -class PersonalMount extends MountPoint implements MoveableMount { - /** @var UserStoragesService */ - protected $storagesService; - - /** @var int */ - protected $numericStorageId; - - /** - * @param UserStoragesService $storagesService - * @param int $storageId - * @param \OCP\Files\Storage $storage - * @param string $mountpoint - * @param array $arguments (optional) configuration for the storage backend - * @param \OCP\Files\Storage\IStorageFactory $loader - * @param array $mountOptions mount specific options - */ - public function __construct( - UserStoragesService $storagesService, - $storageId, - $storage, - $mountpoint, - $arguments = null, - $loader = null, - $mountOptions = null - ) { - parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions); - $this->storagesService = $storagesService; - $this->numericStorageId = $storageId; - } - - /** - * Move the mount point to $target - * - * @param string $target the target mount point - * @return bool - */ - public function moveMount($target) { - $storage = $this->storagesService->getStorage($this->numericStorageId); - // remove "/$user/files" prefix - $targetParts = explode('/', trim($target, '/'), 3); - $storage->setMountPoint($targetParts[2]); - $this->storagesService->updateStorage($storage); - $this->setMountPoint($target); - return true; - } - - /** - * Remove the mount points - * - * @return bool - */ - public function removeMount() { - $this->storagesService->removeStorage($this->numericStorageId); - return true; - } -} diff --git a/apps/files_external/lib/prioritytrait.php b/apps/files_external/lib/prioritytrait.php deleted file mode 100644 index 9745015bef4..00000000000 --- a/apps/files_external/lib/prioritytrait.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCA\Files_External\Service\BackendService; - -/** - * Trait to implement priority mechanics for a configuration class - */ -trait PriorityTrait { - - /** @var int initial priority */ - protected $priority = BackendService::PRIORITY_DEFAULT; - - /** - * @return int - */ - public function getPriority() { - return $this->priority; - } - - /** - * @param int $priority - * @return self - */ - public function setPriority($priority) { - $this->priority = $priority; - return $this; - } - - /** - * @param PriorityTrait $a - * @param PriorityTrait $b - * @return int - */ - public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) { - return ($a->getPriority() - $b->getPriority()); - } - -} - diff --git a/apps/files_external/lib/sessionstoragewrapper.php b/apps/files_external/lib/sessionstoragewrapper.php deleted file mode 100644 index c592cb87a34..00000000000 --- a/apps/files_external/lib/sessionstoragewrapper.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCP\Files\Storage; -use \OC\Files\Storage\Wrapper\PermissionsMask; -use \OCP\Constants; - -/** - * Wrap Storage in PermissionsMask for session ephemeral use - */ -class SessionStorageWrapper extends PermissionsMask { - - /** - * @param array $arguments ['storage' => $storage] - */ - public function __construct($arguments) { - // disable sharing permission - $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE; - parent::__construct($arguments); - } - -} - diff --git a/apps/files_external/lib/storageconfig.php b/apps/files_external/lib/storageconfig.php deleted file mode 100644 index 590a5f53249..00000000000 --- a/apps/files_external/lib/storageconfig.php +++ /dev/null @@ -1,430 +0,0 @@ - - * @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 OCA\Files_external\Lib; - -use OCA\Files_External\Lib\Auth\IUserProvided; -use \OCA\Files_External\Lib\Backend\Backend; -use \OCA\Files_External\Lib\Auth\AuthMechanism; - -/** - * External storage configuration - */ -class StorageConfig implements \JsonSerializable { - const MOUNT_TYPE_ADMIN = 1; - const MOUNT_TYPE_PERSONAl = 2; - - /** - * Storage config id - * - * @var int - */ - private $id; - - /** - * Backend - * - * @var Backend - */ - private $backend; - - /** - * Authentication mechanism - * - * @var AuthMechanism - */ - private $authMechanism; - - /** - * Backend options - * - * @var array - */ - private $backendOptions = []; - - /** - * Mount point path, relative to the user's "files" folder - * - * @var string - */ - private $mountPoint; - - /** - * Storage status - * - * @var int - */ - private $status; - - /** - * Status message - * - * @var string - */ - private $statusMessage; - - /** - * Priority - * - * @var int - */ - private $priority; - - /** - * List of users who have access to this storage - * - * @var array - */ - private $applicableUsers = []; - - /** - * List of groups that have access to this storage - * - * @var array - */ - private $applicableGroups = []; - - /** - * Mount-specific options - * - * @var array - */ - private $mountOptions = []; - - /** - * Whether it's a personal or admin mount - * - * @var int - */ - private $type; - - /** - * Creates a storage config - * - * @param int|null $id config id or null for a new config - */ - public function __construct($id = null) { - $this->id = $id; - $this->mountOptions['enable_sharing'] = false; - } - - /** - * Returns the configuration id - * - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * Sets the configuration id - * - * @param int $id configuration id - */ - public function setId($id) { - $this->id = $id; - } - - /** - * Returns mount point path relative to the user's - * "files" folder. - * - * @return string path - */ - public function getMountPoint() { - return $this->mountPoint; - } - - /** - * Sets mount point path relative to the user's - * "files" folder. - * The path will be normalized. - * - * @param string $mountPoint path - */ - public function setMountPoint($mountPoint) { - $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); - } - - /** - * @return Backend - */ - public function getBackend() { - return $this->backend; - } - - /** - * @param Backend $backend - */ - public function setBackend(Backend $backend) { - $this->backend= $backend; - } - - /** - * @return AuthMechanism - */ - public function getAuthMechanism() { - return $this->authMechanism; - } - - /** - * @param AuthMechanism $authMechanism - */ - public function setAuthMechanism(AuthMechanism $authMechanism) { - $this->authMechanism = $authMechanism; - } - - /** - * Returns the external storage backend-specific options - * - * @return array backend options - */ - public function getBackendOptions() { - return $this->backendOptions; - } - - /** - * Sets the external storage backend-specific options - * - * @param array $backendOptions backend options - */ - public function setBackendOptions($backendOptions) { - if($this->getBackend() instanceof Backend) { - $parameters = $this->getBackend()->getParameters(); - foreach($backendOptions as $key => $value) { - if(isset($parameters[$key])) { - switch ($parameters[$key]->getType()) { - case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: - $value = (bool)$value; - break; - } - $backendOptions[$key] = $value; - } - } - } - - $this->backendOptions = $backendOptions; - } - - /** - * @param string $key - * @return mixed - */ - public function getBackendOption($key) { - if (isset($this->backendOptions[$key])) { - return $this->backendOptions[$key]; - } - return null; - } - - /** - * @param string $key - * @param mixed $value - */ - public function setBackendOption($key, $value) { - $this->backendOptions[$key] = $value; - } - - /** - * Returns the mount priority - * - * @return int priority - */ - public function getPriority() { - return $this->priority; - } - - /** - * Sets the mount priotity - * - * @param int $priority priority - */ - public function setPriority($priority) { - $this->priority = $priority; - } - - /** - * Returns the users for which to mount this storage - * - * @return array applicable users - */ - public function getApplicableUsers() { - return $this->applicableUsers; - } - - /** - * Sets the users for which to mount this storage - * - * @param array|null $applicableUsers applicable users - */ - public function setApplicableUsers($applicableUsers) { - if (is_null($applicableUsers)) { - $applicableUsers = []; - } - $this->applicableUsers = $applicableUsers; - } - - /** - * Returns the groups for which to mount this storage - * - * @return array applicable groups - */ - public function getApplicableGroups() { - return $this->applicableGroups; - } - - /** - * Sets the groups for which to mount this storage - * - * @param array|null $applicableGroups applicable groups - */ - public function setApplicableGroups($applicableGroups) { - if (is_null($applicableGroups)) { - $applicableGroups = []; - } - $this->applicableGroups = $applicableGroups; - } - - /** - * Returns the mount-specific options - * - * @return array mount specific options - */ - public function getMountOptions() { - return $this->mountOptions; - } - - /** - * Sets the mount-specific options - * - * @param array $mountOptions applicable groups - */ - public function setMountOptions($mountOptions) { - if (is_null($mountOptions)) { - $mountOptions = []; - } - $this->mountOptions = $mountOptions; - } - - /** - * @param string $key - * @return mixed - */ - public function getMountOption($key) { - if (isset($this->mountOptions[$key])) { - return $this->mountOptions[$key]; - } - return null; - } - - /** - * @param string $key - * @param mixed $value - */ - public function setMountOption($key, $value) { - $this->mountOptions[$key] = $value; - } - - /** - * Gets the storage status, whether the config worked last time - * - * @return int $status status - */ - public function getStatus() { - return $this->status; - } - - /** - * Gets the message describing the storage status - * - * @return string|null - */ - public function getStatusMessage() { - return $this->statusMessage; - } - - /** - * Sets the storage status, whether the config worked last time - * - * @param int $status status - * @param string|null $message optional message - */ - public function setStatus($status, $message = null) { - $this->status = $status; - $this->statusMessage = $message; - } - - /** - * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl - */ - public function getType() { - return $this->type; - } - - /** - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl - */ - public function setType($type) { - $this->type = $type; - } - - /** - * Serialize config to JSON - * - * @return array - */ - public function jsonSerialize() { - $result = []; - if (!is_null($this->id)) { - $result['id'] = $this->id; - } - $result['mountPoint'] = $this->mountPoint; - $result['backend'] = $this->backend->getIdentifier(); - $result['authMechanism'] = $this->authMechanism->getIdentifier(); - $result['backendOptions'] = $this->backendOptions; - if (!is_null($this->priority)) { - $result['priority'] = $this->priority; - } - if (!empty($this->applicableUsers)) { - $result['applicableUsers'] = $this->applicableUsers; - } - if (!empty($this->applicableGroups)) { - $result['applicableGroups'] = $this->applicableGroups; - } - if (!empty($this->mountOptions)) { - $result['mountOptions'] = $this->mountOptions; - } - if (!is_null($this->status)) { - $result['status'] = $this->status; - } - if (!is_null($this->statusMessage)) { - $result['statusMessage'] = $this->statusMessage; - } - $result['userProvided'] = $this->authMechanism instanceof IUserProvided; - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; - return $result; - } -} diff --git a/apps/files_external/lib/storagemodifiertrait.php b/apps/files_external/lib/storagemodifiertrait.php deleted file mode 100644 index 30c2108feec..00000000000 --- a/apps/files_external/lib/storagemodifiertrait.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCP\IUser; -use \OCP\Files\Storage; -use \OCA\Files_External\Lib\StorageConfig; -use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; -use \OCP\Files\StorageNotAvailableException; - -/** - * Trait for objects that can modify StorageConfigs and wrap Storages - * - * When a storage implementation is being prepared for use, the StorageConfig - * 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 - * a wrapped storage that changes its behaviour. - * - * Certain configuration options need to be set before the implementation is - * constructed, while others are retrieved directly from the storage - * implementation and so need a wrapper to be modified. - */ -trait StorageModifierTrait { - - /** - * Modify a StorageConfig parameters - * - * @param StorageConfig $storage - * @param IUser $user User the storage is being used as - * @throws InsufficientDataForMeaningfulAnswerException - * @throws StorageNotAvailableException - */ - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { - } - - /** - * Wrap a Storage if necessary - * - * @param Storage $storage - * @return Storage - * @throws InsufficientDataForMeaningfulAnswerException - * @throws StorageNotAvailableException - */ - public function wrapStorage(Storage $storage) { - return $storage; - } - -} - diff --git a/apps/files_external/lib/visibilitytrait.php b/apps/files_external/lib/visibilitytrait.php deleted file mode 100644 index 916c8e69d9c..00000000000 --- a/apps/files_external/lib/visibilitytrait.php +++ /dev/null @@ -1,136 +0,0 @@ - - * - * @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 OCA\Files_External\Lib; - -use \OCA\Files_External\Service\BackendService; - -/** - * Trait to implement visibility mechanics for a configuration class - * - * The standard visibility defines which users/groups can use or see the - * object. The allowed visibility defines the maximum visibility allowed to be - * set on the object. The standard visibility is often set dynamically by - * stored configuration parameters that can be modified by the administrator, - * while the allowed visibility is set directly by the object and cannot be - * modified by the administrator. - */ -trait VisibilityTrait { - - /** @var int visibility */ - protected $visibility = BackendService::VISIBILITY_DEFAULT; - - /** @var int allowed visibilities */ - protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT; - - /** - * @return int - */ - public function getVisibility() { - return $this->visibility; - } - - /** - * Check if the backend is visible for a user type - * - * @param int $visibility - * @return bool - */ - public function isVisibleFor($visibility) { - if ($this->visibility & $visibility) { - return true; - } - return false; - } - - /** - * @param int $visibility - * @return self - */ - public function setVisibility($visibility) { - $this->visibility = $visibility; - $this->allowedVisibility |= $visibility; - return $this; - } - - /** - * @param int $visibility - * @return self - */ - public function addVisibility($visibility) { - return $this->setVisibility($this->visibility | $visibility); - } - - /** - * @param int $visibility - * @return self - */ - public function removeVisibility($visibility) { - return $this->setVisibility($this->visibility & ~$visibility); - } - - /** - * @return int - */ - public function getAllowedVisibility() { - return $this->allowedVisibility; - } - - /** - * Check if the backend is allowed to be visible for a user type - * - * @param int $allowedVisibility - * @return bool - */ - public function isAllowedVisibleFor($allowedVisibility) { - if ($this->allowedVisibility & $allowedVisibility) { - return true; - } - return false; - } - - /** - * @param int $allowedVisibility - * @return self - */ - public function setAllowedVisibility($allowedVisibility) { - $this->allowedVisibility = $allowedVisibility; - $this->visibility &= $allowedVisibility; - return $this; - } - - /** - * @param int $allowedVisibility - * @return self - */ - public function addAllowedVisibility($allowedVisibility) { - return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility); - } - - /** - * @param int $allowedVisibility - * @return self - */ - public function removeAllowedVisibility($allowedVisibility) { - return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility); - } - -} -- cgit v1.2.3