Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] copy labels when moving cards between boards #6288

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -81,6 +82,7 @@ public function __construct(
StackMapper $stackMapper,
BoardMapper $boardMapper,
LabelMapper $labelMapper,
LabelService $labelService,
PermissionService $permissionService,
BoardService $boardService,
NotificationHelper $notificationHelper,
Expand All @@ -101,6 +103,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 @@ -369,8 +372,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 @@ -129,8 +129,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
Loading