|
25 | 25 | namespace OCA\Deck\Service; |
26 | 26 |
|
27 | 27 | use OCA\Deck\Activity\ActivityManager; |
| 28 | +use OCA\Deck\Db\Acl; |
28 | 29 | use OCA\Deck\Db\Assignment; |
29 | 30 | use OCA\Deck\Db\AssignmentMapper; |
| 31 | +use OCA\Deck\NoPermissionException; |
30 | 32 | use OCA\Deck\Db\Board; |
31 | 33 | use OCA\Deck\Db\BoardMapper; |
32 | 34 | use OCA\Deck\Db\Card; |
@@ -549,6 +551,69 @@ public function testRemoveLabelArchived() { |
549 | 551 | $this->cardService->removeLabel(123, 999); |
550 | 552 | } |
551 | 553 |
|
| 554 | + public function testAssignLabelWithReadPermission() { |
| 555 | + // Users with READ permission (but not EDIT) should be able to assign labels |
| 556 | + // This allows read-only users to label cards they are assigned to |
| 557 | + $card = new Card(); |
| 558 | + $card->setArchived(false); |
| 559 | + $card->setId(123); |
| 560 | + $label = new Label(); |
| 561 | + $label->setBoardId(1); |
| 562 | + |
| 563 | + $this->permissionService->expects($this->exactly(2)) |
| 564 | + ->method('checkPermission') |
| 565 | + ->willReturn(true); |
| 566 | + $this->cardMapper->expects($this->once())->method('find')->willReturn($card); |
| 567 | + $this->cardMapper->expects($this->once())->method('assignLabel'); |
| 568 | + $this->cardMapper->expects($this->once()) |
| 569 | + ->method('findBoardId') |
| 570 | + ->willReturn(1); |
| 571 | + $this->labelMapper->expects($this->once()) |
| 572 | + ->method('find') |
| 573 | + ->willReturn($label); |
| 574 | + $this->cardService->assignLabel(123, 999); |
| 575 | + } |
| 576 | + |
| 577 | + public function testAssignLabelWithoutReadPermission() { |
| 578 | + // Users without READ permission should get NoPermissionException |
| 579 | + $this->permissionService->expects($this->once()) |
| 580 | + ->method('checkPermission') |
| 581 | + ->willThrowException(new NoPermissionException('Permission denied')); |
| 582 | + $this->cardMapper->expects($this->never())->method('assignLabel'); |
| 583 | + $this->expectException(NoPermissionException::class); |
| 584 | + $this->cardService->assignLabel(123, 999); |
| 585 | + } |
| 586 | + |
| 587 | + public function testRemoveLabelRequiresEditPermission() { |
| 588 | + // Removing a label requires EDIT permission (higher than READ) |
| 589 | + // This is intentional: read-only users can add labels but not remove them |
| 590 | + $card = new Card(); |
| 591 | + $card->setArchived(false); |
| 592 | + $card->setId(123); |
| 593 | + $label = new Label(); |
| 594 | + $label->setBoardId(1); |
| 595 | + |
| 596 | + $this->permissionService->expects($this->exactly(2)) |
| 597 | + ->method('checkPermission') |
| 598 | + ->willReturn(true); |
| 599 | + $this->cardMapper->expects($this->once())->method('find')->willReturn($card); |
| 600 | + $this->cardMapper->expects($this->once())->method('removeLabel'); |
| 601 | + $this->labelMapper->expects($this->once()) |
| 602 | + ->method('find') |
| 603 | + ->willReturn($label); |
| 604 | + $this->cardService->removeLabel(123, 999); |
| 605 | + } |
| 606 | + |
| 607 | + public function testRemoveLabelWithoutEditPermission() { |
| 608 | + // Without EDIT permission, removing a label should fail |
| 609 | + $this->permissionService->expects($this->once()) |
| 610 | + ->method('checkPermission') |
| 611 | + ->willThrowException(new NoPermissionException('Permission denied')); |
| 612 | + $this->cardMapper->expects($this->never())->method('removeLabel'); |
| 613 | + $this->expectException(NoPermissionException::class); |
| 614 | + $this->cardService->removeLabel(123, 999); |
| 615 | + } |
| 616 | + |
552 | 617 | public function testDoneMarksCardAsDone(): void { |
553 | 618 | $card = new Card(); |
554 | 619 | $card->setId(42); |
|
0 commit comments