feat: Implement reference resolving for cards that have a link in the title
Signed-off-by: Julius Härtl <jus@bitgrid.net> fix: Enrich on update Signed-off-by: Julius Knorr <jus@bitgrid.net> fix: Enrich on create Signed-off-by: Julius Knorr <jus@bitgrid.net>
This commit is contained in:
committed by
Julius Knorr
parent
46c4c7d4fd
commit
75be929077
@@ -58,7 +58,7 @@ use Sabre\VObject\Component\VCalendar;
|
||||
class Card extends RelationalEntity {
|
||||
public const TITLE_MAX_LENGTH = 255;
|
||||
|
||||
protected $title;
|
||||
protected string $title = '';
|
||||
protected $description;
|
||||
protected $descriptionPrev;
|
||||
protected $stackId;
|
||||
|
||||
@@ -8,10 +8,12 @@ namespace OCA\Deck\Model;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCP\Collaboration\Reference\Reference;
|
||||
|
||||
class CardDetails extends Card {
|
||||
private Card $card;
|
||||
private ?Board $board;
|
||||
private ?Reference $referenceData = null;
|
||||
|
||||
public function __construct(Card $card, ?Board $board = null) {
|
||||
parent::__construct();
|
||||
@@ -23,6 +25,10 @@ class CardDetails extends Card {
|
||||
$this->board = $board;
|
||||
}
|
||||
|
||||
public function setReferenceData(?Reference $data): void {
|
||||
$this->referenceData = $data;
|
||||
}
|
||||
|
||||
public function jsonSerialize(array $extras = []): array {
|
||||
$array = parent::jsonSerialize();
|
||||
$array['overdue'] = $this->getDueStatus();
|
||||
@@ -38,6 +44,8 @@ class CardDetails extends Card {
|
||||
$array['overdue'] = $this->getDueStatus();
|
||||
$this->appendBoardDetails($array);
|
||||
|
||||
$array['referenceData'] = $this->referenceData?->jsonSerialize();
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Validators\CardServiceValidator;
|
||||
use OCP\Collaboration\Reference\IReferenceManager;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IRequest;
|
||||
@@ -37,9 +38,6 @@ use OCP\IUserManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CardService {
|
||||
|
||||
private ?string $currentUser;
|
||||
|
||||
public function __construct(
|
||||
private CardMapper $cardMapper,
|
||||
private StackMapper $stackMapper,
|
||||
@@ -61,13 +59,13 @@ class CardService {
|
||||
private IRequest $request,
|
||||
private CardServiceValidator $cardServiceValidator,
|
||||
private AssignmentService $assignmentService,
|
||||
?string $userId,
|
||||
private IReferenceManager $referenceManager,
|
||||
private ?string $userId,
|
||||
) {
|
||||
$this->currentUser = $userId;
|
||||
}
|
||||
|
||||
public function enrichCards($cards) {
|
||||
$user = $this->userManager->get($this->currentUser);
|
||||
$user = $this->userManager->get($this->userId);
|
||||
|
||||
$cardIds = array_map(function (Card $card) use ($user) {
|
||||
// Everything done in here might be heavy as it is executed for every card
|
||||
@@ -107,11 +105,21 @@ class CardService {
|
||||
|
||||
return array_map(
|
||||
function (Card $card): CardDetails {
|
||||
return new CardDetails($card);
|
||||
$cardDetails = new CardDetails($card);
|
||||
|
||||
$references = $this->referenceManager->extractReferences($card->getTitle());
|
||||
$reference = array_shift($references);
|
||||
if ($reference) {
|
||||
$referenceData = $this->referenceManager->resolveReference($reference);
|
||||
$cardDetails->setReferenceData($referenceData);
|
||||
}
|
||||
|
||||
return $cardDetails;
|
||||
},
|
||||
$cards
|
||||
);
|
||||
}
|
||||
|
||||
public function fetchDeleted($boardId) {
|
||||
$this->cardServiceValidator->check(compact('boardId'));
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
@@ -191,6 +199,8 @@ class CardService {
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
$this->eventDispatcher->dispatchTyped(new CardCreatedEvent($card));
|
||||
|
||||
[$card] = $this->enrichCards([$card]);
|
||||
|
||||
return $card;
|
||||
}
|
||||
|
||||
@@ -265,7 +275,7 @@ class CardService {
|
||||
}
|
||||
|
||||
$changes = new ChangeSet($card);
|
||||
if ($card->getLastEditor() !== $this->currentUser && $card->getLastEditor() !== null) {
|
||||
if ($card->getLastEditor() !== $this->userId && $card->getLastEditor() !== null) {
|
||||
$this->activityManager->triggerEvent(
|
||||
ActivityManager::DECK_OBJECT_CARD,
|
||||
$card,
|
||||
@@ -278,7 +288,7 @@ class CardService {
|
||||
);
|
||||
|
||||
$card->setDescriptionPrev($card->getDescription());
|
||||
$card->setLastEditor($this->currentUser);
|
||||
$card->setLastEditor($this->userId);
|
||||
}
|
||||
$card->setTitle($title);
|
||||
$card->setStackId($stackId);
|
||||
@@ -352,6 +362,8 @@ class CardService {
|
||||
|
||||
$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card, $changes->getBefore()));
|
||||
|
||||
[$card] = $this->enrichCards([$card]);
|
||||
|
||||
return $card;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user