Skip to content

Commit 2fde8ea

Browse files
authored
Merge pull request #6953 from nextcloud/backport/6933/stable30
[stable30] fix: Limit label actions to labels of the cards board
2 parents 508cf46 + 4b17dc9 commit 2fde8ea

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/Service/CardService.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,9 @@ public function undone(int $id): Card {
600600
public function assignLabel($cardId, $labelId) {
601601
$this->cardServiceValidator->check(compact('cardId', 'labelId'));
602602

603-
604603
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
604+
$this->permissionService->checkPermission($this->labelMapper, $labelId, Acl::PERMISSION_READ);
605+
605606
if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
606607
throw new StatusException('Operation not allowed. This board is archived.');
607608
}
@@ -610,6 +611,9 @@ public function assignLabel($cardId, $labelId) {
610611
throw new StatusException('Operation not allowed. This card is archived.');
611612
}
612613
$label = $this->labelMapper->find($labelId);
614+
if ($label->getBoardId() !== $this->cardMapper->findBoardId($card->getId())) {
615+
throw new StatusException('Operation not allowed. Label does not exist.');
616+
}
613617
$this->cardMapper->assignLabel($cardId, $labelId);
614618
$this->changeHelper->cardChanged($cardId);
615619
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
@@ -631,6 +635,8 @@ public function removeLabel($cardId, $labelId) {
631635

632636

633637
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
638+
$this->permissionService->checkPermission($this->labelMapper, $labelId, Acl::PERMISSION_READ);
639+
634640
if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
635641
throw new StatusException('Operation not allowed. This board is archived.');
636642
}
@@ -639,6 +645,9 @@ public function removeLabel($cardId, $labelId) {
639645
throw new StatusException('Operation not allowed. This card is archived.');
640646
}
641647
$label = $this->labelMapper->find($labelId);
648+
if ($label->getBoardId() !== $this->cardMapper->findBoardId($card->getId())) {
649+
throw new StatusException('Operation not allowed. Label does not exist.');
650+
}
642651
$this->cardMapper->removeLabel($cardId, $labelId);
643652
$this->changeHelper->cardChanged($cardId);
644653
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
71452
1+
71618

tests/unit/Service/CardServiceTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCA\Deck\Db\Card;
3232
use OCA\Deck\Db\CardMapper;
3333
use OCA\Deck\Db\ChangeHelper;
34+
use OCA\Deck\Db\Label;
3435
use OCA\Deck\Db\LabelMapper;
3536
use OCA\Deck\Db\Stack;
3637
use OCA\Deck\Db\StackMapper;
@@ -347,8 +348,17 @@ public function testUnarchive() {
347348
public function testAssignLabel() {
348349
$card = new Card();
349350
$card->setArchived(false);
351+
$card->setId(123);
352+
$label = new Label();
353+
$label->setBoardId(1);
350354
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
351355
$this->cardMapper->expects($this->once())->method('assignLabel');
356+
$this->cardMapper->expects($this->once())
357+
->method('findBoardId')
358+
->willReturn(1);
359+
$this->labelMapper->expects($this->once())
360+
->method('find')
361+
->willReturn($label);
352362
$this->cardService->assignLabel(123, 999);
353363
}
354364

@@ -364,8 +374,17 @@ public function testAssignLabelArchived() {
364374
public function testRemoveLabel() {
365375
$card = new Card();
366376
$card->setArchived(false);
377+
$card->setId(123);
378+
$label = new Label();
379+
$label->setBoardId(1);
367380
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
368381
$this->cardMapper->expects($this->once())->method('removeLabel');
382+
$this->cardMapper->expects($this->once())
383+
->method('findBoardId')
384+
->willReturn(1);
385+
$this->labelMapper->expects($this->once())
386+
->method('find')
387+
->willReturn($label);
369388
$this->cardService->removeLabel(123, 999);
370389
}
371390

0 commit comments

Comments
 (0)