Skip to content

Commit cde06ab

Browse files
Merge pull request #8190 from nextcloud/update-setDoneStack
fix: validate board permission in setDoneStack method
2 parents 3a21a22 + e351f6e commit cde06ab

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/Service/StackService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ public function reorder(int $id, int $order): array {
306306
*/
307307
public function setDoneStack(int $stackId, int $boardId, bool $isDone): void {
308308
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_MANAGE);
309+
$stack = $this->stackMapper->find($stackId);
310+
311+
if ($stack->getBoardId() !== $boardId) {
312+
throw new BadRequestException('Stack does not belong to the specified board.');
313+
}
309314

310315
if ($this->boardService->isArchived($this->stackMapper, $stackId)) {
311316
throw new NoPermissionException('Operation not allowed. This board is archived.');

tests/unit/Service/StackServiceTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ private function createStack(int $id, int $order) {
276276

277277
public function testSetDoneStackSetsDoneColumn(): void {
278278
$this->permissionService->expects($this->once())->method('checkPermission');
279+
$this->stackMapper->expects($this->once())
280+
->method('find')
281+
->with(5)
282+
->willReturn($this->createStack(5, 0));
279283
$this->boardService->expects($this->once())->method('isArchived')->willReturn(false);
280284
$this->stackMapper->expects($this->once())
281285
->method('clearDoneColumnForBoard')
@@ -303,6 +307,10 @@ public function testSetDoneStackSetsDoneColumn(): void {
303307
public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void {
304308
$this->permissionService->expects($this->once())->method('checkPermission');
305309
$this->boardService->expects($this->once())->method('isArchived')->willReturn(false);
310+
$this->stackMapper->expects($this->once())
311+
->method('find')
312+
->with(5)
313+
->willReturn($this->createStack(5, 0));
306314
$this->stackMapper->expects($this->never())->method('clearDoneColumnForBoard');
307315
$this->cardMapper->expects($this->never())->method('findAll');
308316
$this->cardMapper->expects($this->never())->method('update');
@@ -314,9 +322,24 @@ public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void {
314322

315323
public function testSetDoneStackThrowsOnArchivedBoard(): void {
316324
$this->permissionService->expects($this->once())->method('checkPermission');
325+
$this->stackMapper->expects($this->once())
326+
->method('find')
327+
->with(5)
328+
->willReturn($this->createStack(5, 0));
317329
$this->boardService->expects($this->once())->method('isArchived')->willReturn(true);
318330
$this->stackMapper->expects($this->never())->method('setIsDoneColumn');
319331
$this->expectException(\OCA\Deck\NoPermissionException::class);
320332
$this->stackService->setDoneStack(5, 1, true);
321333
}
334+
335+
public function testSetDoneStackThrowsOnMismatchBoardId(): void {
336+
$this->permissionService->expects($this->once())->method('checkPermission');
337+
$this->stackMapper->expects($this->once())
338+
->method('find')
339+
->with(5)
340+
->willReturn($this->createStack(5, 0));
341+
$this->stackMapper->expects($this->never())->method('setIsDoneColumn');
342+
$this->expectException(\OCA\Deck\BadRequestException::class);
343+
$this->stackService->setDoneStack(5, 2, true);
344+
}
322345
}

0 commit comments

Comments
 (0)