Skip to content

Commit

Permalink
Merge pull request #6289 from nextcloud/backport/6257/stable30
Browse files Browse the repository at this point in the history
[stable30] copy labels when moving cards between boards
  • Loading branch information
grnd-alt authored Sep 2, 2024
2 parents acaaccd + c846880 commit b3b9b0d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
31 changes: 30 additions & 1 deletion lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CardService {
private StackMapper $stackMapper;
private BoardMapper $boardMapper;
private LabelMapper $labelMapper;
private LabelService $labelService;
private PermissionService $permissionService;
private BoardService $boardService;
private NotificationHelper $notificationHelper;
Expand All @@ -61,6 +62,7 @@ public function __construct(
StackMapper $stackMapper,
BoardMapper $boardMapper,
LabelMapper $labelMapper,
LabelService $labelService,
PermissionService $permissionService,
BoardService $boardService,
NotificationHelper $notificationHelper,
Expand All @@ -81,6 +83,7 @@ public function __construct(
$this->stackMapper = $stackMapper;
$this->boardMapper = $boardMapper;
$this->labelMapper = $labelMapper;
$this->labelService = $labelService;
$this->permissionService = $permissionService;
$this->boardService = $boardService;
$this->notificationHelper = $notificationHelper;
Expand Down Expand Up @@ -349,8 +352,34 @@ public function update($id, $title, $stackId, $type, $owner, $description = '',
}
$card->setDescription($description);


// @var Card $card
$card = $this->cardMapper->update($card);
$oldBoardId = $this->stackMapper->findBoardId($changes->getBefore()->getStackId());
$boardId = $this->cardMapper->findBoardId($card->getId());
if($boardId !== $oldBoardId) {
$stack = $this->stackMapper->find($card->getStackId());
$board = $this->boardService->find($this->cardMapper->findBoardId($card->getId()));
$boardLabels = $board->getLabels() ?? [];
foreach($card->getLabels() as $cardLabel) {
$this->removeLabel($card->getId(), $cardLabel->getId());
$label = $this->labelMapper->find($cardLabel->getId());
$filteredLabels = array_values(array_filter($boardLabels, fn ($item) => $item->getTitle() === $label->getTitle()));
// clone labels that are assigned to card but don't exist in new board
if (empty($filteredLabels)) {
if ($this->permissionService->getPermissions($boardId)[Acl::PERMISSION_MANAGE] === true) {
$newLabel = $this->labelService->create($label->getTitle(), $label->getColor(), $board->getId());
$boardLabels[] = $label;
$this->assignLabel($card->getId(), $newLabel->getId());
}
} else {
$this->assignLabel($card->getId(), $filteredLabels[0]->getId());
}
}
$board->setLabels($boardLabels);
$this->boardMapper->update($board);
$this->changeHelper->boardChanged($board->getId());
}

if ($resetDuedateNotification) {
$this->notificationHelper->markDuedateAsRead($card);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Service/Importer/Systems/DeckJsonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public function getCardLabelAssignment(): array {
foreach ($this->tmpCards as $sourceCard) {
foreach ($sourceCard->labels as $label) {
$cardId = $this->cards[$sourceCard->id]->getId();
$labelId = $this->labels[$label->id]->getId();
$cardsLabels[$cardId][] = $labelId;
if ($this->getImportService()->getData()->id === $label->boardId) {
$labelId = $this->labels[$label->id]->getId();
$cardsLabels[$cardId][] = $labelId;
}
}
}
return $cardsLabels;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class CardServiceTest extends TestCase {
private $boardService;
/** @var LabelMapper|MockObject */
private $labelMapper;
/** @var LabelService|MockObject */
private $labelService;
private $boardMapper;
/** @var AttachmentService|MockObject */
private $attachmentService;
Expand Down Expand Up @@ -96,6 +98,7 @@ public function setUp(): void {
$this->stackMapper = $this->createMock(StackMapper::class);
$this->boardMapper = $this->createMock(BoardMapper::class);
$this->labelMapper = $this->createMock(LabelMapper::class);
$this->labelService = $this->createMock(LabelService::class);
$this->permissionService = $this->createMock(PermissionService::class);
$this->boardService = $this->createMock(BoardService::class);
$this->notificationHelper = $this->createMock(NotificationHelper::class);
Expand All @@ -118,6 +121,7 @@ public function setUp(): void {
$this->stackMapper,
$this->boardMapper,
$this->labelMapper,
$this->labelService,
$this->permissionService,
$this->boardService,
$this->notificationHelper,
Expand Down

0 comments on commit b3b9b0d

Please sign in to comment.