Changes to make possible implement api endpoint
Update documentation Start implementing getSystems route Code to route getSystems Controller to board import Change return Increase coverage Signed-off-by: Vitor Mattos <vitor@php.rio>
This commit is contained in:
committed by
Julius Härtl
parent
39a927de18
commit
4138953208
@@ -24,9 +24,9 @@
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OC\Comments\Comment;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Assignment;
|
||||
use OCA\Deck\Db\AssignmentMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\Label;
|
||||
@@ -36,8 +36,6 @@ use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class BoardImportTrelloService extends ABoardImportService {
|
||||
/** @var AssignmentMapper */
|
||||
private $assignmentMapper;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IL10N */
|
||||
@@ -60,25 +58,15 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
private $members = [];
|
||||
|
||||
public function __construct(
|
||||
BoardService $boardService,
|
||||
AssignmentMapper $assignmentMapper,
|
||||
IUserManager $userManager,
|
||||
IL10N $l10n
|
||||
) {
|
||||
$this->boardService = $boardService;
|
||||
$this->assignmentMapper = $assignmentMapper;
|
||||
$this->userManager = $userManager;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
public function validate(): ABoardImportService {
|
||||
$this->boardImportTrelloService->validateOwner();
|
||||
$this->boardImportTrelloService->validateUsers();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ABoardImportService
|
||||
* @return self
|
||||
*/
|
||||
public function validateUsers(): self {
|
||||
if (empty($this->getImportService()->getConfig('uidRelation'))) {
|
||||
@@ -91,8 +79,8 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
if (!$user) {
|
||||
throw new \LogicException('Trello user ' . $trelloUid . ' not found in property "members" of json data');
|
||||
}
|
||||
if (!is_string($nextcloudUid)) {
|
||||
throw new \LogicException('User on setting uidRelation must be a string');
|
||||
if (!is_string($nextcloudUid) && !is_numeric($nextcloudUid)) {
|
||||
throw new \LogicException('User on setting uidRelation is invalid');
|
||||
}
|
||||
$this->getImportService()->getConfig('uidRelation')->$trelloUid = $this->userManager->get($nextcloudUid);
|
||||
if (!$this->getImportService()->getConfig('uidRelation')->$trelloUid) {
|
||||
@@ -170,6 +158,9 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
|
||||
$card->setTitle($trelloCard->name);
|
||||
$card->setStackId($this->stacks[$trelloCard->idList]->getId());
|
||||
$cardsOnStack = $this->stacks[$trelloCard->idList]->getCards();
|
||||
$cardsOnStack[] = $card;
|
||||
$this->stacks[$trelloCard->idList]->setCards($cardsOnStack);
|
||||
$card->setType('plain');
|
||||
$card->setOrder($trelloCard->idShort);
|
||||
$card->setOwner($this->getImportService()->getConfig('owner')->getUID());
|
||||
@@ -184,17 +175,17 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
return $this->cards;
|
||||
}
|
||||
|
||||
public function updateCard($cardTrelloId, Card $card): self {
|
||||
$this->cards[$cardTrelloId] = $card;
|
||||
public function updateCard($id, Card $card): self {
|
||||
$this->cards[$id] = $card;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ABoardImportService
|
||||
* @return self
|
||||
*/
|
||||
private function appendAttachmentsToDescription($trelloCard) {
|
||||
private function appendAttachmentsToDescription($trelloCard): self {
|
||||
if (empty($trelloCard->attachments)) {
|
||||
return;
|
||||
return $this;
|
||||
}
|
||||
$trelloCard->desc .= "\n\n## {$this->l10n->t('Attachments')}\n";
|
||||
$trelloCard->desc .= "| {$this->l10n->t('File')} | {$this->l10n->t('date')} |\n";
|
||||
@@ -206,9 +197,12 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function importParticipants(): ABoardImportService {
|
||||
public function importParticipants(): self {
|
||||
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
||||
foreach ($trelloCard->idMembers as $idMember) {
|
||||
if (empty($this->members[$idMember])) {
|
||||
continue;
|
||||
}
|
||||
$assignment = new Assignment();
|
||||
$assignment->setCardId($this->cards[$trelloCard->id]->getId());
|
||||
$assignment->setParticipant($this->members[$idMember]->getUID());
|
||||
@@ -219,7 +213,7 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function importComments(): ABoardImportService {
|
||||
public function importComments() {
|
||||
foreach ($this->getImportService()->getData()->cards as $trelloCard) {
|
||||
$comments = array_filter(
|
||||
$this->getImportService()->getData()->actions,
|
||||
@@ -246,7 +240,6 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function replaceUsernames($text) {
|
||||
@@ -320,13 +313,16 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
|
||||
public function getBoard(): Board {
|
||||
$board = new Board();
|
||||
if (!$this->getImportService()->getData()->name) {
|
||||
throw new BadRequestException('Invalid name of board');
|
||||
}
|
||||
$board->setTitle($this->getImportService()->getData()->name);
|
||||
$board->setOwner($this->getImportService()->getConfig('owner')->getUID());
|
||||
$board->setColor($this->getImportService()->getConfig('color'));
|
||||
return $board;
|
||||
}
|
||||
|
||||
public function importLabels(): self {
|
||||
public function importLabels(): array {
|
||||
foreach ($this->getImportService()->getData()->labels as $label) {
|
||||
if (empty($label->name)) {
|
||||
$labelTitle = 'Unnamed ' . $label->color . ' label';
|
||||
@@ -340,6 +336,6 @@ class BoardImportTrelloService extends ABoardImportService {
|
||||
);
|
||||
$this->labels[$label->id] = $newLabel;
|
||||
}
|
||||
return $this;
|
||||
return $this->labels;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user