@@ -36,6 +36,7 @@ use OCA\Deck\Db\CardMapper;
|
|||||||
use OCA\Deck\Event\AclCreatedEvent;
|
use OCA\Deck\Event\AclCreatedEvent;
|
||||||
use OCA\Deck\Event\AclDeletedEvent;
|
use OCA\Deck\Event\AclDeletedEvent;
|
||||||
use OCA\Deck\Event\AclUpdatedEvent;
|
use OCA\Deck\Event\AclUpdatedEvent;
|
||||||
|
use OCA\Deck\Event\BoardUpdatedEvent;
|
||||||
use OCA\Deck\Event\CardCreatedEvent;
|
use OCA\Deck\Event\CardCreatedEvent;
|
||||||
use OCA\Deck\Event\CardDeletedEvent;
|
use OCA\Deck\Event\CardDeletedEvent;
|
||||||
use OCA\Deck\Event\CardUpdatedEvent;
|
use OCA\Deck\Event\CardUpdatedEvent;
|
||||||
@@ -154,6 +155,13 @@ class Application extends App implements IBootstrap {
|
|||||||
// Event listening for realtime updates via notify_push
|
// Event listening for realtime updates via notify_push
|
||||||
$context->registerEventListener(SessionCreatedEvent::class, LiveUpdateListener::class);
|
$context->registerEventListener(SessionCreatedEvent::class, LiveUpdateListener::class);
|
||||||
$context->registerEventListener(SessionClosedEvent::class, LiveUpdateListener::class);
|
$context->registerEventListener(SessionClosedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(BoardUpdatedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(CardCreatedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(CardUpdatedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(CardDeletedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(AclCreatedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(AclUpdatedEvent::class, LiveUpdateListener::class);
|
||||||
|
$context->registerEventListener(AclDeletedEvent::class, LiveUpdateListener::class);
|
||||||
|
|
||||||
$context->registerNotifierService(Notifier::class);
|
$context->registerNotifierService(Notifier::class);
|
||||||
$context->registerEventListener(LoadAdditionalScriptsEvent::class, ResourceAdditionalScriptsListener::class);
|
$context->registerEventListener(LoadAdditionalScriptsEvent::class, ResourceAdditionalScriptsListener::class);
|
||||||
|
|||||||
@@ -29,16 +29,24 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|||||||
use OCP\Cache\CappedMemoryCache;
|
use OCP\Cache\CappedMemoryCache;
|
||||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
use OCP\ICache;
|
||||||
|
use OCP\ICacheFactory;
|
||||||
|
|
||||||
/** @template-extends DeckMapper<Stack> */
|
/** @template-extends DeckMapper<Stack> */
|
||||||
class StackMapper extends DeckMapper implements IPermissionMapper {
|
class StackMapper extends DeckMapper implements IPermissionMapper {
|
||||||
private CappedMemoryCache $stackCache;
|
private CappedMemoryCache $stackCache;
|
||||||
private CardMapper $cardMapper;
|
private CardMapper $cardMapper;
|
||||||
|
private ICache $cache;
|
||||||
|
|
||||||
public function __construct(IDBConnection $db, CardMapper $cardMapper) {
|
public function __construct(
|
||||||
|
IDBConnection $db,
|
||||||
|
CardMapper $cardMapper,
|
||||||
|
ICacheFactory $cacheFactory
|
||||||
|
) {
|
||||||
parent::__construct($db, 'deck_stacks', Stack::class);
|
parent::__construct($db, 'deck_stacks', Stack::class);
|
||||||
$this->cardMapper = $cardMapper;
|
$this->cardMapper = $cardMapper;
|
||||||
$this->stackCache = new CappedMemoryCache();
|
$this->stackCache = new CappedMemoryCache();
|
||||||
|
$this->cache = $cacheFactory->createDistributed('deck-stackMapper');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,12 +165,19 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
* @throws \OCP\DB\Exception
|
* @throws \OCP\DB\Exception
|
||||||
*/
|
*/
|
||||||
public function findBoardId($id): ?int {
|
public function findBoardId($id): ?int {
|
||||||
|
$result = $this->cache->get('findBoardId:' . $id);
|
||||||
|
if ($result !== null) {
|
||||||
|
return $result !== false ? $result : null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$entity = $this->find($id);
|
$entity = $this->find($id);
|
||||||
return $entity->getBoardId();
|
$result = $entity->getBoardId();
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
|
$result = false;
|
||||||
} catch (MultipleObjectsReturnedException $e) {
|
} catch (MultipleObjectsReturnedException $e) {
|
||||||
}
|
}
|
||||||
return null;
|
$this->cache->set('findBoardId:' . $id, $result);
|
||||||
|
|
||||||
|
return $result !== false ? $result : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
lib/Event/BoardUpdatedEvent.php
Normal file
43
lib/Event/BoardUpdatedEvent.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* @copyright Copyright (c) 2022 chandi Langecker <git@chandi.it>
|
||||||
|
*
|
||||||
|
* @author chandi Langecker <git@chandi.it>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace OCA\Deck\Event;
|
||||||
|
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
|
||||||
|
class BoardUpdatedEvent extends Event {
|
||||||
|
private $boardId;
|
||||||
|
|
||||||
|
public function __construct(int $boardId) {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->boardId = $boardId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBoardId(): int {
|
||||||
|
return $this->boardId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,5 +26,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\Deck\Event;
|
namespace OCA\Deck\Event;
|
||||||
|
|
||||||
|
use OCA\Deck\Db\Card;
|
||||||
|
|
||||||
class CardUpdatedEvent extends ACardEvent {
|
class CardUpdatedEvent extends ACardEvent {
|
||||||
|
private $cardBefore;
|
||||||
|
|
||||||
|
public function __construct(Card $card, Card $before = null) {
|
||||||
|
parent::__construct($card);
|
||||||
|
$this->cardBefore = $before;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCardBefore() {
|
||||||
|
return $this->cardBefore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\Deck\Listeners;
|
namespace OCA\Deck\Listeners;
|
||||||
|
|
||||||
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\NotifyPushEvents;
|
use OCA\Deck\NotifyPushEvents;
|
||||||
|
use OCA\Deck\Event\AAclEvent;
|
||||||
|
use OCA\Deck\Event\ACardEvent;
|
||||||
|
use OCA\Deck\Event\BoardUpdatedEvent;
|
||||||
|
use OCA\Deck\Event\CardUpdatedEvent;
|
||||||
use OCA\Deck\Event\SessionClosedEvent;
|
use OCA\Deck\Event\SessionClosedEvent;
|
||||||
use OCA\Deck\Event\SessionCreatedEvent;
|
use OCA\Deck\Event\SessionCreatedEvent;
|
||||||
use OCA\Deck\Service\SessionService;
|
use OCA\Deck\Service\SessionService;
|
||||||
@@ -37,18 +42,20 @@ use OCP\IRequest;
|
|||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/** @template-implements IEventListener<Event|SessionCreatedEvent|SessionClosedEvent> */
|
/** @template-implements IEventListener<Event|SessionCreatedEvent|SessionClosedEvent|AAclEvent|ACardEvent|CardUpdatedEvent|BoardUpdatedEvent> */
|
||||||
class LiveUpdateListener implements IEventListener {
|
class LiveUpdateListener implements IEventListener {
|
||||||
private LoggerInterface $logger;
|
private LoggerInterface $logger;
|
||||||
private SessionService $sessionService;
|
private SessionService $sessionService;
|
||||||
private IRequest $request;
|
private IRequest $request;
|
||||||
|
private StackMapper $stackMapper;
|
||||||
private $queue;
|
private $queue;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ContainerInterface $container,
|
ContainerInterface $container,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
SessionService $sessionService
|
SessionService $sessionService,
|
||||||
|
StackMapper $stackMapper
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
$this->queue = $container->get(IQueue::class);
|
$this->queue = $container->get(IQueue::class);
|
||||||
@@ -59,6 +66,7 @@ class LiveUpdateListener implements IEventListener {
|
|||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->sessionService = $sessionService;
|
$this->sessionService = $sessionService;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->stackMapper = $stackMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event): void {
|
public function handle(Event $event): void {
|
||||||
@@ -68,17 +76,37 @@ class LiveUpdateListener implements IEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// the web frontend is adding the Session-ID as a header on every request
|
// the web frontend is adding the Session-ID as a header
|
||||||
// TODO: verify the token! this currently allows to spoof a token from someone
|
// TODO: verify the token! this currently allows to spoof a token from someone
|
||||||
// else, preventing this person from getting any live updates
|
// else, preventing this person from getting updates
|
||||||
$causingSessionToken = $this->request->getHeader('x-nc-deck-session');
|
$causingSessionToken = $this->request->getHeader('x-nc-deck-session');
|
||||||
if (
|
if (
|
||||||
$event instanceof SessionCreatedEvent ||
|
$event instanceof SessionCreatedEvent ||
|
||||||
$event instanceof SessionClosedEvent
|
$event instanceof SessionClosedEvent ||
|
||||||
|
$event instanceof BoardUpdatedEvent ||
|
||||||
|
$event instanceof AAclEvent
|
||||||
) {
|
) {
|
||||||
$this->sessionService->notifyAllSessions($this->queue, $event->getBoardId(), NotifyPushEvents::DeckBoardUpdate, [
|
$this->sessionService->notifyAllSessions($this->queue, $event->getBoardId(), NotifyPushEvents::DeckBoardUpdate, [
|
||||||
'id' => $event->getBoardId()
|
'id' => $event->getBoardId()
|
||||||
], $causingSessionToken);
|
], $causingSessionToken);
|
||||||
|
} elseif ($event instanceof ACardEvent) {
|
||||||
|
$boardId = $this->stackMapper->findBoardId($event->getCard()->getStackId());
|
||||||
|
$this->sessionService->notifyAllSessions($this->queue, $boardId, NotifyPushEvents::DeckCardUpdate, [
|
||||||
|
'boardId' => $boardId,
|
||||||
|
'cardId' => $event->getCard()->getId()
|
||||||
|
], $causingSessionToken);
|
||||||
|
|
||||||
|
// if card got moved to a diferent board, we should notify
|
||||||
|
// also sessions active on the previous board
|
||||||
|
if ($event instanceof CardUpdatedEvent && $event->getCardBefore()) {
|
||||||
|
$previousBoardId = $this->stackMapper->findBoardId($event->getCardBefore()->getStackId());
|
||||||
|
if ($boardId !== $previousBoardId) {
|
||||||
|
$this->sessionService->notifyAllSessions($this->queue, $previousBoardId, NotifyPushEvents::DeckCardUpdate, [
|
||||||
|
'boardId' => $boardId,
|
||||||
|
'cardId' => $event->getCard()->getId()
|
||||||
|
], $causingSessionToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error('Error when handling live update event', ['exception' => $e]);
|
$this->logger->error('Error when handling live update event', ['exception' => $e]);
|
||||||
|
|||||||
@@ -26,4 +26,5 @@ namespace OCA\Deck;
|
|||||||
|
|
||||||
class NotifyPushEvents {
|
class NotifyPushEvents {
|
||||||
public const DeckBoardUpdate = 'deck_board_update';
|
public const DeckBoardUpdate = 'deck_board_update';
|
||||||
|
public const DeckCardUpdate = 'deck_card_update';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ use OCA\Deck\Db\BoardMapper;
|
|||||||
use OCA\Deck\Db\LabelMapper;
|
use OCA\Deck\Db\LabelMapper;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCA\Deck\BadRequestException;
|
use OCA\Deck\BadRequestException;
|
||||||
|
use OCA\Deck\Event\BoardUpdatedEvent;
|
||||||
use OCA\Deck\Validators\BoardServiceValidator;
|
use OCA\Deck\Validators\BoardServiceValidator;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\Server;
|
use OCP\Server;
|
||||||
@@ -379,6 +380,7 @@ class BoardService {
|
|||||||
$this->boardMapper->mapOwner($board);
|
$this->boardMapper->mapOwner($board);
|
||||||
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
|
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
|
||||||
$this->changeHelper->boardChanged($board->getId());
|
$this->changeHelper->boardChanged($board->getId());
|
||||||
|
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($board->getId()));
|
||||||
|
|
||||||
return $board;
|
return $board;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ class CardService {
|
|||||||
}
|
}
|
||||||
$this->changeHelper->cardChanged($card->getId(), true);
|
$this->changeHelper->cardChanged($card->getId(), true);
|
||||||
|
|
||||||
$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card));
|
$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card, $changes->getBefore()));
|
||||||
|
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
@@ -443,6 +443,8 @@ class CardService {
|
|||||||
$result[$card->getOrder()] = $card;
|
$result[$card->getOrder()] = $card;
|
||||||
}
|
}
|
||||||
$this->changeHelper->cardChanged($id, false);
|
$this->changeHelper->cardChanged($id, false);
|
||||||
|
$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card));
|
||||||
|
|
||||||
return array_values($result);
|
return array_values($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ use OCA\Deck\Db\ChangeHelper;
|
|||||||
use OCA\Deck\Db\LabelMapper;
|
use OCA\Deck\Db\LabelMapper;
|
||||||
use OCA\Deck\Db\Stack;
|
use OCA\Deck\Db\Stack;
|
||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
|
use OCA\Deck\Event\BoardUpdatedEvent;
|
||||||
use OCA\Deck\Model\CardDetails;
|
use OCA\Deck\Model\CardDetails;
|
||||||
use OCA\Deck\NoPermissionException;
|
use OCA\Deck\NoPermissionException;
|
||||||
use OCA\Deck\StatusException;
|
use OCA\Deck\StatusException;
|
||||||
use OCA\Deck\Validators\StackServiceValidator;
|
use OCA\Deck\Validators\StackServiceValidator;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class StackService {
|
class StackService {
|
||||||
@@ -55,6 +57,7 @@ class StackService {
|
|||||||
private ActivityManager $activityManager;
|
private ActivityManager $activityManager;
|
||||||
private ChangeHelper $changeHelper;
|
private ChangeHelper $changeHelper;
|
||||||
private LoggerInterface $logger;
|
private LoggerInterface $logger;
|
||||||
|
private IEventDispatcher $eventDispatcher;
|
||||||
private StackServiceValidator $stackServiceValidator;
|
private StackServiceValidator $stackServiceValidator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -70,6 +73,7 @@ class StackService {
|
|||||||
ActivityManager $activityManager,
|
ActivityManager $activityManager,
|
||||||
ChangeHelper $changeHelper,
|
ChangeHelper $changeHelper,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
|
IEventDispatcher $eventDispatcher,
|
||||||
StackServiceValidator $stackServiceValidator
|
StackServiceValidator $stackServiceValidator
|
||||||
) {
|
) {
|
||||||
$this->stackMapper = $stackMapper;
|
$this->stackMapper = $stackMapper;
|
||||||
@@ -84,6 +88,7 @@ class StackService {
|
|||||||
$this->activityManager = $activityManager;
|
$this->activityManager = $activityManager;
|
||||||
$this->changeHelper = $changeHelper;
|
$this->changeHelper = $changeHelper;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->stackServiceValidator = $stackServiceValidator;
|
$this->stackServiceValidator = $stackServiceValidator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +242,7 @@ class StackService {
|
|||||||
ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE
|
ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE
|
||||||
);
|
);
|
||||||
$this->changeHelper->boardChanged($boardId);
|
$this->changeHelper->boardChanged($boardId);
|
||||||
|
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($boardId));
|
||||||
|
|
||||||
return $stack;
|
return $stack;
|
||||||
}
|
}
|
||||||
@@ -265,6 +271,7 @@ class StackService {
|
|||||||
ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE
|
ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE
|
||||||
);
|
);
|
||||||
$this->changeHelper->boardChanged($stack->getBoardId());
|
$this->changeHelper->boardChanged($stack->getBoardId());
|
||||||
|
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($stack->getBoardId()));
|
||||||
$this->enrichStackWithCards($stack);
|
$this->enrichStackWithCards($stack);
|
||||||
|
|
||||||
return $stack;
|
return $stack;
|
||||||
@@ -306,6 +313,7 @@ class StackService {
|
|||||||
ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE
|
ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE
|
||||||
);
|
);
|
||||||
$this->changeHelper->boardChanged($stack->getBoardId());
|
$this->changeHelper->boardChanged($stack->getBoardId());
|
||||||
|
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($stack->getBoardId()));
|
||||||
|
|
||||||
return $stack;
|
return $stack;
|
||||||
}
|
}
|
||||||
@@ -345,6 +353,7 @@ class StackService {
|
|||||||
$result[$stack->getOrder()] = $stack;
|
$result[$stack->getOrder()] = $stack;
|
||||||
}
|
}
|
||||||
$this->changeHelper->boardChanged($stackToSort->getBoardId());
|
$this->changeHelper->boardChanged($stackToSort->getBoardId());
|
||||||
|
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($stackToSort->getBoardId()));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,8 +95,7 @@ export default {
|
|||||||
.avatar-wrapper {
|
.avatar-wrapper {
|
||||||
background-color: #b9b9b9;
|
background-color: #b9b9b9;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
border-width: 2px;
|
border: 1px solid var(--color-border-dark);
|
||||||
border-style: solid;
|
|
||||||
width: var(--size);
|
width: var(--size);
|
||||||
height: var(--size);
|
height: var(--size);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -52,6 +52,18 @@ hasPush = listen('deck_board_update', (name, body) => {
|
|||||||
store.dispatch('refreshBoard', currentBoardId)
|
store.dispatch('refreshBoard', currentBoardId)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
listen('deck_card_update', (name, body) => {
|
||||||
|
|
||||||
|
// ignore update events which we have triggered ourselves
|
||||||
|
if (isOurSessionToken(body._causingSessionToken)) return
|
||||||
|
|
||||||
|
// only handle update events for the currently open board
|
||||||
|
const currentBoardId = store.state.currentBoard?.id
|
||||||
|
if (body.boardId !== currentBoardId) return
|
||||||
|
|
||||||
|
store.dispatch('loadStacks', currentBoardId)
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the notify_push app active and can
|
* is the notify_push app active and can
|
||||||
* provide us with real time updates?
|
* provide us with real time updates?
|
||||||
|
|||||||
@@ -273,6 +273,17 @@ export default {
|
|||||||
addNewCard(state, card) {
|
addNewCard(state, card) {
|
||||||
state.cards.push(card)
|
state.cards.push(card)
|
||||||
},
|
},
|
||||||
|
setCards(state, cards) {
|
||||||
|
const deletedCards = state.cards.filter(_card => {
|
||||||
|
return cards.findIndex(c => _card.id === c.id) === -1
|
||||||
|
})
|
||||||
|
for (const card of deletedCards) {
|
||||||
|
this.commit('deleteCard', card)
|
||||||
|
}
|
||||||
|
for (const card of cards) {
|
||||||
|
this.commit('addCard', card)
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async addCard({ commit }, card) {
|
async addCard({ commit }, card) {
|
||||||
|
|||||||
@@ -333,10 +333,15 @@ export default new Vuex.Store({
|
|||||||
commit('setAssignableUsers', board.users)
|
commit('setAssignableUsers', board.users)
|
||||||
},
|
},
|
||||||
|
|
||||||
async refreshBoard({ commit }, boardId) {
|
async refreshBoard({ commit, dispatch }, boardId) {
|
||||||
const board = await apiClient.loadById(boardId)
|
const board = await apiClient.loadById(boardId)
|
||||||
|
const etagHasChanged = board.ETag !== this.state.currentBoard.ETag
|
||||||
commit('setCurrentBoard', board)
|
commit('setCurrentBoard', board)
|
||||||
commit('setAssignableUsers', board.users)
|
commit('setAssignableUsers', board.users)
|
||||||
|
|
||||||
|
if (etagHasChanged) {
|
||||||
|
dispatch('loadStacks', boardId)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleShowArchived({ commit }) {
|
toggleShowArchived({ commit }) {
|
||||||
|
|||||||
@@ -84,14 +84,16 @@ export default {
|
|||||||
call = 'loadArchivedStacks'
|
call = 'loadArchivedStacks'
|
||||||
}
|
}
|
||||||
const stacks = await apiClient[call](boardId)
|
const stacks = await apiClient[call](boardId)
|
||||||
|
const cards = []
|
||||||
for (const i in stacks) {
|
for (const i in stacks) {
|
||||||
const stack = stacks[i]
|
const stack = stacks[i]
|
||||||
for (const j in stack.cards) {
|
for (const j in stack.cards) {
|
||||||
commit('addCard', stack.cards[j])
|
cards.push(stack.cards[j])
|
||||||
}
|
}
|
||||||
delete stack.cards
|
delete stack.cards
|
||||||
commit('addStack', stack)
|
commit('addStack', stack)
|
||||||
}
|
}
|
||||||
|
commit('setCards', cards)
|
||||||
},
|
},
|
||||||
createStack({ commit }, stack) {
|
createStack({ commit }, stack) {
|
||||||
stack.boardId = this.state.currentBoard.id
|
stack.boardId = this.state.currentBoard.id
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ class BoardServiceTest extends TestCase {
|
|||||||
|
|
||||||
public function testUpdate() {
|
public function testUpdate() {
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
|
$board->setId(123);
|
||||||
$board->setTitle('MyBoard');
|
$board->setTitle('MyBoard');
|
||||||
$board->setOwner('admin');
|
$board->setOwner('admin');
|
||||||
$board->setColor('00ff00');
|
$board->setColor('00ff00');
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use OCA\Deck\Db\LabelMapper;
|
|||||||
use OCA\Deck\Db\Stack;
|
use OCA\Deck\Db\Stack;
|
||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\Validators\StackServiceValidator;
|
use OCA\Deck\Validators\StackServiceValidator;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use \Test\TestCase;
|
use \Test\TestCase;
|
||||||
|
|
||||||
@@ -71,6 +72,8 @@ class StackServiceTest extends TestCase {
|
|||||||
private $changeHelper;
|
private $changeHelper;
|
||||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
private $eventDispatcher;
|
||||||
/** @var StackServiceValidator|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var StackServiceValidator|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $stackServiceValidator;
|
private $stackServiceValidator;
|
||||||
|
|
||||||
@@ -88,6 +91,7 @@ class StackServiceTest extends TestCase {
|
|||||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||||
$this->logger = $this->createMock(LoggerInterface::class);
|
$this->logger = $this->createMock(LoggerInterface::class);
|
||||||
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||||
$this->stackServiceValidator = $this->createMock(StackServiceValidator::class);
|
$this->stackServiceValidator = $this->createMock(StackServiceValidator::class);
|
||||||
|
|
||||||
$this->stackService = new StackService(
|
$this->stackService = new StackService(
|
||||||
@@ -103,6 +107,7 @@ class StackServiceTest extends TestCase {
|
|||||||
$this->activityManager,
|
$this->activityManager,
|
||||||
$this->changeHelper,
|
$this->changeHelper,
|
||||||
$this->logger,
|
$this->logger,
|
||||||
|
$this->eventDispatcher,
|
||||||
$this->stackServiceValidator
|
$this->stackServiceValidator
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -198,6 +203,7 @@ class StackServiceTest extends TestCase {
|
|||||||
$this->permissionService->expects($this->once())->method('checkPermission');
|
$this->permissionService->expects($this->once())->method('checkPermission');
|
||||||
$stackToBeDeleted = new Stack();
|
$stackToBeDeleted = new Stack();
|
||||||
$stackToBeDeleted->setId(1);
|
$stackToBeDeleted->setId(1);
|
||||||
|
$stackToBeDeleted->setBoardId(1);
|
||||||
$this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted);
|
$this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted);
|
||||||
$this->stackMapper->expects($this->once())->method('update')->willReturn($stackToBeDeleted);
|
$this->stackMapper->expects($this->once())->method('update')->willReturn($stackToBeDeleted);
|
||||||
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([]);
|
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([]);
|
||||||
@@ -246,6 +252,7 @@ class StackServiceTest extends TestCase {
|
|||||||
private function createStack($id, $order) {
|
private function createStack($id, $order) {
|
||||||
$stack = new Stack();
|
$stack = new Stack();
|
||||||
$stack->setId($id);
|
$stack->setId($id);
|
||||||
|
$stack->setBoardId(1);
|
||||||
$stack->setOrder($order);
|
$stack->setOrder($order);
|
||||||
return $stack;
|
return $stack;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user