Skip to content

Commit e0e6ee7

Browse files
authored
Merge pull request #6483 from nextcloud/backport/6290/stable4.7
[stable4.7] fix(teams): resolve undefined variable error and add logging
2 parents a76603c + 2b1f393 commit e0e6ee7

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

lib/Controller/ContactController.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*/
3131
namespace OCA\Calendar\Controller;
3232

33+
use Exception;
3334
use OCA\Calendar\Service\ServiceException;
35+
use OCA\Circles\Api\v1\Circles;
3436
use OCA\Circles\Exceptions\CircleNotFoundException;
3537
use OCP\App\IAppManager;
3638
use OCP\AppFramework\Controller;
@@ -40,6 +42,7 @@
4042
use OCP\Contacts\IManager;
4143
use OCP\IRequest;
4244
use OCP\IUserManager;
45+
use Psr\Log\LoggerInterface;
4346

4447
/**
4548
* Class ContactController
@@ -63,11 +66,14 @@ class ContactController extends Controller {
6366
* @param IRequest $request
6467
* @param IManager $contacts
6568
*/
66-
public function __construct(string $appName,
69+
public function __construct(
70+
string $appName,
6771
IRequest $request,
6872
IManager $contacts,
6973
IAppManager $appManager,
70-
IUserManager $userManager) {
74+
IUserManager $userManager,
75+
private LoggerInterface $logger,
76+
) {
7177
parent::__construct($appName, $request);
7278
$this->contactsManager = $contacts;
7379
$this->appManager = $appManager;
@@ -196,32 +202,32 @@ public function searchAttendee(string $search):JSONResponse {
196202
* @param string $circleId CircleId to query for members
197203
* @return JSONResponse
198204
* @throws Exception
199-
* @throws \OCP\AppFramework\QueryException
200205
*
201206
* @NoAdminRequired
202207
*/
203208
public function getCircleMembers(string $circleId):JSONResponse {
204-
if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
209+
if (!class_exists('\OCA\Circles\Api\v1\Circles') || !$this->appManager->isEnabledForUser('circles')) {
210+
$this->logger->debug('Circles not enabled');
205211
return new JSONResponse();
206212
}
207213
if (!$this->contactsManager->isEnabled()) {
214+
$this->logger->debug('Contacts not enabled');
208215
return new JSONResponse();
209216
}
210217

211218
try {
212-
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId, true);
219+
$circle = Circles::detailsCircle($circleId, true);
213220
} catch (QueryException $ex) {
221+
$this->logger->error('Could not resolve circle details', ['exception' => $ex]);
214222
return new JSONResponse();
215223
} catch (CircleNotFoundException $ex) {
216-
return new JSONResponse();
217-
}
218-
219-
if (!$circle) {
224+
$this->logger->error('Could not find circle', ['exception' => $ex]);
220225
return new JSONResponse();
221226
}
222227

223228
$circleMembers = $circle->getInheritedMembers();
224229

230+
$contacts = [];
225231
foreach ($circleMembers as $circleMember) {
226232
if ($circleMember->isLocal()) {
227233

@@ -230,7 +236,8 @@ public function getCircleMembers(string $circleId):JSONResponse {
230236
$user = $this->userManager->get($circleMemberUserId);
231237

232238
if ($user === null) {
233-
throw new ServiceException('Could not find organizer');
239+
$this->logger->error('Could not find user with user id' . $circleMemberUserId);
240+
throw new ServiceException('Could not find circle member');
234241
}
235242

236243
$contacts[] = [

tests/php/unit/Controller/ContactControllerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\IRequest;
3131
use OCP\IUserManager;
3232
use PHPUnit\Framework\MockObject\MockObject;
33+
use Psr\Log\LoggerInterface;
3334

3435
class ContactControllerTest extends TestCase {
3536
/** @var string */
@@ -58,8 +59,14 @@ protected function setUp():void {
5859
$this->manager = $this->createMock(IManager::class);
5960
$this->appManager = $this->createMock(IAppManager::class);
6061
$this->userManager = $this->createMock(IUserManager::class);
62+
$this->logger = $this->createMock(LoggerInterface::class);
6163
$this->controller = new ContactController($this->appName,
62-
$this->request, $this->manager, $this->appManager, $this->userManager);
64+
$this->request,
65+
$this->manager,
66+
$this->appManager,
67+
$this->userManager,
68+
$this->logger,
69+
);
6370
}
6471

6572
public function testSearchLocationDisabled():void {

0 commit comments

Comments
 (0)