Merge pull request #665 from nextcloud/enhancement/659

Implement modification changes for REST API
This commit is contained in:
Julius Härtl
2018-11-05 15:07:35 +01:00
committed by GitHub
21 changed files with 313 additions and 99 deletions

View File

@@ -46,6 +46,13 @@
<notnull>false</notnull> <notnull>false</notnull>
<unsigned>true</unsigned> <unsigned>true</unsigned>
</field> </field>
<field>
<name>last_modified</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
</declaration> </declaration>
</table> </table>
<table> <table>
@@ -85,6 +92,13 @@
<notnull>false</notnull> <notnull>false</notnull>
<unsigned>true</unsigned> <unsigned>true</unsigned>
</field> </field>
<field>
<name>last_modified</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
<index> <index>
<name>deck_stacks_board_id_index</name> <name>deck_stacks_board_id_index</name>
<field> <field>

View File

@@ -60,9 +60,14 @@ class BoardApiController extends ApiController {
* Return all of the boards that the current user has access to. * Return all of the boards that the current user has access to.
*/ */
public function index() { public function index() {
$boards = $this->service->findAll(); $modified = $this->request->getHeader('If-Modified-Since');
if ($modified === '') {
$boards = $this->service->findAll();
} else {
$boards = $this->service->findAll(strtotime($modified));
}
return new DataResponse($boards, HTTP::STATUS_OK); return new DataResponse($boards, HTTP::STATUS_OK);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
@@ -72,7 +77,7 @@ class BoardApiController extends ApiController {
* *
* Return the board specified by $this->request->getParam('boardId'). * Return the board specified by $this->request->getParam('boardId').
*/ */
public function get() { public function get() {
$board = $this->service->find($this->request->getParam('boardId')); $board = $this->service->find($this->request->getParam('boardId'));
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }
@@ -87,8 +92,8 @@ class BoardApiController extends ApiController {
* *
* Create a board with the specified title and color. * Create a board with the specified title and color.
*/ */
public function create($title, $color) { public function create($title, $color) {
$board = $this->service->create($title, $this->userId, $color); $board = $this->service->create($title, $this->userId, $color);
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }
@@ -96,14 +101,14 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $title * @params $title
* @params $color * @params $color
* @params $archived * @params $archived
* *
* Update a board with the specified boardId, title and color, and archived state. * Update a board with the specified boardId, title and color, and archived state.
*/ */
public function update($title, $color, $archived = false) { public function update($title, $color, $archived = false) {
$board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived); $board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived);
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }
@@ -112,7 +117,7 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Delete the board specified by $boardId. Return the board that was deleted. * Delete the board specified by $boardId. Return the board that was deleted.
*/ */
@@ -125,12 +130,12 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Undo the deletion of the board specified by $boardId. * Undo the deletion of the board specified by $boardId.
*/ */
public function undoDelete() { public function undoDelete() {
$board = $this->service->deleteUndo($this->request->getParam('boardId')); $board = $this->service->deleteUndo($this->request->getParam('boardId'));
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }

View File

@@ -35,8 +35,8 @@
* @package OCA\Deck\Controller * @package OCA\Deck\Controller
*/ */
class CardApiController extends ApiController { class CardApiController extends ApiController {
private $cardService; private $cardService;
private $userId; private $userId;
/** /**
* @param string $appName * @param string $appName
@@ -45,9 +45,9 @@ class CardApiController extends ApiController {
* @param $userId * @param $userId
*/ */
public function __construct($appName, IRequest $request, CardService $cardService, $userId) { public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->cardService = $cardService; $this->cardService = $cardService;
$this->userId = $userId; $this->userId = $userId;
} }
/** /**
@@ -70,7 +70,7 @@ class CardApiController extends ApiController {
* @params $title * @params $title
* @params $type * @params $type
* @params $order * @params $order
* *
* Get a specific card. * Get a specific card.
*/ */
public function create($title, $type = 'plain', $order = 999) { public function create($title, $type = 'plain', $order = 999) {
@@ -82,20 +82,20 @@ class CardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Update a card * Update a card
*/ */
public function update($title, $type, $order = 0, $description = '', $owner, $duedate = null) { public function update($title, $type, $order = 0, $description = '', $owner, $duedate = null) {
$card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $order, $description, $owner, $duedate, 0); $card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $order, $description, $owner, $duedate, 0);
return new DataResponse($card, HTTP::STATUS_OK); return new DataResponse($card, HTTP::STATUS_OK);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Delete a specific card. * Delete a specific card.
*/ */
public function delete() { public function delete() {
@@ -106,8 +106,8 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Assign a label to a card. * Assign a label to a card.
*/ */
public function assignLabel($labelId) { public function assignLabel($labelId) {
@@ -118,8 +118,8 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Assign a label to a card. * Assign a label to a card.
*/ */
public function removeLabel($labelId) { public function removeLabel($labelId) {
@@ -130,8 +130,8 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Unassign a label to a card. * Unassign a label to a card.
*/ */
public function unassignUser($userId) { public function unassignUser($userId) {
@@ -147,12 +147,12 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Unassign a label to a card. * Unassign a label to a card.
*/ */
public function reorder($stackId, $order) { public function reorder($stackId, $order) {
$card = $this->cardService->reorder($this->request->getParam('cardId'), $stackId, $order); $card = $this->cardService->reorder($this->request->getParam('cardId'), $stackId, $order);
return new DataResponse($card, HTTP::STATUS_OK); return new DataResponse($card, HTTP::STATUS_OK);
} }
} }

View File

@@ -49,7 +49,7 @@ class StackApiController extends ApiController {
public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) { public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->stackService = $stackService; $this->stackService = $stackService;
$this->boardService = $boardService; $this->boardService = $boardService;
} }
/** /**
@@ -59,8 +59,13 @@ class StackApiController extends ApiController {
* *
* Return all of the stacks in the specified board. * Return all of the stacks in the specified board.
*/ */
public function index() { public function index() {
$stacks = $this->stackService->findAll($this->request->getParam('boardId')); $since = 0;
$modified = $this->request->getHeader('If-Modified-Since');
if ($modified !== '') {
$since = strtotime($modified);
}
$stacks = $this->stackService->findAll($this->request->getParam('boardId'), $since);
return new DataResponse($stacks, HTTP::STATUS_OK); return new DataResponse($stacks, HTTP::STATUS_OK);
} }
@@ -75,7 +80,7 @@ class StackApiController extends ApiController {
$stack = $this->stackService->find($this->request->getParam('stackId')); $stack = $this->stackService->find($this->request->getParam('stackId'));
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
@@ -95,13 +100,13 @@ class StackApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $title * @params $title
* @params $order * @params $order
* *
* Update a stack by the specified stackId and boardId with the values that were put. * Update a stack by the specified stackId and boardId with the values that were put.
*/ */
public function update($title, $order) { public function update($title, $order) {
$stack = $this->stackService->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order, 0); $stack = $this->stackService->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order, 0);
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }
@@ -113,7 +118,7 @@ class StackApiController extends ApiController {
* *
* Delete the stack specified by $this->request->getParam('stackId'). * Delete the stack specified by $this->request->getParam('stackId').
*/ */
public function delete() { public function delete() {
$stack = $this->stackService->delete($this->request->getParam('stackId')); $stack = $this->stackService->delete($this->request->getParam('stackId'));
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }

View File

@@ -5,20 +5,20 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
@@ -35,12 +35,14 @@ class Board extends RelationalEntity {
protected $users = []; protected $users = [];
protected $shared; protected $shared;
protected $deletedAt = 0; protected $deletedAt = 0;
protected $lastModified = 0;
public function __construct() { public function __construct() {
$this->addType('id', 'integer'); $this->addType('id', 'integer');
$this->addType('shared', 'integer'); $this->addType('shared', 'integer');
$this->addType('archived', 'boolean'); $this->addType('archived', 'boolean');
$this->addType('deletedAt', 'integer'); $this->addType('deletedAt', 'integer');
$this->addType('lastModified', 'integer');
$this->addRelation('labels'); $this->addRelation('labels');
$this->addRelation('acl'); $this->addRelation('acl');
$this->addRelation('shared'); $this->addRelation('shared');
@@ -75,4 +77,4 @@ class Board extends RelationalEntity {
$this->acl[$a->id] = $a; $this->acl[$a->id] = $a;
} }
} }
} }

View File

@@ -62,7 +62,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
public function find($id, $withLabels = false, $withAcl = false) { public function find($id, $withLabels = false, $withAcl = false) {
$sql = 'SELECT id, title, owner, color, archived, deleted_at FROM `*PREFIX*deck_boards` ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, last_modified FROM `*PREFIX*deck_boards` ' .
'WHERE `id` = ?'; 'WHERE `id` = ?';
$board = $this->findEntity($sql, [$id]); $board = $this->findEntity($sql, [$id]);
@@ -89,11 +89,14 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @param null $offset * @param null $offset
* @return array * @return array
*/ */
public function findAllByUser($userId, $limit = null, $offset = null) { public function findAllByUser($userId, $limit = null, $offset = null, $since = 0) {
$sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared FROM `*PREFIX*deck_boards` WHERE owner = ? UNION ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ?';
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared FROM `*PREFIX*deck_boards` as boards ' . $entries = $this->findEntities($sql, [$userId, $since], $limit, $offset);
'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ?';
$entries = $this->findEntities($sql, [$userId, $userId, Acl::PERMISSION_TYPE_USER, $userId], $limit, $offset); $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ? UNION ' .
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' .
'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ? AND last_modified > ?';
$entries = $this->findEntities($sql, [$userId, $since, $userId, Acl::PERMISSION_TYPE_USER, $userId, $since], $limit, $offset);
/* @var Board $entry */ /* @var Board $entry */
foreach ($entries as $entry) { foreach ($entries as $entry) {
$acl = $this->aclMapper->findAll($entry->id); $acl = $this->aclMapper->findAll($entry->id);
@@ -115,7 +118,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
if (count($groups) <= 0) { if (count($groups) <= 0) {
return []; return [];
} }
$sql = 'SELECT boards.id, title, owner, color, archived, deleted_at, 2 as shared FROM `*PREFIX*deck_boards` as boards ' . $sql = 'SELECT boards.id, title, owner, color, archived, deleted_at, 2 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' .
'INNER JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND ('; 'INNER JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND (';
for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) { for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) {
$sql .= 'acl.participant = ? '; $sql .= 'acl.participant = ? ';
@@ -141,7 +144,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
public function findToDelete() { public function findToDelete() {
// add buffer of 5 min // add buffer of 5 min
$timeLimit = time() - (60 * 5); $timeLimit = time() - (60 * 5);
$sql = 'SELECT id, title, owner, color, archived, deleted_at FROM `*PREFIX*deck_boards` ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, last_modified FROM `*PREFIX*deck_boards` ' .
'WHERE `deleted_at` > 0 AND `deleted_at` < ?'; 'WHERE `deleted_at` > 0 AND `deleted_at` < ?';
return $this->findEntities($sql, [$timeLimit]); return $this->findEntities($sql, [$timeLimit]);
} }

View File

@@ -118,10 +118,10 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
return $card; return $card;
} }
public function findAll($stackId, $limit = null, $offset = null) { public function findAll($stackId, $limit = null, $offset = null, $since = -1) {
$sql = 'SELECT * FROM `*PREFIX*deck_cards` $sql = 'SELECT * FROM `*PREFIX*deck_cards`
WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 ORDER BY `order`'; WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 AND last_modified > ? ORDER BY `order`';
return $this->findEntities($sql, [$stackId], $limit, $offset); return $this->findEntities($sql, [$stackId, $since], $limit, $offset);
} }
public function findDeleted($boardId, $limit = null, $offset = null) { public function findDeleted($boardId, $limit = null, $offset = null) {

102
lib/Db/ChangeHelper.php Normal file
View File

@@ -0,0 +1,102 @@
<?php
/**
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IGroupManager;
class ChangeHelper {
const TYPE_BOARD = 'boardChanged';
const TYPE_CARD = 'cardChanged';
private $db;
public function __construct(
IDBConnection $db,
ICacheFactory $cacheFactory,
IRequest $request
) {
$this->db = $db;
$this->cache = $cacheFactory->createDistributed('deck_changes');
$this->request = $request;
}
public function boardChanged($boardId) {
$time = time();
$etag = md5($time . microtime());
$this->cache->set(self::TYPE_BOARD . '-' . $boardId, $etag);
$sql = 'UPDATE `*PREFIX*deck_boards` SET `last_modified` = ? WHERE `id` = ?';
$this->db->executeUpdate($sql, [$time, $boardId]);
}
public function cardChanged($cardId, $updateCard = true) {
$time = time();
$etag = md5($time . microtime());
$this->cache->set(self::TYPE_CARD . '-' .$cardId, $etag);
if ($updateCard) {
$sql = 'UPDATE `*PREFIX*deck_cards` SET `last_modified` = ? WHERE `id` = ?';
$this->db->executeUpdate($sql, [time(), $cardId]);
}
$sql = 'SELECT s.board_id as id, c.stack_id as stack_id FROM oc_deck_stacks as s inner join oc_deck_cards as c ON c.stack_id = s.id WHERE c.id = ?';
$result = $this->db->executeQuery($sql, [$cardId]);
if ($row = $result->fetch()) {
$this->boardChanged($row['id']);
$this->stackChanged($row['stack_id']);
}
}
public function stackChanged($stackId, $updateBoard = true) {
$time = time();
$etag = md5($time . microtime());
$this->cache->set(self::TYPE_CARD . '-' .$stackId, $etag);
if ($updateBoard) {
$sql = 'UPDATE `*PREFIX*deck_stacks` SET `last_modified` = ? WHERE `id` = ?';
$this->db->executeUpdate($sql, [time(), $stackId]);
}
}
public function checkEtag($type, $id) {
$etag = $this->getEtag($type, $id);
if ($this->request->getHeader('If-None-Match') === $etag) {
return true;
}
return false;
}
public function getEtag($type, $id) {
$entry = $this->cache->get($type . '-' .$id);
if ($entry === 'null') {
return '';
}
return $entry;
}
}

View File

@@ -28,6 +28,7 @@ class Stack extends RelationalEntity {
protected $title; protected $title;
protected $boardId; protected $boardId;
protected $deletedAt = 0; protected $deletedAt = 0;
protected $lastModified = 0;
protected $cards = array(); protected $cards = array();
protected $order; protected $order;
@@ -35,6 +36,7 @@ class Stack extends RelationalEntity {
$this->addType('id', 'integer'); $this->addType('id', 'integer');
$this->addType('boardId', 'integer'); $this->addType('boardId', 'integer');
$this->addType('deletedAt', 'integer'); $this->addType('deletedAt', 'integer');
$this->addType('lastModified', 'integer');
$this->addType('order', 'integer'); $this->addType('order', 'integer');
} }

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Attachment; use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
@@ -56,6 +57,8 @@ class AttachmentService {
private $l10n; private $l10n;
/** @var ActivityManager */ /** @var ActivityManager */
private $activityManager; private $activityManager;
/** @var ChangeHelper */
private $changeHelper;
/** /**
* AttachmentService constructor. * AttachmentService constructor.
@@ -69,7 +72,7 @@ class AttachmentService {
* @param IL10N $l10n * @param IL10N $l10n
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
*/ */
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId, IL10N $l10n, ActivityManager $activityManager) { public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId, IL10N $l10n, ActivityManager $activityManager) {
$this->attachmentMapper = $attachmentMapper; $this->attachmentMapper = $attachmentMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
@@ -78,6 +81,7 @@ class AttachmentService {
$this->cache = $cacheFactory->createDistributed('deck-card-attachments-'); $this->cache = $cacheFactory->createDistributed('deck-card-attachments-');
$this->l10n = $l10n; $this->l10n = $l10n;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
// Register shipped attachment services // Register shipped attachment services
// TODO: move this to a plugin based approach once we have different types of attachments // TODO: move this to a plugin based approach once we have different types of attachments
@@ -205,6 +209,7 @@ class AttachmentService {
} catch (InvalidAttachmentType $e) { } catch (InvalidAttachmentType $e) {
// just store the data // just store the data
} }
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_CREATE);
return $attachment; return $attachment;
} }
@@ -216,12 +221,11 @@ class AttachmentService {
* @param $cardId * @param $cardId
* @param $attachmentId * @param $attachmentId
* @return Response * @return Response
* @throws \OCA\Deck\NotFoundException * @throws BadRequestException
* @throws NoPermissionException * @throws NoPermissionException
* @throws NotFoundException * @throws NotFoundException
* @throws \OCP\AppFramework\Db\DoesNotExistException * @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/ */
public function display($cardId, $attachmentId) { public function display($cardId, $attachmentId) {
@@ -290,6 +294,7 @@ class AttachmentService {
} catch (InvalidAttachmentType $e) { } catch (InvalidAttachmentType $e) {
// just store the data // just store the data
} }
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE);
return $attachment; return $attachment;
} }
@@ -332,6 +337,7 @@ class AttachmentService {
// just delete without further action // just delete without further action
} }
$attachment = $this->attachmentMapper->delete($attachment); $attachment = $this->attachmentMapper->delete($attachment);
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE);
return $attachment; return $attachment;
} }
@@ -355,6 +361,7 @@ class AttachmentService {
if ($service->allowUndo()) { if ($service->allowUndo()) {
$attachment->setDeletedAt(0); $attachment->setDeletedAt(0);
$attachment = $this->attachmentMapper->update($attachment); $attachment = $this->attachmentMapper->update($attachment);
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_RESTORE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_RESTORE);
return $attachment; return $attachment;
} }

View File

@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\IPermissionMapper; use OCA\Deck\Db\IPermissionMapper;
use OCA\Deck\Db\Label; use OCA\Deck\Db\Label;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
@@ -54,6 +55,7 @@ class BoardService {
private $groupManager; private $groupManager;
private $userId; private $userId;
private $activityManager; private $activityManager;
private $changeHelper;
public function __construct( public function __construct(
BoardMapper $boardMapper, BoardMapper $boardMapper,
@@ -66,6 +68,7 @@ class BoardService {
IUserManager $userManager, IUserManager $userManager,
IGroupManager $groupManager, IGroupManager $groupManager,
ActivityManager $activityManager, ActivityManager $activityManager,
ChangeHelper $changeHelper,
$userId $userId
) { ) {
$this->boardMapper = $boardMapper; $this->boardMapper = $boardMapper;
@@ -78,16 +81,17 @@ class BoardService {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
$this->userId = $userId; $this->userId = $userId;
} }
/** /**
* @return array * @return array
*/ */
public function findAll() { public function findAll($since = 0) {
$userInfo = $this->getBoardPrerequisites(); $userInfo = $this->getBoardPrerequisites();
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']); $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']); $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
$complete = array_merge($userBoards, $groupBoards); $complete = array_merge($userBoards, $groupBoards);
$result = []; $result = [];
foreach ($complete as &$item) { foreach ($complete as &$item) {
@@ -276,6 +280,7 @@ class BoardService {
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] 'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
]); ]);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
$this->changeHelper->boardChanged($new_board->getId());
return $new_board; return $new_board;
} }
@@ -299,6 +304,7 @@ class BoardService {
$board->setDeletedAt(time()); $board->setDeletedAt(time());
$board = $this->boardMapper->update($board); $board = $this->boardMapper->update($board);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE);
$this->changeHelper->boardChanged($board->getId());
return $board; return $board;
} }
@@ -320,6 +326,7 @@ class BoardService {
$board->setDeletedAt(0); $board->setDeletedAt(0);
$board = $this->boardMapper->update($board); $board = $this->boardMapper->update($board);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
$this->changeHelper->boardChanged($board->getId());
return $board; return $board;
} }
@@ -380,6 +387,7 @@ class BoardService {
$this->boardMapper->update($board); // operate on clone so we can check for updated fields $this->boardMapper->update($board); // operate on clone so we can check for updated fields
$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());
return $board; return $board;
} }
@@ -392,8 +400,8 @@ class BoardService {
* @param $share * @param $share
* @param $manage * @param $manage
* @return \OCP\AppFramework\Db\Entity * @return \OCP\AppFramework\Db\Entity
* @throws \OCA\Deck\
* @throws BadRequestException * @throws BadRequestException
* @throws \OCA\Deck\NoPermissionException
*/ */
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) { public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
@@ -436,6 +444,7 @@ class BoardService {
$newAcl = $this->aclMapper->insert($acl); $newAcl = $this->aclMapper->insert($acl);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
$this->boardMapper->mapAcl($newAcl); $this->boardMapper->mapAcl($newAcl);
$this->changeHelper->boardChanged($boardId);
return $newAcl; return $newAcl;
} }
@@ -475,7 +484,9 @@ class BoardService {
$acl->setPermissionShare($share); $acl->setPermissionShare($share);
$acl->setPermissionManage($manage); $acl->setPermissionManage($manage);
$this->boardMapper->mapAcl($acl); $this->boardMapper->mapAcl($acl);
return $this->aclMapper->update($acl); $board = $this->aclMapper->update($acl);
$this->changeHelper->boardChanged($acl->getBoardId());
return $board;
} }
/** /**
@@ -503,6 +514,7 @@ class BoardService {
} }
} }
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
$this->changeHelper->boardChanged($acl->getBoardId());
return $this->aclMapper->delete($acl); return $this->aclMapper->delete($acl);
} }

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
@@ -54,6 +55,8 @@ class CardService {
private $currentUser; private $currentUser;
private $activityManager; private $activityManager;
private $commentsManager; private $commentsManager;
private $changeHelper;
private $userManager;
public function __construct( public function __construct(
CardMapper $cardMapper, CardMapper $cardMapper,
@@ -68,6 +71,7 @@ class CardService {
ActivityManager $activityManager, ActivityManager $activityManager,
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
ChangeHelper $changeHelper,
$userId $userId
) { ) {
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
@@ -82,6 +86,7 @@ class CardService {
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->commentsManager = $commentsManager; $this->commentsManager = $commentsManager;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->changeHelper = $changeHelper;
$this->currentUser = $userId; $this->currentUser = $userId;
} }
@@ -176,6 +181,7 @@ class CardService {
$card->setOwner($owner); $card->setOwner($owner);
$card = $this->cardMapper->insert($card); $card = $this->cardMapper->insert($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -202,6 +208,7 @@ class CardService {
$card->setDeletedAt(time()); $card->setDeletedAt(time());
$this->cardMapper->update($card); $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -263,6 +270,7 @@ class CardService {
$changes->setAfter($card); $changes->setAfter($card);
$card = $this->cardMapper->update($card); $card = $this->cardMapper->update($card);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE); $this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -295,6 +303,7 @@ class CardService {
throw new StatusException('Operation not allowed. This card is archived.'); throw new StatusException('Operation not allowed. This card is archived.');
} }
$card->setTitle($title); $card->setTitle($title);
$this->changeHelper->cardChanged($card->getId(), false);
return $this->cardMapper->update($card); return $this->cardMapper->update($card);
} }
@@ -349,7 +358,7 @@ class CardService {
$this->cardMapper->update($card); $this->cardMapper->update($card);
$result[$card->getOrder()] = $card; $result[$card->getOrder()] = $card;
} }
$this->changeHelper->cardChanged($id, false);
return $result; return $result;
} }
@@ -376,6 +385,7 @@ class CardService {
$card->setArchived(true); $card->setArchived(true);
$newCard = $this->cardMapper->update($card); $newCard = $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_ARCHIVE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_ARCHIVE);
$this->changeHelper->cardChanged($id, false);
return $newCard; return $newCard;
} }
@@ -402,6 +412,7 @@ class CardService {
$card->setArchived(false); $card->setArchived(false);
$newCard = $this->cardMapper->update($card); $newCard = $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_UNARCHIVE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_UNARCHIVE);
$this->changeHelper->cardChanged($id, false);
return $newCard; return $newCard;
} }
@@ -434,6 +445,7 @@ class CardService {
} }
$label = $this->labelMapper->find($labelId); $label = $this->labelMapper->find($labelId);
$this->cardMapper->assignLabel($cardId, $labelId); $this->cardMapper->assignLabel($cardId, $labelId);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
} }
@@ -466,6 +478,7 @@ class CardService {
} }
$label = $this->labelMapper->find($labelId); $label = $this->labelMapper->find($labelId);
$this->cardMapper->removeLabel($cardId, $labelId); $this->cardMapper->removeLabel($cardId, $labelId);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
} }
@@ -473,9 +486,10 @@ class CardService {
* @param $cardId * @param $cardId
* @param $userId * @param $userId
* @return bool|null|\OCP\AppFramework\Db\Entity * @return bool|null|\OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException * @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/ */
public function assignUser($cardId, $userId) { public function assignUser($cardId, $userId) {
@@ -505,6 +519,7 @@ class CardService {
$assignment->setCardId($cardId); $assignment->setCardId($cardId);
$assignment->setParticipant($userId); $assignment->setParticipant($userId);
$assignment = $this->assignedUsersMapper->insert($assignment); $assignment = $this->assignedUsersMapper->insert($assignment);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]);
return $assignment; return $assignment;
} }
@@ -513,10 +528,11 @@ class CardService {
* @param $cardId * @param $cardId
* @param $userId * @param $userId
* @return \OCP\AppFramework\Db\Entity * @return \OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws NotFoundException * @throws NotFoundException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException * @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/ */
public function unassignUser($cardId, $userId) { public function unassignUser($cardId, $userId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
@@ -535,6 +551,7 @@ class CardService {
$assignment = $this->assignedUsersMapper->delete($assignment); $assignment = $this->assignedUsersMapper->delete($assignment);
$card = $this->cardMapper->find($cardId); $card = $this->cardMapper->find($cardId);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
$this->changeHelper->cardChanged($cardId, false);
return $assignment; return $assignment;
} }
} }

View File

@@ -5,24 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label; use OCA\Deck\Db\Label;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
@@ -38,11 +39,14 @@ class LabelService {
private $permissionService; private $permissionService;
/** @var BoardService */ /** @var BoardService */
private $boardService; private $boardService;
/** @var ChangeHelper */
private $changeHelper;
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService) { public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService, ChangeHelper $changeHelper) {
$this->labelMapper = $labelMapper; $this->labelMapper = $labelMapper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->boardService = $boardService; $this->boardService = $boardService;
$this->changeHelper = $changeHelper;
} }
/** /**
@@ -94,6 +98,7 @@ class LabelService {
$label->setTitle($title); $label->setTitle($title);
$label->setColor($color); $label->setColor($color);
$label->setBoardId($boardId); $label->setBoardId($boardId);
$this->changeHelper->boardChanged($boardId);
return $this->labelMapper->insert($label); return $this->labelMapper->insert($label);
} }
@@ -116,7 +121,9 @@ class LabelService {
if ($this->boardService->isArchived($this->labelMapper, $id)) { if ($this->boardService->isArchived($this->labelMapper, $id)) {
throw new StatusException('Operation not allowed. This board is archived.'); throw new StatusException('Operation not allowed. This board is archived.');
} }
return $this->labelMapper->delete($this->find($id)); $label = $this->labelMapper->delete($this->find($id));
$this->changeHelper->boardChanged($label->getBoardId());
return $label;
} }
/** /**
@@ -151,7 +158,8 @@ class LabelService {
$label = $this->find($id); $label = $this->find($id);
$label->setTitle($title); $label->setTitle($title);
$label->setColor($color); $label->setColor($color);
$this->changeHelper->boardChanged($label->getBoardId());
return $this->labelMapper->update($label); return $this->labelMapper->update($label);
} }
} }

View File

@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Stack; use OCA\Deck\Db\Stack;
@@ -49,6 +50,7 @@ class StackService {
private $assignedUsersMapper; private $assignedUsersMapper;
private $attachmentService; private $attachmentService;
private $activityManager; private $activityManager;
private $changeHelper;
public function __construct( public function __construct(
StackMapper $stackMapper, StackMapper $stackMapper,
@@ -60,7 +62,8 @@ class StackService {
CardService $cardService, CardService $cardService,
AssignedUsersMapper $assignedUsersMapper, AssignedUsersMapper $assignedUsersMapper,
AttachmentService $attachmentService, AttachmentService $attachmentService,
ActivityManager $activityManager ActivityManager $activityManager,
ChangeHelper $changeHelper
) { ) {
$this->stackMapper = $stackMapper; $this->stackMapper = $stackMapper;
$this->boardMapper = $boardMapper; $this->boardMapper = $boardMapper;
@@ -72,12 +75,13 @@ class StackService {
$this->assignedUsersMapper = $assignedUsersMapper; $this->assignedUsersMapper = $assignedUsersMapper;
$this->attachmentService = $attachmentService; $this->attachmentService = $attachmentService;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
} }
private function enrichStackWithCards($stack) { private function enrichStackWithCards($stack, $since = -1) {
$cards = $this->cardMapper->findAll($stack->getId()); $cards = $this->cardMapper->findAll($stack->getId(), null, null, $since);
if(is_null($cards)) { if(\count($cards) === 0) {
return; return;
} }
@@ -88,9 +92,9 @@ class StackService {
$stack->setCards($cards); $stack->setCards($cards);
} }
private function enrichStacksWithCards($stacks) { private function enrichStacksWithCards($stacks, $since = -1) {
foreach ($stacks as $stack) { foreach ($stacks as $stack) {
$this->enrichStackWithCards($stack); $this->enrichStackWithCards($stack, $since);
} }
} }
@@ -123,14 +127,14 @@ class StackService {
* @throws \OCA\Deck\NoPermissionException * @throws \OCA\Deck\NoPermissionException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function findAll($boardId) { public function findAll($boardId, $since = 0) {
if (is_numeric($boardId) === false) { if (is_numeric($boardId) === false) {
throw new BadRequestException('boardId must be a number'); throw new BadRequestException('boardId must be a number');
} }
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ); $this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
$stacks = $this->stackMapper->findAll($boardId); $stacks = $this->stackMapper->findAll($boardId);
$this->enrichStacksWithCards($stacks); $this->enrichStacksWithCards($stacks, $since);
return $stacks; return $stacks;
} }
@@ -203,6 +207,7 @@ class StackService {
$stack->setOrder($order); $stack->setOrder($order);
$stack = $this->stackMapper->insert($stack); $stack = $this->stackMapper->insert($stack);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE);
$this->changeHelper->boardChanged($boardId);
return $stack; return $stack;
} }
@@ -227,7 +232,7 @@ class StackService {
$stack = $this->stackMapper->update($stack); $stack = $this->stackMapper->update($stack);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE);
$this->changeHelper->boardChanged($stack->getBoardId());
$this->enrichStackWithCards($stack); $this->enrichStackWithCards($stack);
return $stack; return $stack;
} }
@@ -276,6 +281,7 @@ class StackService {
$changes->setAfter($stack); $changes->setAfter($stack);
$stack = $this->stackMapper->update($stack); $stack = $this->stackMapper->update($stack);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE); $this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE);
$this->changeHelper->boardChanged($stack->getBoardId());
return $stack; return $stack;
} }
@@ -318,7 +324,7 @@ class StackService {
$this->stackMapper->update($stack); $this->stackMapper->update($stack);
$result[$stack->getOrder()] = $stack; $result[$stack->getOrder()] = $stack;
} }
$this->changeHelper->boardChanged($stackToSort->getBoardId());
return $result; return $result;
} }
} }

View File

@@ -26,6 +26,7 @@ class BoardTest extends TestCase {
'labels' => array(), 'labels' => array(),
'permissions' => [], 'permissions' => [],
'deletedAt' => 0, 'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(), 'acl' => array(),
'archived' => false, 'archived' => false,
'users' => ['user1', 'user2'], 'users' => ['user1', 'user2'],
@@ -43,6 +44,7 @@ class BoardTest extends TestCase {
'labels' => array("foo", "bar"), 'labels' => array("foo", "bar"),
'permissions' => [], 'permissions' => [],
'deletedAt' => 0, 'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(), 'acl' => array(),
'archived' => false, 'archived' => false,
'users' => [], 'users' => [],
@@ -67,10 +69,11 @@ class BoardTest extends TestCase {
'labels' => array(), 'labels' => array(),
'permissions' => [], 'permissions' => [],
'deletedAt' => 0, 'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(), 'acl' => array(),
'archived' => false, 'archived' => false,
'shared' => 1, 'shared' => 1,
'users' => [], 'users' => [],
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
} }

View File

@@ -39,7 +39,8 @@ class StackTest extends \Test\TestCase {
'title' => "My Stack", 'title' => "My Stack",
'order' => 1, 'order' => 1,
'boardId' => 1, 'boardId' => 1,
'deletedAt' => 0 'deletedAt' => 0,
'lastModified' => 0,
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
public function testJsonSerializeWithCards() { public function testJsonSerializeWithCards() {
@@ -52,7 +53,8 @@ class StackTest extends \Test\TestCase {
'order' => 1, 'order' => 1,
'boardId' => 1, 'boardId' => 1,
'cards' => array("foo", "bar"), 'cards' => array("foo", "bar"),
'deletedAt' => 0 'deletedAt' => 0,
'lastModified' => 0,
], $board->jsonSerialize()); ], $board->jsonSerialize());
} }
} }

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Attachment; use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\AppFramework\IAppContainer; use OCP\AppFramework\IAppContainer;
@@ -73,6 +74,8 @@ class AttachmentServiceTest extends TestCase {
private $cache; private $cache;
/** @var IL10N */ /** @var IL10N */
private $l10n; private $l10n;
/** @var ChangeHelper */
private $changeHelper;
/** /**
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
@@ -99,8 +102,9 @@ class AttachmentServiceTest extends TestCase {
->willReturn($this->appContainer); ->willReturn($this->appContainer);
$this->l10n = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
} }
public function testRegisterAttachmentService() { public function testRegisterAttachmentService() {
@@ -112,7 +116,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file')); $this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom'))); $this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
@@ -130,7 +134,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class); $attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$attachmentService->getService('deck_file_invalid'); $attachmentService->getService('deck_file_invalid');
} }

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Board; use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCP\IUser; use OCP\IUser;
@@ -62,7 +63,8 @@ class BoardServiceTest extends TestCase {
private $groupManager; private $groupManager;
/** @var ActivityManager */ /** @var ActivityManager */
private $activityManager; private $activityManager;
/** @var ChangeHelper */
private $changeHelper;
private $userId = 'admin'; private $userId = 'admin';
public function setUp() { public function setUp() {
@@ -77,6 +79,7 @@ class BoardServiceTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class); $this->groupManager = $this->createMock(IGroupManager::class);
$this->activityManager = $this->createMock(ActivityManager::class); $this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->service = new BoardService( $this->service = new BoardService(
$this->boardMapper, $this->boardMapper,
@@ -89,6 +92,7 @@ class BoardServiceTest extends TestCase {
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->activityManager, $this->activityManager,
$this->changeHelper,
$this->userId $this->userId
); );

View File

@@ -29,6 +29,7 @@ use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper; use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
@@ -69,6 +70,8 @@ class CardServiceTest extends TestCase {
private $commentsManager; private $commentsManager;
/** @var ICommentsManager|MockObject */ /** @var ICommentsManager|MockObject */
private $userManager; private $userManager;
/** @var ChangeHelper|MockObject */
private $changeHelper;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
@@ -84,6 +87,7 @@ class CardServiceTest extends TestCase {
$this->activityManager = $this->createMock(ActivityManager::class); $this->activityManager = $this->createMock(ActivityManager::class);
$this->commentsManager = $this->createMock(ICommentsManager::class); $this->commentsManager = $this->createMock(ICommentsManager::class);
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->cardService = new CardService( $this->cardService = new CardService(
$this->cardMapper, $this->cardMapper,
$this->stackMapper, $this->stackMapper,
@@ -97,6 +101,7 @@ class CardServiceTest extends TestCase {
$this->activityManager, $this->activityManager,
$this->commentsManager, $this->commentsManager,
$this->userManager, $this->userManager,
$this->changeHelper,
'user1' 'user1'
); );
} }

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Service; namespace OCA\Deck\Service;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label; use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
use Test\TestCase; use Test\TestCase;
@@ -38,6 +39,8 @@ class LabelServiceTest extends TestCase {
private $labelService; private $labelService;
/** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */ /** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */
private $boardService; private $boardService;
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
private $changeHelper;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
@@ -46,10 +49,12 @@ class LabelServiceTest extends TestCase {
$this->permissionService = $this->getMockBuilder(PermissionService::class) $this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class); $this->boardService = $this->createMock(BoardService::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->labelService = new LabelService( $this->labelService = new LabelService(
$this->labelMapper, $this->labelMapper,
$this->permissionService, $this->permissionService,
$this->boardService $this->boardService,
$this->changeHelper
); );
} }
@@ -95,13 +100,15 @@ class LabelServiceTest extends TestCase {
} }
public function testDelete() { public function testDelete() {
$label = new Label();
$label->setId(1);
$this->labelMapper->expects($this->once()) $this->labelMapper->expects($this->once())
->method('find') ->method('find')
->willReturn(new Label()); ->willReturn($label);
$this->labelMapper->expects($this->once()) $this->labelMapper->expects($this->once())
->method('delete') ->method('delete')
->willReturn(1); ->willReturn($label);
$this->assertEquals(1, $this->labelService->delete(123)); $this->assertEquals($label, $this->labelService->delete(1));
} }
} }

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label; use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper; use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack; use OCA\Deck\Db\Stack;
@@ -66,6 +67,8 @@ class StackServiceTest extends TestCase {
private $cardService; private $cardService;
/** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */
private $activityManager; private $activityManager;
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
private $changeHelper;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
@@ -79,6 +82,7 @@ class StackServiceTest extends TestCase {
$this->attachmentService = $this->createMock(AttachmentService::class); $this->attachmentService = $this->createMock(AttachmentService::class);
$this->labelMapper = $this->createMock(LabelMapper::class); $this->labelMapper = $this->createMock(LabelMapper::class);
$this->activityManager = $this->createMock(ActivityManager::class); $this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->stackService = new StackService( $this->stackService = new StackService(
$this->stackMapper, $this->stackMapper,
@@ -90,7 +94,8 @@ class StackServiceTest extends TestCase {
$this->cardService, $this->cardService,
$this->assignedUsersMapper, $this->assignedUsersMapper,
$this->attachmentService, $this->attachmentService,
$this->activityManager $this->activityManager,
$this->changeHelper
); );
} }
@@ -185,6 +190,7 @@ class StackServiceTest extends TestCase {
$stackToBeDeleted->setId(1); $stackToBeDeleted->setId(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->stackService->delete(123); $this->stackService->delete(123);
$this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past"); $this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past");
$this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set"); $this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set");