Skip to content

Commit

Permalink
test: Adapt unit tests
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 Jan 12, 2024
1 parent f70b31c commit 06414ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/Service/PermissionService.php
Expand Up @@ -160,19 +160,19 @@ public function checkPermission($mapper, $id, $permission, $userId = null, bool
throw new NoPermissionException('Permission denied');
}

$permissions = $this->getPermissions($boardId, $userId);
if ($permissions[$permission] === true) {
if (!$allowDeletedCard && $mapper instanceof CardMapper) {
$card = $mapper->find($id);
if ($card->getDeletedAt() > 0) {
throw new NoPermissionException('Card is deleted');
try {
$permissions = $this->getPermissions($boardId, $userId);
if ($permissions[$permission] === true) {
if (!$allowDeletedCard && $mapper instanceof CardMapper) {
$card = $mapper->find($id);
if ($card->getDeletedAt() > 0) {
throw new NoPermissionException('Card is deleted');
}
}
}

return true;
}
return true;
}

try {
$acls = $this->getBoard((int)$boardId)->getAcl() ?? [];
$result = $this->userCan($acls, $permission, $userId);
if ($result) {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Service/PermissionServiceTest.php
Expand Up @@ -240,6 +240,8 @@ public function testCheckPermission($boardId, $permission, $result, $owner = 'fo
->method('sharingDisabledForUser')
->willReturn(false);

$this->aclMapper->method('findAll')->willReturn([]);

if ($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
Expand All @@ -262,6 +264,8 @@ public function testCheckPermissionWithoutMapper($boardId, $permission, $result,
$this->boardMapper->expects($this->any())->method('find')->willReturn($board);
}

$this->aclMapper->method('findAll')->willReturn([]);

if ($result) {
$actual = $this->service->checkPermission($mapper, 1234, $permission);
$this->assertTrue($actual);
Expand Down

0 comments on commit 06414ea

Please sign in to comment.