diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index 0eccb00d4..c43ea54ae 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -1,4 +1,5 @@ circlesService = $circlesService; - $this->aclMapper = $aclMapper; - $this->boardMapper = $boardMapper; - $this->logger = $logger; - $this->userManager = $userManager; - $this->groupManager = $groupManager; - $this->shareManager = $shareManager; - $this->config = $config; - $this->userId = $userId; - $this->boardCache = new CappedMemoryCache(); $this->permissionCache = new CappedMemoryCache(); } @@ -78,10 +49,9 @@ public function __construct( /** * Get current user permissions for a board by id * - * @param $boardId * @return bool|array */ - public function getPermissions($boardId, ?string $userId = null) { + public function getPermissions(int $boardId, ?string $userId = null) { if ($userId === null) { $userId = $this->userId; } @@ -99,7 +69,7 @@ public function getPermissions($boardId, ?string $userId = null) { $owner = false; $acls = []; } - + $permissions = [ Acl::PERMISSION_READ => $owner || $this->userCan($acls, Acl::PERMISSION_READ, $userId), Acl::PERMISSION_EDIT => $owner || $this->userCan($acls, Acl::PERMISSION_EDIT, $userId), @@ -133,11 +103,10 @@ public function matchPermissions(Board $board) { /** * check permissions for replacing dark magic middleware * - * @param numeric $id * @throws NoPermissionException */ public function checkPermission(?IPermissionMapper $mapper, $id, int $permission, $userId = null, bool $allowDeletedCard = false): bool { - $boardId = $id; + $boardId = (int)$id; if ($mapper instanceof IPermissionMapper && !($mapper instanceof BoardMapper)) { $boardId = $mapper->findBoardId($id); } @@ -150,7 +119,7 @@ public function checkPermission(?IPermissionMapper $mapper, $id, int $permission if ($permissions[$permission] === true) { if (!$allowDeletedCard && $mapper instanceof CardMapper) { - $card = $mapper->find($id); + $card = $mapper->find((int)$id); if ($card->getDeletedAt() > 0) { throw new NoPermissionException('Card is deleted'); } diff --git a/tests/unit/Service/PermissionServiceTest.php b/tests/unit/Service/PermissionServiceTest.php index 2a5d2b933..bca3efc33 100644 --- a/tests/unit/Service/PermissionServiceTest.php +++ b/tests/unit/Service/PermissionServiceTest.php @@ -34,39 +34,28 @@ use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; use OCP\Share\IManager; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class PermissionServiceTest extends \Test\TestCase { - - /** @var IRequest */ - private $request; - private $circlesService; - /** @var PermissionService*/ - private $service; - /** @var ILogger */ - private $logger; - /** @var AclMapper */ - private $aclMapper; - /** @var BoardMapper */ - private $boardMapper; - /** @var IUserManager */ - private $userManager; - /** @var IGroupManager */ - private $groupManager; - /** @var IManager */ - private $shareManager; - /** @var IConfig */ - private $config; - /** @var string */ - private $userId = 'admin'; + private IRequest|MockObject $request; + private CirclesService|MockObject $circlesService; + private PermissionService $service; + private LoggerInterface|MockObject $logger; + private AclMapper|MockObject $aclMapper; + private BoardMapper|MockObject $boardMapper; + private IUserManager $userManager; + private IGroupManager|MockObject $groupManager; + private MockObject|IManager $shareManager; + private IConfig|MockObject $config; public function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->request = $this->createMock(IRequest::class); $this->circlesService = $this->createMock(CirclesService::class); $this->aclMapper = $this->createMock(AclMapper::class);