diff --git a/lib/Controller/ContactController.php b/lib/Controller/ContactController.php index af1ee7518..06c44cb8a 100644 --- a/lib/Controller/ContactController.php +++ b/lib/Controller/ContactController.php @@ -7,7 +7,9 @@ */ namespace OCA\Calendar\Controller; +use Exception; use OCA\Calendar\Service\ServiceException; +use OCA\Circles\Api\v1\Circles; use OCA\Circles\Exceptions\CircleNotFoundException; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -17,6 +19,7 @@ use OCP\Contacts\IManager; use OCP\IRequest; use OCP\IUserManager; +use Psr\Log\LoggerInterface; /** * Class ContactController @@ -44,7 +47,9 @@ public function __construct(string $appName, IRequest $request, IManager $contacts, IAppManager $appManager, - IUserManager $userManager) { + IUserManager $userManager, + private LoggerInterface $logger, + ) { parent::__construct($appName, $request); $this->contactsManager = $contacts; $this->appManager = $appManager; @@ -173,32 +178,32 @@ public function searchAttendee(string $search):JSONResponse { * @param string $circleId CircleId to query for members * @return JSONResponse * @throws Exception - * @throws \OCP\AppFramework\QueryException * * @NoAdminRequired */ public function getCircleMembers(string $circleId):JSONResponse { - if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { + if (!class_exists('\OCA\Circles\Api\v1\Circles') || !$this->appManager->isEnabledForUser('circles')) { + $this->logger->debug('Circles not enabled'); return new JSONResponse(); } if (!$this->contactsManager->isEnabled()) { + $this->logger->debug('Contacts not enabled'); return new JSONResponse(); } try { - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId, true); + $circle = Circles::detailsCircle($circleId, true); } catch (QueryException $ex) { + $this->logger->error('Could not resolve circle details', ['exception' => $ex]); return new JSONResponse(); } catch (CircleNotFoundException $ex) { - return new JSONResponse(); - } - - if (!$circle) { + $this->logger->error('Could not find circle', ['exception' => $ex]); return new JSONResponse(); } $circleMembers = $circle->getInheritedMembers(); + $contacts = []; foreach ($circleMembers as $circleMember) { if ($circleMember->isLocal()) { @@ -207,7 +212,8 @@ public function getCircleMembers(string $circleId):JSONResponse { $user = $this->userManager->get($circleMemberUserId); if ($user === null) { - throw new ServiceException('Could not find organizer'); + $this->logger->error('Could not find user with user id' . $circleMemberUserId); + throw new ServiceException('Could not find circle member'); } $contacts[] = [ diff --git a/tests/php/unit/Controller/ContactControllerTest.php b/tests/php/unit/Controller/ContactControllerTest.php index 3b176ee3c..57e88f998 100644 --- a/tests/php/unit/Controller/ContactControllerTest.php +++ b/tests/php/unit/Controller/ContactControllerTest.php @@ -14,6 +14,7 @@ use OCP\IRequest; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class ContactControllerTest extends TestCase { /** @var string */ @@ -42,8 +43,14 @@ protected function setUp():void { $this->manager = $this->createMock(IManager::class); $this->appManager = $this->createMock(IAppManager::class); $this->userManager = $this->createMock(IUserManager::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->controller = new ContactController($this->appName, - $this->request, $this->manager, $this->appManager, $this->userManager); + $this->request, + $this->manager, + $this->appManager, + $this->userManager, + $this->logger, + ); } public function testSearchLocationDisabled():void {