From c57f2a51b9a489dfa0c128cdff198ba579221682 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 10 Aug 2021 10:37:04 -0100 Subject: [PATCH] Using CirclesManager Signed-off-by: Maxence Lange --- lib/Service/SearchService.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 8cdfe613..dd8737e0 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -31,11 +31,15 @@ namespace OCA\FullTextSearch\Service; +use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; use Exception; +use OC; use OC\App\AppManager; use OC\FullTextSearch\Model\DocumentAccess; use OC\User\NoUserException; -use OCA\Circles\Api\v1\Circles; +use OCA\Circles\CirclesManager; +use OCA\Circles\Model\Circle; +use OCA\FullTextSearch\AppInfo\Application; use OCA\FullTextSearch\Exceptions\EmptySearchException; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; use OCA\FullTextSearch\Model\SearchRequest; @@ -59,6 +63,9 @@ class SearchService implements ISearchService { + use TNC22Logger; + + /** @var string */ private $userId; @@ -111,6 +118,8 @@ public function __construct( $this->providerService = $providerService; $this->platformService = $platformService; $this->miscService = $miscService; + + $this->setup('app', Application::APP_ID); } @@ -215,16 +224,19 @@ private function getDocumentAccessFromUser(IUser $user): IDocumentAccess { $rights->setViewerId($user->getUID()); $rights->setGroups($this->groupManager->getUserGroupIds($user)); - if ($this->appManager->isEnabledForUser('circles', $user)) { - try { - $rights->setCircles(Circles::joinedCircleIds($user->getUID())); - } catch (Exception $e) { - $this->miscService->log('Circles is set as enabled but: ' . $e->getMessage()); - } + try { + /** @var CirclesManager $circleManager */ + $circleManager = OC::$server->get(CirclesManager::class); + $circleManager->startsession(); + $circleIds = array_map( + function (Circle $circle): string { + return $circle->getSingleId(); + }, $circleManager->getCircles() + ); + $rights->setCircles($circleIds); + } catch (Exception $e) { } return $rights; } - - }