diff --git a/lib/Controller/ContactController.php b/lib/Controller/ContactController.php index c7b6d9acd..58eae0d4c 100644 --- a/lib/Controller/ContactController.php +++ b/lib/Controller/ContactController.php @@ -30,7 +30,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; @@ -40,6 +42,7 @@ use OCP\Contacts\IManager; use OCP\IRequest; use OCP\IUserManager; +use Psr\Log\LoggerInterface; /** * Class ContactController @@ -63,11 +66,14 @@ class ContactController extends Controller { * @param IRequest $request * @param IManager $contacts */ - public function __construct(string $appName, + 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; @@ -196,32 +202,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()) { @@ -230,7 +236,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 98f4d1bbc..6cf411175 100644 --- a/tests/php/unit/Controller/ContactControllerTest.php +++ b/tests/php/unit/Controller/ContactControllerTest.php @@ -30,6 +30,7 @@ use OCP\IRequest; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class ContactControllerTest extends TestCase { /** @var string */ @@ -58,8 +59,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 {