Skip to content

Commit

Permalink
Catch any error during circle detail fetching
Browse files Browse the repository at this point in the history
Signed-off-by: Julius H盲rtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed May 3, 2021
1 parent ef044ca commit fbcad7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
16 changes: 10 additions & 6 deletions lib/Db/BoardMapper.php
Expand Up @@ -25,16 +25,17 @@

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\IGroupManager;
use Psr\Log\LoggerInterface;

class BoardMapper extends DeckMapper implements IPermissionMapper {
private $labelMapper;
private $aclMapper;
private $stackMapper;
private $userManager;
private $groupManager;
private $logger;

private $circlesEnabled;

Expand All @@ -44,14 +45,16 @@ public function __construct(
AclMapper $aclMapper,
StackMapper $stackMapper,
IUserManager $userManager,
IGroupManager $groupManager
IGroupManager $groupManager,
LoggerInterface $logger
) {
parent::__construct($db, 'deck_boards', Board::class);
$this->labelMapper = $labelMapper;
$this->aclMapper = $aclMapper;
$this->stackMapper = $stackMapper;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->logger = $logger;

$this->circlesEnabled = \OC::$server->getAppManager()->isEnabledForUser('circles');
}
Expand Down Expand Up @@ -248,15 +251,15 @@ public function mapAcl(Acl &$acl) {
if ($user !== null) {
return new User($user);
}
\OC::$server->getLogger()->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
$this->logger->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
return null;
}
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
$group = $groupManager->get($participant);
if ($group !== null) {
return new Group($group);
}
\OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
$this->logger->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant());
return null;
}
if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE) {
Expand All @@ -268,11 +271,12 @@ public function mapAcl(Acl &$acl) {
if ($circle) {
return new Circle($circle);
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
$this->logger->error('Failed to get circle details when building ACL', ['exception' => $e]);
}
return null;
}
\OC::$server->getLogger()->log(ILogger::WARN, 'Unknown permission type for mapping acl ' . $acl->getId());
$this->logger->warning('Unknown permission type for mapping acl ' . $acl->getId());
return null;
});
}
Expand Down
27 changes: 3 additions & 24 deletions tests/psalm-baseline.xml
Expand Up @@ -105,7 +105,8 @@
<ParamNameMismatch occurrences="1">
<code>$boardId</code>
</ParamNameMismatch>
<UndefinedClass occurrences="1">
<UndefinedClass occurrences="2">
<code>\OCA\Circles\Api\v1\Circles</code>
<code>\OCA\Circles\Api\v1\Circles</code>
</UndefinedClass>
</file>
Expand Down Expand Up @@ -170,20 +171,12 @@
<code>$stackId</code>
</ParamNameMismatch>
</file>
<file src="lib/Notification/NotificationHelper.php">
<InvalidScalarArgument occurrences="1">
<code>$board-&gt;getId()</code>
</InvalidScalarArgument>
</file>
<file src="lib/Notification/Notifier.php">
<RedundantCast occurrences="7">
<RedundantCast occurrences="4">
<code>(string) $l-&gt;t('%s has mentioned you in a comment on "%s".', [$dn, $params[0]])</code>
<code>(string) $l-&gt;t('The board "%s" has been shared with you by %s.', [$params[0], $dn])</code>
<code>(string) $l-&gt;t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn])</code>
<code>(string) $l-&gt;t('The card "%s" on "%s" has reached its due date.', $params)</code>
<code>(string) $l-&gt;t('{user} has assigned the card "%s" on "%s" to you.', [$params[0], $params[1]])</code>
<code>(string) $l-&gt;t('{user} has mentioned you in a comment on "%s".', [$params[0]])</code>
<code>(string) $l-&gt;t('{user} has shared the board %s with you.', [$params[0]])</code>
</RedundantCast>
</file>
<file src="lib/Provider/DeckProvider.php">
Expand All @@ -196,12 +189,6 @@
<code>$cardId</code>
<code>$cardId</code>
</InvalidScalarArgument>
<UndefinedThisPropertyAssignment occurrences="1">
<code>$this-&gt;currentUser</code>
</UndefinedThisPropertyAssignment>
<UndefinedThisPropertyFetch occurrences="1">
<code>$this-&gt;currentUser</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/Service/BoardService.php">
<TooManyArguments occurrences="2">
Expand Down Expand Up @@ -265,7 +252,6 @@
</RedundantCondition>
</file>
<file src="lib/Service/FilesAppService.php">
<InvalidCatch occurrences="1"/>
<MissingDependency occurrences="4">
<code>$this-&gt;rootFolder</code>
<code>$this-&gt;rootFolder</code>
Expand All @@ -279,13 +265,6 @@
<code>\OCA\Circles\Api\v1\Circles</code>
</UndefinedClass>
</file>
<file src="lib/Service/SearchService.php">
<UndefinedThisPropertyFetch occurrences="3">
<code>$this-&gt;l10n</code>
<code>$this-&gt;urlGenerator</code>
<code>$this-&gt;userManager</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/Service/StackService.php">
<UndefinedClass occurrences="1">
<code>BadRquestException</code>
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Db/AclMapperTest.php
Expand Up @@ -25,6 +25,7 @@

use OCP\IGroupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\AppFramework\Db\MapperTestUtility;

/**
Expand Down Expand Up @@ -54,7 +55,8 @@ public function setup(): void {
$this->aclMapper,
\OC::$server->query(StackMapper::class),
$this->userManager,
$this->groupManager
$this->groupManager,
$this->createMock(LoggerInterface::class)
);

$this->boards = [
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Db/BoardMapperTest.php
Expand Up @@ -26,6 +26,7 @@
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\AppFramework\Db\MapperTestUtility;

/**
Expand Down Expand Up @@ -61,7 +62,8 @@ public function setUp(): void {
\OC::$server->query(AclMapper::class),
\OC::$server->query(StackMapper::class),
$this->userManager,
$this->groupManager
$this->groupManager,
$this->createMock(LoggerInterface::class)
);
$this->aclMapper = \OC::$server->query(AclMapper::class);
$this->labelMapper = \OC::$server->query(LabelMapper::class);
Expand Down

0 comments on commit fbcad7f

Please sign in to comment.