Skip to content

Commit

Permalink
Merge pull request #5000 from nextcloud/backport/4969/stable27
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Aug 9, 2023
2 parents 4d10663 + 2f349e0 commit 0f8a6c0
Show file tree
Hide file tree
Showing 19 changed files with 990 additions and 472 deletions.
12 changes: 11 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
use OCA\Deck\Reference\BoardReferenceProvider;
use OCA\Deck\Reference\CardReferenceProvider;
use OCA\Deck\Reference\CommentReferenceProvider;
use OCA\Deck\Reference\CreateCardReferenceProvider;
use OCA\Deck\Search\CardCommentProvider;
use OCA\Deck\Search\DeckProvider;
use OCA\Deck\Service\PermissionService;
use OCA\Deck\Sharing\DeckShareProvider;
use OCA\Deck\Sharing\Listener;
use OCA\Text\Event\LoadEditor;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand All @@ -83,15 +85,21 @@ class Application extends App implements IBootstrap {

public const COMMENT_ENTITY_TYPE = 'deckCard';

private $referenceLoaded = false;

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);

// TODO move this back to ::register after fixing the autoload issue
// (and use a listener class)
$container = $this->getContainer();
$eventDispatcher = $container->get(IEventDispatcher::class);
$eventDispatcher->addListener(RenderReferenceEvent::class, function () {
$eventDispatcher->addListener(RenderReferenceEvent::class, function (RenderReferenceEvent $e) use ($eventDispatcher) {
Util::addScript(self::APP_ID, self::APP_ID . '-reference');
if (!$this->referenceLoaded && class_exists(LoadEditor::class)) {
$this->referenceLoaded = true;
$eventDispatcher->dispatchTyped(new LoadEditor());
}
});
}

Expand Down Expand Up @@ -129,6 +137,8 @@ public function register(IRegistrationContext $context): void {
$context->registerSearchProvider(CardCommentProvider::class);
$context->registerDashboardWidget(DeckWidget::class);

$context->registerReferenceProvider(CreateCardReferenceProvider::class);

// reference widget
$context->registerReferenceProvider(CardReferenceProvider::class);
$context->registerReferenceProvider(BoardReferenceProvider::class);
Expand Down
11 changes: 10 additions & 1 deletion lib/Controller/CardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@ public function get() {
*
* Get a specific card.
*/
public function create($title, $type = 'plain', $order = 999, $description = '', $duedate = null) {
public function create($title, $type = 'plain', $order = 999, $description = '', $duedate = null, $labels = [], $users = []) {
$card = $this->cardService->create($title, $this->request->getParam('stackId'), $type, $order, $this->userId, $description, $duedate);

foreach ($labels as $labelId) {
$this->cardService->assignLabel($card->id, $labelId);
}

foreach ($users as $user) {
$this->assignmentService->assignUser($card->id, $user['id'], $user['type']);
}

return new DataResponse($card, HTTP::STATUS_OK);
}

Expand Down
14 changes: 12 additions & 2 deletions lib/Controller/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ public function rename($cardId, $title) {
* @param int $order
* @return \OCP\AppFramework\Db\Entity
*/
public function create($title, $stackId, $type = 'plain', $order = 999, string $description = '') {
return $this->cardService->create($title, $stackId, $type, $order, $this->userId, $description);
public function create($title, $stackId, $type = 'plain', $order = 999, string $description = '', $duedate = null, $labels = [], $users = []) {
$card = $this->cardService->create($title, $stackId, $type, $order, $this->userId, $description, $duedate);

foreach ($labels as $label) {
$this->assignLabel($card->id, $label);
}

foreach ($users as $user) {
$this->assignmentService->assignUser($card->id, $user['id'], $user['type']);
}

return $card;
}

/**
Expand Down
16 changes: 15 additions & 1 deletion lib/Reference/CardReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public function matchReference(string $referenceText): bool {
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;

// link example: https://nextcloud.local/index.php/apps/deck/card/11
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/card\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/card\/[0-9]+$/', $referenceText) === 1;

return $noIndexMatch || $indexMatch;
}

Expand All @@ -124,8 +128,8 @@ public function resolveReference(string $referenceText): ?IReference {
[$boardId, $cardId] = $ids;
try {
$card = $this->cardService->find((int) $cardId)->jsonSerialize();
$board = $this->boardService->find((int) $boardId)->jsonSerialize();
$stack = $this->stackService->find((int) $card['stackId'])->jsonSerialize();
$board = $this->boardService->find((int)($boardId ?? $stack['boardId']))->jsonSerialize();
} catch (NoPermissionException $e) {
// Skip throwing if user has no permissions
return null;
Expand Down Expand Up @@ -202,6 +206,16 @@ private function getBoardCardId(string $url): ?array {
return [$matches2[1], $matches2[2]];
}

preg_match('/^' . preg_quote($start, '/') . '\/card\/([0-9]+)$/', $url, $matches);
if ($matches && count($matches) > 1) {
return [null, $matches[1]];
}

preg_match('/^' . preg_quote($startIndex, '/') . '\/card\/([0-9]+)$/', $url, $matches2);
if ($matches2 && count($matches2) > 1) {
return [null, $matches2[1]];
}

return null;
}

Expand Down
77 changes: 77 additions & 0 deletions lib/Reference/CreateCardReferenceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace OCA\Deck\Reference;

use OCA\Deck\AppInfo\Application;
use OCP\Collaboration\Reference\ADiscoverableReferenceProvider;
use OCP\Collaboration\Reference\IReference;
use OCP\IL10N;

use OCP\IURLGenerator;

class CreateCardReferenceProvider extends ADiscoverableReferenceProvider {
public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
private ?string $userId) {
}

/**
* @inheritDoc
*/
public function getId(): string {
return 'create-new-deck-card';
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Create a new deck card');
}

/**
* @inheritDoc
*/
public function getOrder(): int {
return 10;
}

/**
* @inheritDoc
*/
public function getIconUrl(): string {
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
);
}

/**
* @inheritDoc
*/
public function matchReference(string $referenceText): bool {
return false;
}

/**
* @inheritDoc
*/
public function resolveReference(string $referenceText): ?IReference {
return null;
}

/**
* @inheritDoc
*/
public function getCachePrefix(string $referenceId): string {
return $this->userId ?? '';
}

/**
* We don't use the userId here but rather a reference unique id
* @inheritDoc
*/
public function getCacheKey(string $referenceId): ?string {
return $referenceId;
}
}
Loading

0 comments on commit 0f8a6c0

Please sign in to comment.