Fix deleteAcl

Signed-off-by: raul <raul@nextcloud.com>
This commit is contained in:
raul
2022-09-21 19:12:54 +02:00
committed by Raul Ferreira Fuentes
parent af8e61ece6
commit 24a4260e55
3 changed files with 19 additions and 8 deletions

View File

@@ -42,6 +42,7 @@ use OCA\Deck\Event\AclUpdatedEvent;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
@@ -55,6 +56,8 @@ use OCP\IUserManager;
use OCA\Deck\BadRequestException; use OCA\Deck\BadRequestException;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Server; use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class BoardService { class BoardService {
private BoardMapper $boardMapper; private BoardMapper $boardMapper;
@@ -592,12 +595,14 @@ class BoardService {
} }
/** /**
* @throws DbException
* @throws DoesNotExistException * @throws DoesNotExistException
* @throws \OCA\Deck\NoPermissionException * @throws NoPermissionException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws MultipleObjectsReturnedException
* @throws BadRequestException * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function deleteAcl(int $id): bool { public function deleteAcl(int $id): ?Acl {
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE); $this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
/** @var Acl $acl */ /** @var Acl $acl */
$acl = $this->aclMapper->find($id); $acl = $this->aclMapper->find($id);
@@ -622,8 +627,10 @@ class BoardService {
} }
} }
$deletedAcl = $this->aclMapper->delete($acl);
$this->eventDispatcher->dispatchTyped(new AclDeletedEvent($acl)); $this->eventDispatcher->dispatchTyped(new AclDeletedEvent($acl));
return (bool) $this->aclMapper->delete($acl);
return $deletedAcl;
} }
/** /**

View File

@@ -427,6 +427,6 @@ class BoardServiceTest extends TestCase {
->method('delete') ->method('delete')
->with($acl) ->with($acl)
->willReturn($acl); ->willReturn($acl);
$this->assertTrue($this->service->deleteAcl(123)); $this->assertEquals($acl, $this->service->deleteAcl(123));
} }
} }

View File

@@ -164,10 +164,14 @@ class BoardControllerTest extends \Test\TestCase {
} }
public function testDeleteAcl() { public function testDeleteAcl() {
$acl = $this->getMockBuilder(Acl::class)
->disableOriginalConstructor()
->getMock();
$this->boardService->expects($this->once()) $this->boardService->expects($this->once())
->method('deleteAcl') ->method('deleteAcl')
->with(1) ->with(1)
->willReturn(true); ->willReturn($acl);
$this->assertEquals(true, $this->controller->deleteAcl(1)); $this->assertEquals($acl, $this->controller->deleteAcl(1));
} }
} }