Skip to content

Commit

Permalink
fix(teams): resolve undefined variable error and add logging
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <[email protected]>
  • Loading branch information
miaulalala committed Nov 4, 2024
1 parent dd6aaec commit 56ca9af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,7 @@
use OCP\Contacts\IManager;
use OCP\IRequest;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
* Class ContactController
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {

Expand All @@ -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[] = [
Expand Down
9 changes: 8 additions & 1 deletion tests/php/unit/Controller/ContactControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 56ca9af

Please sign in to comment.