diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2017-10-20 19:34:36 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2017-10-20 19:34:36 +0300 |
commit | 2397af8a413f30685c27d81fbcbcea469112efc4 (patch) | |
tree | b91bf1329ff5ebe4882897abf24e1ca21b06a7b7 /lib | |
parent | b39762fd12d3a155390a299326671e89fd656266 (diff) |
moving files/methods around
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Api/v1/Circles.php | 18 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 138 | ||||
-rw-r--r-- | lib/Db/CircleProviderRequest.php | 106 | ||||
-rw-r--r-- | lib/Db/CircleProviderRequestBuilder.php | 7 | ||||
-rw-r--r-- | lib/Service/CirclesService.php | 33 | ||||
-rw-r--r-- | lib/ShareByCircleProvider.php | 95 |
6 files changed, 211 insertions, 186 deletions
diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php index dced9d7f..bbb08d9e 100644 --- a/lib/Api/v1/Circles.php +++ b/lib/Api/v1/Circles.php @@ -452,24 +452,16 @@ class Circles { /** * Get a list of objects which are shred with $circleUniqueId. * - * @param string|array $tagIds Tag id or array of tag ids. - * @param string $objectType object type - * @param int $limit Count of object ids you want to get - * @param string $offset The last object id you already received + * @since 0.14.0 * - * @return string[] array of object ids or empty array if none found - * - * @throws \OCP\SystemTag\TagNotFoundException if at least one of the - * given tags does not exist - * @throws \InvalidArgumentException When a limit is specified together with - * multiple tag ids + * @param array $circleUniqueIds * - * @since 9.0.0 + * @return string[] array of object ids or empty array if none found */ - public static function getObjectIdsForCircles($circleUniqueIds) { + public static function getFilesForCircles($circleUniqueIds) { $c = self::getContainer(); return $c->query(CirclesService::class) - ->getObjectIdsForCircles($circleUniqueIds); + ->getFilesForCircles($circleUniqueIds); } }
\ No newline at end of file diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 27b2c001..a0c95821 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -29,33 +29,13 @@ namespace OCA\Circles\AppInfo; -use OCA\Circles\Controller\FederatedController; -use OCA\Circles\Controller\GroupsController; -use OCA\Circles\Controller\NavigationController; -use OCA\Circles\Controller\CirclesController; -use OCA\Circles\Controller\MembersController; - - -use OCA\Circles\Controller\SettingsController; -use OCA\Circles\Controller\SharesController; -use OCA\Circles\Db\CirclesRequest; -use OCA\Circles\Db\FederatedLinksRequest; -use OCA\Circles\Db\MembersRequest; -use OCA\Circles\Events\UserEvents; -use OCA\Circles\Service\BroadcastService; -use OCA\Circles\Service\CirclesService; -use OCA\Circles\Service\EventsService; -use OCA\Circles\Service\FederatedLinkService; -use OCA\Circles\Service\GroupsService; -use OCA\Circles\Service\MembersService; -use OCA\Circles\Service\ConfigService; -use OCA\Circles\Service\MiscService; -use OCA\Circles\Service\SearchService; -use OCA\Circles\Service\SharingFrameService; +use OCA\Circles\Api\v1\Circles; +use OCA\Files\App as FilesApp; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\Util; + class Application extends App { const APP_NAME = 'circles'; @@ -65,17 +45,18 @@ class Application extends App { const CLIENT_TIMEOUT = 3; + /** @var IAppContainer */ + private $container; + /** * @param array $params */ public function __construct(array $params = array()) { parent::__construct(self::APP_NAME, $params); - $container = $this->getContainer(); + $this->container = $this->getContainer(); - // TODO: POURQUOI SELF:: ??!?? - self::registerEvents($container); - self::registerHooks(); + $this->registerHooks(); } @@ -93,58 +74,31 @@ class Application extends App { /** - * Register Events - * - * @param IAppContainer $container - */ - public function registerEvents(IAppContainer $container) { -// $container->registerService( -// 'UserEvents', function(IAppContainer $c) { -// return new UserEvents( -// $c->query('MembersService'), $c->query('GroupsService'), $c->query('MiscService') -// ); -// } -// ); - } - - - /** * Register Navigation elements */ public function registerNavigation() { - // Register Navigation Tab - $this->getContainer() - ->getServer() - ->getNavigationManager() - ->add( - function() { - $urlGen = \OC::$server->getURLGenerator(); - $navName = \OC::$server->getL10N(self::APP_NAME) - ->t('Circles'); - - return [ - 'id' => self::APP_NAME, - 'order' => 5, - 'href' => $urlGen->linkToRoute('circles.Navigation.navigate'), - 'icon' => $urlGen->imagePath(self::APP_NAME, 'circles.svg'), - 'name' => $navName - ]; - } - ); - - // Register Navigation in FileList - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('circles'); - return [ - 'id' => 'circlesfilter', - 'appname' => 'circles', - 'script' => 'list.php', - 'order' => 25, - 'name' => $l->t('Circles'), - ]; - }); + + $appManager = $this->container->getServer() + ->getNavigationManager(); + $appManager->add( + function() { + $urlGen = \OC::$server->getURLGenerator(); + $navName = \OC::$server->getL10N(self::APP_NAME) + ->t('Circles'); + + return [ + 'id' => self::APP_NAME, + 'order' => 5, + 'href' => $urlGen->linkToRoute('circles.Navigation.navigate'), + 'icon' => $urlGen->imagePath(self::APP_NAME, 'circles.svg'), + 'name' => $navName + ]; + } + ); + } + public function registerSettingsAdmin() { \OCP\App::registerAdmin(self::APP_NAME, 'lib/admin'); } @@ -154,19 +108,37 @@ class Application extends App { $eventDispatcher->addListener( 'OCA\Files::loadAdditionalScripts', function() { - // FIXME: no public API for these ? - \OCP\Util::addScript('circles', 'circles.v1.circles'); - \OCP\Util::addScript('circles', 'circles.v1.links'); - \OCP\Util::addScript('circles', 'circles.v1.members'); - \OCP\Util::addScript('circles', 'circles.v1'); + Circles::addJavascriptAPI(); + + Util::addScript('circles', 'files/circles.files.app'); + Util::addScript('circles', 'files/circles.files.list'); + + Util::addStyle('circles', 'files/circles.filelist'); + } + ); + } - \OCP\Util::addScript('circles', 'circles.files.app'); - \OCP\Util::addScript('circles', 'circles.files.list'); - \OCP\Util::addStyle('circles'); - \OCP\Util::addStyle('circles', 'circles.filelist'); + /** + * + */ + public function registerFilesNavigation() { + + $appManager = FilesApp::getNavigationManager(); + $appManager->add( + function() { + $l = \OC::$server->getL10N('circles'); + + return [ + 'id' => 'circlesfilter', + 'appname' => 'circles', + 'script' => 'files/list.php', + 'order' => 25, + 'name' => $l->t('Shared to Circles'), + ]; } ); } + } diff --git a/lib/Db/CircleProviderRequest.php b/lib/Db/CircleProviderRequest.php new file mode 100644 index 00000000..5b5af1b2 --- /dev/null +++ b/lib/Db/CircleProviderRequest.php @@ -0,0 +1,106 @@ +<?php +/** + * Circles - Bring cloud-users closer together. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\Circles\Db; + + +use OCA\Circles\Model\Member; + +class CircleProviderRequest extends CircleProviderRequestBuilder { + + + /** + * @param $userId + * @param $circleUniqueIds + * @param $limit + * @param $offset + * + * @return array + */ + public function getFilesForCircles($userId, $circleUniqueIds, $limit, $offset) { + + $qb = $this->getCompleteSelectSql(); + $this->linkToFileCache($qb, $userId); + $this->limitToPage($qb, $limit, $offset); + $this->limitToCircles($qb, $circleUniqueIds); + + $this->linkToMember($qb, $userId, $this->configService->isLinkedGroupsAllowed()); + + $this->leftJoinShareInitiator($qb); + $cursor = $qb->execute(); + + $object_ids = []; + while ($data = $cursor->fetch()) { + + if ($data['initiator_circle_level'] < Member::LEVEL_MEMBER + && ($data['initiator_group_level'] < Member::LEVEL_MEMBER + || !$this->configService->isLinkedGroupsAllowed()) + ) { + continue; + } + + self::editShareFromParentEntry($data); + if (self::isAccessibleResult($data)) { + $object_ids[] = $data['file_source']; + } + } + $cursor->closeCursor(); + + return $object_ids; + } + + + /** + * Returns whether the given database result can be interpreted as + * a share with accessible file (not trashed, not deleted) + * + * @param $data + *F + * + * @return bool + */ + protected static function isAccessibleResult($data) { + if ($data['fileid'] === null) { + return false; + } + + return (!(explode('/', $data['path'], 2)[0] !== 'files' + && explode(':', $data['storage_string_id'], 2)[0] === 'home')); + } + + + /** + * @param $data + */ + protected static function editShareFromParentEntry(&$data) { + if ($data['parent_id'] > 0) { + $data['permissions'] = $data['parent_perms']; + $data['file_target'] = $data['parent_target']; + } + } + +}
\ No newline at end of file diff --git a/lib/Db/CircleProviderRequestBuilder.php b/lib/Db/CircleProviderRequestBuilder.php index d37c65fd..2fb98ad9 100644 --- a/lib/Db/CircleProviderRequestBuilder.php +++ b/lib/Db/CircleProviderRequestBuilder.php @@ -35,15 +35,10 @@ use Doctrine\DBAL\Query\QueryBuilder; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; use OCP\Share; use OCP\Share\IShare; -class CircleProviderRequestBuilder { - - - /** @var IDBConnection */ - protected $dbConnection; +class CircleProviderRequestBuilder extends CoreRequestBuilder { /** diff --git a/lib/Service/CirclesService.php b/lib/Service/CirclesService.php index 2836f4fa..ecf0097d 100644 --- a/lib/Service/CirclesService.php +++ b/lib/Service/CirclesService.php @@ -31,13 +31,13 @@ namespace OCA\Circles\Service; use OCA\Circles\AppInfo\Application; +use OCA\Circles\Db\CircleProviderRequest; use OCA\Circles\Db\CirclesRequest; use OCA\Circles\Db\FederatedLinksRequest; use OCA\Circles\Db\MembersRequest; use OCA\Circles\Exceptions\CircleAlreadyExistsException; use OCA\Circles\Exceptions\CircleTypeDisabledException; use OCA\Circles\Exceptions\FederatedCircleNotAllowedException; -use OCA\Circles\Exceptions\MemberDoesNotExistException; use OCA\Circles\Exceptions\MemberIsNotOwnerException; use OCA\Circles\Model\Circle; use OCA\Circles\Model\Member; @@ -67,12 +67,12 @@ class CirclesService { /** @var EventsService */ private $eventsService; + /** @var CircleProviderRequest */ + private $circleProviderRequest; + /** @var MiscService */ private $miscService; - /** @var ShareByCircleProvider */ - private $shareProvider; - /** * CirclesService constructor. @@ -84,6 +84,7 @@ class CirclesService { * @param MembersRequest $membersRequest * @param FederatedLinksRequest $federatedLinksRequest * @param EventsService $eventsService + * @param CircleProviderRequest $circleProviderRequest * @param MiscService $miscService */ public function __construct( @@ -94,8 +95,8 @@ class CirclesService { MembersRequest $membersRequest, FederatedLinksRequest $federatedLinksRequest, EventsService $eventsService, - MiscService $miscService, - ShareByCircleProvider $shareProvider + CircleProviderRequest $circleProviderRequest, + MiscService $miscService ) { $this->userId = $userId; $this->l10n = $l10n; @@ -104,8 +105,8 @@ class CirclesService { $this->membersRequest = $membersRequest; $this->federatedLinksRequest = $federatedLinksRequest; $this->eventsService = $eventsService; + $this->circleProviderRequest = $circleProviderRequest; $this->miscService = $miscService; - $this->shareProvider = $shareProvider; } @@ -302,7 +303,9 @@ class CirclesService { try { $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); - $member = $this->membersRequest->getFreshNewMember($circleUniqueId, $this->userId, Member::TYPE_USER); + $member = $this->membersRequest->getFreshNewMember( + $circleUniqueId, $this->userId, Member::TYPE_USER + ); $member->hasToBeAbleToJoinTheCircle(); $member->joinCircle($circle->getType()); $this->membersRequest->updateMember($member); @@ -444,12 +447,22 @@ class CirclesService { return $urlGen->getAbsoluteURL($urlGen->imagePath(Application::APP_NAME, 'black_circle' . $ext)); } - public function getObjectIdsForCircles($circleUniqueIds, $limit = -1, $offset = 0) { + + /** + * @param string $circleUniqueIds + * @param int $limit + * @param int $offset + * + * @return array + */ + public function getFilesForCircles($circleUniqueIds, $limit = -1, $offset = 0) { if (!is_array($circleUniqueIds)) { $circleUniqueIds = [$circleUniqueIds]; } - $objectIds = $this->shareProvider->getObjectIdsForCircles($this->userId, $circleUniqueIds, $limit, $offset); + $objectIds = $this->circleProviderRequest->getFilesForCircles( + $this->userId, $circleUniqueIds, $limit, $offset + ); return $objectIds; } diff --git a/lib/ShareByCircleProvider.php b/lib/ShareByCircleProvider.php index 82ef21cb..06ddae47 100644 --- a/lib/ShareByCircleProvider.php +++ b/lib/ShareByCircleProvider.php @@ -36,7 +36,7 @@ use OC\Share20\Exception\InvalidShare; use OC\Share20\Share; use OCA\Circles\Api\v1\Circles; use OCA\Circles\AppInfo\Application; -use OCA\Circles\Db\CircleProviderRequestBuilder; +use OCA\Circles\Db\CircleProviderRequest; use OCA\Circles\Db\CirclesRequest; use OCA\Circles\Db\MembersRequest; use OCA\Circles\Model\Circle; @@ -58,7 +58,8 @@ use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IShare; use OCP\Share\IShareProvider; -class ShareByCircleProvider extends CircleProviderRequestBuilder implements IShareProvider { + +class ShareByCircleProvider extends CircleProviderRequest implements IShareProvider { /** @var IDBConnection */ protected $dbConnection; @@ -109,23 +110,20 @@ class ShareByCircleProvider extends CircleProviderRequestBuilder implements ISha IDBConnection $connection, ISecureRandom $secureRandom, IUserManager $userManager, IRootFolder $rootFolder, IL10N $l10n, ILogger $logger, IURLGenerator $urlGenerator ) { - $this->dbConnection = $connection; + $app = new Application(); + $container = $app->getContainer(); + $configService = $container->query(ConfigService::class); + $miscService = $container->query(MiscService::class); + + parent::__construct($l10n, $connection, $configService, $miscService); + $this->secureRandom = $secureRandom; $this->userManager = $userManager; $this->rootFolder = $rootFolder; - $this->l10n = $l10n; $this->logger = $logger; $this->urlGenerator = $urlGenerator; - - $app = new Application(); - $this->circlesRequest = $app->getContainer() - ->query(CirclesRequest::class); - $this->membersRequest = $app->getContainer() - ->query(MembersRequest::class); - $this->configService = $app->getContainer() - ->query(ConfigService::class); - $this->miscService = $app->getContainer() - ->query(MiscService::class); + $this->circlesRequest = $container->query(CirclesRequest::class); + $this->membersRequest = $container->query(MembersRequest::class); } @@ -450,6 +448,15 @@ class ShareByCircleProvider extends CircleProviderRequestBuilder implements ISha } + /** + * @param string $userId + * @param $shareType + * @param Node $node + * @param int $limit + * @param int $offset + * + * @return array + */ private function getSharedWithCircleMembers($userId, $shareType, $node, $limit, $offset) { $qb = $this->getCompleteSelectSql(); @@ -485,16 +492,6 @@ class ShareByCircleProvider extends CircleProviderRequestBuilder implements ISha return $shares; } - /** - * @param $data - */ - private static function editShareFromParentEntry(&$data) { - if ($data['parent_id'] > 0) { - $data['permissions'] = $data['parent_perms']; - $data['file_target'] = $data['parent_target']; - } - } - /** * Get a share by token @@ -538,37 +535,6 @@ class ShareByCircleProvider extends CircleProviderRequestBuilder implements ISha return $share; } - public function getObjectIdsForCircles($userId, $circleUniqueIds, $limit, $offset) { - - $qb = $this->getCompleteSelectSql(); - $this->linkToFileCache($qb, $userId); - $this->limitToPage($qb, $limit, $offset); - $this->limitToCircles($qb, $circleUniqueIds); - - $this->linkToMember($qb, $userId, $this->configService->isLinkedGroupsAllowed()); - - $this->leftJoinShareInitiator($qb); - $cursor = $qb->execute(); - - $object_ids = []; - while ($data = $cursor->fetch()) { - - if ($data['initiator_circle_level'] < Member::LEVEL_MEMBER - && ($data['initiator_group_level'] < Member::LEVEL_MEMBER - || !$this->configService->isLinkedGroupsAllowed()) - ) { - continue; - } - - self::editShareFromParentEntry($data); - if (self::isAccessibleResult($data)) { - $object_ids[] = $data['file_source']; - } - } - $cursor->closeCursor(); - - return $object_ids; - } /** * We don't return a thing about children. @@ -692,25 +658,6 @@ class ShareByCircleProvider extends CircleProviderRequestBuilder implements ISha /** - * Returns whether the given database result can be interpreted as - * a share with accessible file (not trashed, not deleted) - * - * @param $data - *F - * - * @return bool - */ - private static function isAccessibleResult($data) { - if ($data['fileid'] === null) { - return false; - } - - return (!(explode('/', $data['path'], 2)[0] !== 'files' - && explode(':', $data['storage_string_id'], 2)[0] === 'home')); - } - - - /** * @param IShare $share * * @return \Exception |