Skip to content

Commit

Permalink
Merge pull request #6483 from nextcloud/backport/6290/stable4.7
Browse files Browse the repository at this point in the history
[stable4.7] fix(teams): resolve undefined variable error and add logging
  • Loading branch information
st3iny authored Nov 11, 2024
2 parents a76603c + 2b1f393 commit e0e6ee7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
27 changes: 17 additions & 10 deletions lib/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +42,7 @@
use OCP\Contacts\IManager;
use OCP\IRequest;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

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

Expand All @@ -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[] = [
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 @@ -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 */
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e0e6ee7

Please sign in to comment.