Merge pull request #665 from nextcloud/enhancement/659
Implement modification changes for REST API
This commit is contained in:
@@ -46,6 +46,13 @@
|
||||
<notnull>false</notnull>
|
||||
<unsigned>true</unsigned>
|
||||
</field>
|
||||
<field>
|
||||
<name>last_modified</name>
|
||||
<type>integer</type>
|
||||
<default></default>
|
||||
<notnull>false</notnull>
|
||||
<unsigned>true</unsigned>
|
||||
</field>
|
||||
</declaration>
|
||||
</table>
|
||||
<table>
|
||||
@@ -85,6 +92,13 @@
|
||||
<notnull>false</notnull>
|
||||
<unsigned>true</unsigned>
|
||||
</field>
|
||||
<field>
|
||||
<name>last_modified</name>
|
||||
<type>integer</type>
|
||||
<default></default>
|
||||
<notnull>false</notnull>
|
||||
<unsigned>true</unsigned>
|
||||
</field>
|
||||
<index>
|
||||
<name>deck_stacks_board_id_index</name>
|
||||
<field>
|
||||
|
||||
@@ -60,9 +60,14 @@ class BoardApiController extends ApiController {
|
||||
* Return all of the boards that the current user has access to.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
@@ -72,7 +77,7 @@ class BoardApiController extends ApiController {
|
||||
*
|
||||
* Return the board specified by $this->request->getParam('boardId').
|
||||
*/
|
||||
public function get() {
|
||||
public function get() {
|
||||
$board = $this->service->find($this->request->getParam('boardId'));
|
||||
return new DataResponse($board, HTTP::STATUS_OK);
|
||||
}
|
||||
@@ -87,8 +92,8 @@ class BoardApiController extends ApiController {
|
||||
*
|
||||
* Create a board with the specified title and color.
|
||||
*/
|
||||
public function create($title, $color) {
|
||||
$board = $this->service->create($title, $this->userId, $color);
|
||||
public function create($title, $color) {
|
||||
$board = $this->service->create($title, $this->userId, $color);
|
||||
return new DataResponse($board, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
@@ -96,14 +101,14 @@ class BoardApiController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
*
|
||||
* @params $title
|
||||
* @params $color
|
||||
* @params $archived
|
||||
* @params $color
|
||||
* @params $archived
|
||||
*
|
||||
* 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);
|
||||
return new DataResponse($board, HTTP::STATUS_OK);
|
||||
}
|
||||
@@ -112,7 +117,7 @@ class BoardApiController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
*
|
||||
*
|
||||
* Delete the board specified by $boardId. Return the board that was deleted.
|
||||
*/
|
||||
@@ -125,12 +130,12 @@ class BoardApiController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
*
|
||||
*
|
||||
* Undo the deletion of the board specified by $boardId.
|
||||
*/
|
||||
public function undoDelete() {
|
||||
$board = $this->service->deleteUndo($this->request->getParam('boardId'));
|
||||
public function undoDelete() {
|
||||
$board = $this->service->deleteUndo($this->request->getParam('boardId'));
|
||||
return new DataResponse($board, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
* @package OCA\Deck\Controller
|
||||
*/
|
||||
class CardApiController extends ApiController {
|
||||
private $cardService;
|
||||
private $userId;
|
||||
private $cardService;
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
@@ -45,9 +45,9 @@ class CardApiController extends ApiController {
|
||||
* @param $userId
|
||||
*/
|
||||
public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->cardService = $cardService;
|
||||
$this->userId = $userId;
|
||||
parent::__construct($appName, $request);
|
||||
$this->cardService = $cardService;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class CardApiController extends ApiController {
|
||||
* @params $title
|
||||
* @params $type
|
||||
* @params $order
|
||||
*
|
||||
*
|
||||
* Get a specific card.
|
||||
*/
|
||||
public function create($title, $type = 'plain', $order = 999) {
|
||||
@@ -82,20 +82,20 @@ class CardApiController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Update a card
|
||||
*/
|
||||
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);
|
||||
return new DataResponse($card, HTTP::STATUS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Delete a specific card.
|
||||
*/
|
||||
public function delete() {
|
||||
@@ -106,8 +106,8 @@ class CardApiController extends ApiController {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Assign a label to a card.
|
||||
*/
|
||||
public function assignLabel($labelId) {
|
||||
@@ -118,8 +118,8 @@ class CardApiController extends ApiController {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Assign a label to a card.
|
||||
*/
|
||||
public function removeLabel($labelId) {
|
||||
@@ -130,8 +130,8 @@ class CardApiController extends ApiController {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Unassign a label to a card.
|
||||
*/
|
||||
public function unassignUser($userId) {
|
||||
@@ -147,12 +147,12 @@ class CardApiController extends ApiController {
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Unassign a label to a card.
|
||||
*/
|
||||
public function reorder($stackId, $order) {
|
||||
$card = $this->cardService->reorder($this->request->getParam('cardId'), $stackId, $order);
|
||||
return new DataResponse($card, HTTP::STATUS_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class StackApiController extends ApiController {
|
||||
public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) {
|
||||
parent::__construct($appName, $request);
|
||||
$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.
|
||||
*/
|
||||
public function index() {
|
||||
$stacks = $this->stackService->findAll($this->request->getParam('boardId'));
|
||||
public function index() {
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -75,7 +80,7 @@ class StackApiController extends ApiController {
|
||||
$stack = $this->stackService->find($this->request->getParam('stackId'));
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
@@ -95,13 +100,13 @@ class StackApiController extends ApiController {
|
||||
* @NoAdminRequired
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @params $title
|
||||
*
|
||||
* @params $title
|
||||
* @params $order
|
||||
*
|
||||
* 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);
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
}
|
||||
@@ -113,7 +118,7 @@ class StackApiController extends ApiController {
|
||||
*
|
||||
* Delete the stack specified by $this->request->getParam('stackId').
|
||||
*/
|
||||
public function delete() {
|
||||
public function delete() {
|
||||
$stack = $this->stackService->delete($this->request->getParam('stackId'));
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,20 @@
|
||||
* @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;
|
||||
@@ -35,12 +35,14 @@ class Board extends RelationalEntity {
|
||||
protected $users = [];
|
||||
protected $shared;
|
||||
protected $deletedAt = 0;
|
||||
protected $lastModified = 0;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('shared', 'integer');
|
||||
$this->addType('archived', 'boolean');
|
||||
$this->addType('deletedAt', 'integer');
|
||||
$this->addType('lastModified', 'integer');
|
||||
$this->addRelation('labels');
|
||||
$this->addRelation('acl');
|
||||
$this->addRelation('shared');
|
||||
@@ -75,4 +77,4 @@ class Board extends RelationalEntity {
|
||||
$this->acl[$a->id] = $a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @throws DoesNotExistException
|
||||
*/
|
||||
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` = ?';
|
||||
$board = $this->findEntity($sql, [$id]);
|
||||
|
||||
@@ -89,11 +89,14 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @param null $offset
|
||||
* @return array
|
||||
*/
|
||||
public function findAllByUser($userId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared FROM `*PREFIX*deck_boards` WHERE owner = ? UNION ' .
|
||||
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared 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 != ?';
|
||||
$entries = $this->findEntities($sql, [$userId, $userId, Acl::PERMISSION_TYPE_USER, $userId], $limit, $offset);
|
||||
public function findAllByUser($userId, $limit = null, $offset = null, $since = 0) {
|
||||
$sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ?';
|
||||
$entries = $this->findEntities($sql, [$userId, $since], $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 */
|
||||
foreach ($entries as $entry) {
|
||||
$acl = $this->aclMapper->findAll($entry->id);
|
||||
@@ -115,7 +118,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
if (count($groups) <= 0) {
|
||||
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 (';
|
||||
for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) {
|
||||
$sql .= 'acl.participant = ? ';
|
||||
@@ -141,7 +144,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
public function findToDelete() {
|
||||
// add buffer of 5 min
|
||||
$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` < ?';
|
||||
return $this->findEntities($sql, [$timeLimit]);
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
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`
|
||||
WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 ORDER BY `order`';
|
||||
return $this->findEntities($sql, [$stackId], $limit, $offset);
|
||||
WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 AND last_modified > ? ORDER BY `order`';
|
||||
return $this->findEntities($sql, [$stackId, $since], $limit, $offset);
|
||||
}
|
||||
|
||||
public function findDeleted($boardId, $limit = null, $offset = null) {
|
||||
|
||||
102
lib/Db/ChangeHelper.php
Normal file
102
lib/Db/ChangeHelper.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ class Stack extends RelationalEntity {
|
||||
protected $title;
|
||||
protected $boardId;
|
||||
protected $deletedAt = 0;
|
||||
protected $lastModified = 0;
|
||||
protected $cards = array();
|
||||
protected $order;
|
||||
|
||||
@@ -35,6 +36,7 @@ class Stack extends RelationalEntity {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('boardId', 'integer');
|
||||
$this->addType('deletedAt', 'integer');
|
||||
$this->addType('lastModified', 'integer');
|
||||
$this->addType('order', 'integer');
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Attachment;
|
||||
use OCA\Deck\Db\AttachmentMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\InvalidAttachmentType;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\NotFoundException;
|
||||
@@ -56,6 +57,8 @@ class AttachmentService {
|
||||
private $l10n;
|
||||
/** @var ActivityManager */
|
||||
private $activityManager;
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
|
||||
/**
|
||||
* AttachmentService constructor.
|
||||
@@ -69,7 +72,7 @@ class AttachmentService {
|
||||
* @param IL10N $l10n
|
||||
* @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->cardMapper = $cardMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
@@ -78,6 +81,7 @@ class AttachmentService {
|
||||
$this->cache = $cacheFactory->createDistributed('deck-card-attachments-');
|
||||
$this->l10n = $l10n;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
|
||||
// Register shipped attachment services
|
||||
// TODO: move this to a plugin based approach once we have different types of attachments
|
||||
@@ -205,6 +209,7 @@ class AttachmentService {
|
||||
} catch (InvalidAttachmentType $e) {
|
||||
// just store the data
|
||||
}
|
||||
$this->changeHelper->cardChanged($attachment->getCardId());
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_CREATE);
|
||||
return $attachment;
|
||||
}
|
||||
@@ -216,12 +221,11 @@ class AttachmentService {
|
||||
* @param $cardId
|
||||
* @param $attachmentId
|
||||
* @return Response
|
||||
* @throws \OCA\Deck\NotFoundException
|
||||
* @throws BadRequestException
|
||||
* @throws NoPermissionException
|
||||
* @throws NotFoundException
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
* @throws \OCP\AppFramework\Db\
|
||||
* @throws BadRequestException
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
*/
|
||||
public function display($cardId, $attachmentId) {
|
||||
|
||||
@@ -290,6 +294,7 @@ class AttachmentService {
|
||||
} catch (InvalidAttachmentType $e) {
|
||||
// just store the data
|
||||
}
|
||||
$this->changeHelper->cardChanged($attachment->getCardId());
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE);
|
||||
return $attachment;
|
||||
}
|
||||
@@ -332,6 +337,7 @@ class AttachmentService {
|
||||
// just delete without further action
|
||||
}
|
||||
$attachment = $this->attachmentMapper->delete($attachment);
|
||||
$this->changeHelper->cardChanged($attachment->getCardId());
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE);
|
||||
return $attachment;
|
||||
}
|
||||
@@ -355,6 +361,7 @@ class AttachmentService {
|
||||
if ($service->allowUndo()) {
|
||||
$attachment->setDeletedAt(0);
|
||||
$attachment = $this->attachmentMapper->update($attachment);
|
||||
$this->changeHelper->cardChanged($attachment->getCardId());
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_RESTORE);
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\IPermissionMapper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
@@ -54,6 +55,7 @@ class BoardService {
|
||||
private $groupManager;
|
||||
private $userId;
|
||||
private $activityManager;
|
||||
private $changeHelper;
|
||||
|
||||
public function __construct(
|
||||
BoardMapper $boardMapper,
|
||||
@@ -66,6 +68,7 @@ class BoardService {
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
ActivityManager $activityManager,
|
||||
ChangeHelper $changeHelper,
|
||||
$userId
|
||||
) {
|
||||
$this->boardMapper = $boardMapper;
|
||||
@@ -78,16 +81,17 @@ class BoardService {
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findAll() {
|
||||
public function findAll($since = 0) {
|
||||
$userInfo = $this->getBoardPrerequisites();
|
||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
|
||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
|
||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
|
||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
|
||||
$complete = array_merge($userBoards, $groupBoards);
|
||||
$result = [];
|
||||
foreach ($complete as &$item) {
|
||||
@@ -276,6 +280,7 @@ class BoardService {
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
|
||||
]);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
|
||||
$this->changeHelper->boardChanged($new_board->getId());
|
||||
return $new_board;
|
||||
|
||||
}
|
||||
@@ -299,6 +304,7 @@ class BoardService {
|
||||
$board->setDeletedAt(time());
|
||||
$board = $this->boardMapper->update($board);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE);
|
||||
$this->changeHelper->boardChanged($board->getId());
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -320,6 +326,7 @@ class BoardService {
|
||||
$board->setDeletedAt(0);
|
||||
$board = $this->boardMapper->update($board);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
|
||||
$this->changeHelper->boardChanged($board->getId());
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -380,6 +387,7 @@ class BoardService {
|
||||
$this->boardMapper->update($board); // operate on clone so we can check for updated fields
|
||||
$this->boardMapper->mapOwner($board);
|
||||
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
|
||||
$this->changeHelper->boardChanged($board->getId());
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -392,8 +400,8 @@ class BoardService {
|
||||
* @param $share
|
||||
* @param $manage
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
* @throws \OCA\Deck\
|
||||
* @throws BadRequestException
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
*/
|
||||
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
|
||||
|
||||
@@ -436,6 +444,7 @@ class BoardService {
|
||||
$newAcl = $this->aclMapper->insert($acl);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
|
||||
$this->boardMapper->mapAcl($newAcl);
|
||||
$this->changeHelper->boardChanged($boardId);
|
||||
return $newAcl;
|
||||
}
|
||||
|
||||
@@ -475,7 +484,9 @@ class BoardService {
|
||||
$acl->setPermissionShare($share);
|
||||
$acl->setPermissionManage($manage);
|
||||
$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->changeHelper->boardChanged($acl->getBoardId());
|
||||
return $this->aclMapper->delete($acl);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
@@ -54,6 +55,8 @@ class CardService {
|
||||
private $currentUser;
|
||||
private $activityManager;
|
||||
private $commentsManager;
|
||||
private $changeHelper;
|
||||
private $userManager;
|
||||
|
||||
public function __construct(
|
||||
CardMapper $cardMapper,
|
||||
@@ -68,6 +71,7 @@ class CardService {
|
||||
ActivityManager $activityManager,
|
||||
ICommentsManager $commentsManager,
|
||||
IUserManager $userManager,
|
||||
ChangeHelper $changeHelper,
|
||||
$userId
|
||||
) {
|
||||
$this->cardMapper = $cardMapper;
|
||||
@@ -82,6 +86,7 @@ class CardService {
|
||||
$this->activityManager = $activityManager;
|
||||
$this->commentsManager = $commentsManager;
|
||||
$this->userManager = $userManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->currentUser = $userId;
|
||||
}
|
||||
|
||||
@@ -176,6 +181,7 @@ class CardService {
|
||||
$card->setOwner($owner);
|
||||
$card = $this->cardMapper->insert($card);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE);
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
return $card;
|
||||
}
|
||||
|
||||
@@ -202,6 +208,7 @@ class CardService {
|
||||
$card->setDeletedAt(time());
|
||||
$this->cardMapper->update($card);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE);
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
return $card;
|
||||
}
|
||||
|
||||
@@ -263,6 +270,7 @@ class CardService {
|
||||
$changes->setAfter($card);
|
||||
$card = $this->cardMapper->update($card);
|
||||
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE);
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
return $card;
|
||||
}
|
||||
|
||||
@@ -295,6 +303,7 @@ class CardService {
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
$card->setTitle($title);
|
||||
$this->changeHelper->cardChanged($card->getId(), false);
|
||||
return $this->cardMapper->update($card);
|
||||
}
|
||||
|
||||
@@ -349,7 +358,7 @@ class CardService {
|
||||
$this->cardMapper->update($card);
|
||||
$result[$card->getOrder()] = $card;
|
||||
}
|
||||
|
||||
$this->changeHelper->cardChanged($id, false);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -376,6 +385,7 @@ class CardService {
|
||||
$card->setArchived(true);
|
||||
$newCard = $this->cardMapper->update($card);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_ARCHIVE);
|
||||
$this->changeHelper->cardChanged($id, false);
|
||||
return $newCard;
|
||||
}
|
||||
|
||||
@@ -402,6 +412,7 @@ class CardService {
|
||||
$card->setArchived(false);
|
||||
$newCard = $this->cardMapper->update($card);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_UNARCHIVE);
|
||||
$this->changeHelper->cardChanged($id, false);
|
||||
return $newCard;
|
||||
}
|
||||
|
||||
@@ -434,6 +445,7 @@ class CardService {
|
||||
}
|
||||
$label = $this->labelMapper->find($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]);
|
||||
}
|
||||
|
||||
@@ -466,6 +478,7 @@ class CardService {
|
||||
}
|
||||
$label = $this->labelMapper->find($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]);
|
||||
}
|
||||
|
||||
@@ -473,9 +486,10 @@ class CardService {
|
||||
* @param $cardId
|
||||
* @param $userId
|
||||
* @return bool|null|\OCP\AppFramework\Db\Entity
|
||||
* @throws BadRequestException
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function assignUser($cardId, $userId) {
|
||||
|
||||
@@ -505,6 +519,7 @@ class CardService {
|
||||
$assignment->setCardId($cardId);
|
||||
$assignment->setParticipant($userId);
|
||||
$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]);
|
||||
return $assignment;
|
||||
}
|
||||
@@ -513,10 +528,11 @@ class CardService {
|
||||
* @param $cardId
|
||||
* @param $userId
|
||||
* @return \OCP\AppFramework\Db\Entity
|
||||
* @throws BadRequestException
|
||||
* @throws NotFoundException
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function unassignUser($cardId, $userId) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
@@ -535,6 +551,7 @@ class CardService {
|
||||
$assignment = $this->assignedUsersMapper->delete($assignment);
|
||||
$card = $this->cardMapper->find($cardId);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
|
||||
$this->changeHelper->cardChanged($cardId, false);
|
||||
return $assignment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,25 @@
|
||||
* @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\Service;
|
||||
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
@@ -38,11 +39,14 @@ class LabelService {
|
||||
private $permissionService;
|
||||
/** @var 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->permissionService = $permissionService;
|
||||
$this->boardService = $boardService;
|
||||
$this->changeHelper = $changeHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,6 +98,7 @@ class LabelService {
|
||||
$label->setTitle($title);
|
||||
$label->setColor($color);
|
||||
$label->setBoardId($boardId);
|
||||
$this->changeHelper->boardChanged($boardId);
|
||||
return $this->labelMapper->insert($label);
|
||||
}
|
||||
|
||||
@@ -116,7 +121,9 @@ class LabelService {
|
||||
if ($this->boardService->isArchived($this->labelMapper, $id)) {
|
||||
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->setTitle($title);
|
||||
$label->setColor($color);
|
||||
$this->changeHelper->boardChanged($label->getBoardId());
|
||||
return $this->labelMapper->update($label);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
@@ -49,6 +50,7 @@ class StackService {
|
||||
private $assignedUsersMapper;
|
||||
private $attachmentService;
|
||||
private $activityManager;
|
||||
private $changeHelper;
|
||||
|
||||
public function __construct(
|
||||
StackMapper $stackMapper,
|
||||
@@ -60,7 +62,8 @@ class StackService {
|
||||
CardService $cardService,
|
||||
AssignedUsersMapper $assignedUsersMapper,
|
||||
AttachmentService $attachmentService,
|
||||
ActivityManager $activityManager
|
||||
ActivityManager $activityManager,
|
||||
ChangeHelper $changeHelper
|
||||
) {
|
||||
$this->stackMapper = $stackMapper;
|
||||
$this->boardMapper = $boardMapper;
|
||||
@@ -72,12 +75,13 @@ class StackService {
|
||||
$this->assignedUsersMapper = $assignedUsersMapper;
|
||||
$this->attachmentService = $attachmentService;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
}
|
||||
|
||||
private function enrichStackWithCards($stack) {
|
||||
$cards = $this->cardMapper->findAll($stack->getId());
|
||||
private function enrichStackWithCards($stack, $since = -1) {
|
||||
$cards = $this->cardMapper->findAll($stack->getId(), null, null, $since);
|
||||
|
||||
if(is_null($cards)) {
|
||||
if(\count($cards) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,9 +92,9 @@ class StackService {
|
||||
$stack->setCards($cards);
|
||||
}
|
||||
|
||||
private function enrichStacksWithCards($stacks) {
|
||||
private function enrichStacksWithCards($stacks, $since = -1) {
|
||||
foreach ($stacks as $stack) {
|
||||
$this->enrichStackWithCards($stack);
|
||||
$this->enrichStackWithCards($stack, $since);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +127,14 @@ class StackService {
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function findAll($boardId) {
|
||||
public function findAll($boardId, $since = 0) {
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('boardId must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
|
||||
$stacks = $this->stackMapper->findAll($boardId);
|
||||
$this->enrichStacksWithCards($stacks);
|
||||
$this->enrichStacksWithCards($stacks, $since);
|
||||
return $stacks;
|
||||
}
|
||||
|
||||
@@ -203,6 +207,7 @@ class StackService {
|
||||
$stack->setOrder($order);
|
||||
$stack = $this->stackMapper->insert($stack);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE);
|
||||
$this->changeHelper->boardChanged($boardId);
|
||||
return $stack;
|
||||
}
|
||||
|
||||
@@ -227,7 +232,7 @@ class StackService {
|
||||
$stack = $this->stackMapper->update($stack);
|
||||
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE);
|
||||
|
||||
$this->changeHelper->boardChanged($stack->getBoardId());
|
||||
$this->enrichStackWithCards($stack);
|
||||
return $stack;
|
||||
}
|
||||
@@ -276,6 +281,7 @@ class StackService {
|
||||
$changes->setAfter($stack);
|
||||
$stack = $this->stackMapper->update($stack);
|
||||
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE);
|
||||
$this->changeHelper->boardChanged($stack->getBoardId());
|
||||
return $stack;
|
||||
}
|
||||
|
||||
@@ -318,7 +324,7 @@ class StackService {
|
||||
$this->stackMapper->update($stack);
|
||||
$result[$stack->getOrder()] = $stack;
|
||||
}
|
||||
|
||||
$this->changeHelper->boardChanged($stackToSort->getBoardId());
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class BoardTest extends TestCase {
|
||||
'labels' => array(),
|
||||
'permissions' => [],
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
'acl' => array(),
|
||||
'archived' => false,
|
||||
'users' => ['user1', 'user2'],
|
||||
@@ -43,6 +44,7 @@ class BoardTest extends TestCase {
|
||||
'labels' => array("foo", "bar"),
|
||||
'permissions' => [],
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
'acl' => array(),
|
||||
'archived' => false,
|
||||
'users' => [],
|
||||
@@ -67,10 +69,11 @@ class BoardTest extends TestCase {
|
||||
'labels' => array(),
|
||||
'permissions' => [],
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
'acl' => array(),
|
||||
'archived' => false,
|
||||
'shared' => 1,
|
||||
'users' => [],
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ class StackTest extends \Test\TestCase {
|
||||
'title' => "My Stack",
|
||||
'order' => 1,
|
||||
'boardId' => 1,
|
||||
'deletedAt' => 0
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeWithCards() {
|
||||
@@ -52,7 +53,8 @@ class StackTest extends \Test\TestCase {
|
||||
'order' => 1,
|
||||
'boardId' => 1,
|
||||
'cards' => array("foo", "bar"),
|
||||
'deletedAt' => 0
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Attachment;
|
||||
use OCA\Deck\Db\AttachmentMapper;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\InvalidAttachmentType;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
@@ -73,6 +74,8 @@ class AttachmentServiceTest extends TestCase {
|
||||
private $cache;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
|
||||
/**
|
||||
* @throws \OCP\AppFramework\QueryException
|
||||
@@ -99,8 +102,9 @@ class AttachmentServiceTest extends TestCase {
|
||||
->willReturn($this->appContainer);
|
||||
|
||||
$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() {
|
||||
@@ -112,7 +116,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
->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);
|
||||
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
|
||||
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
|
||||
@@ -130,7 +134,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
->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->getService('deck_file_invalid');
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ use OCA\Deck\Db\AssignedUsers;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCP\IUser;
|
||||
@@ -62,7 +63,8 @@ class BoardServiceTest extends TestCase {
|
||||
private $groupManager;
|
||||
/** @var ActivityManager */
|
||||
private $activityManager;
|
||||
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp() {
|
||||
@@ -77,6 +79,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
|
||||
$this->service = new BoardService(
|
||||
$this->boardMapper,
|
||||
@@ -89,6 +92,7 @@ class BoardServiceTest extends TestCase {
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->activityManager,
|
||||
$this->changeHelper,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ use OCA\Deck\Db\AssignedUsers;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
@@ -69,6 +70,8 @@ class CardServiceTest extends TestCase {
|
||||
private $commentsManager;
|
||||
/** @var ICommentsManager|MockObject */
|
||||
private $userManager;
|
||||
/** @var ChangeHelper|MockObject */
|
||||
private $changeHelper;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -84,6 +87,7 @@ class CardServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->commentsManager = $this->createMock(ICommentsManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->cardService = new CardService(
|
||||
$this->cardMapper,
|
||||
$this->stackMapper,
|
||||
@@ -97,6 +101,7 @@ class CardServiceTest extends TestCase {
|
||||
$this->activityManager,
|
||||
$this->commentsManager,
|
||||
$this->userManager,
|
||||
$this->changeHelper,
|
||||
'user1'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use Test\TestCase;
|
||||
@@ -38,6 +39,8 @@ class LabelServiceTest extends TestCase {
|
||||
private $labelService;
|
||||
/** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $boardService;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -46,10 +49,12 @@ class LabelServiceTest extends TestCase {
|
||||
$this->permissionService = $this->getMockBuilder(PermissionService::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->boardService = $this->createMock(BoardService::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
$this->labelService = new LabelService(
|
||||
$this->labelMapper,
|
||||
$this->permissionService,
|
||||
$this->boardService
|
||||
$this->boardService,
|
||||
$this->changeHelper
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,13 +100,15 @@ class LabelServiceTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
$label = new Label();
|
||||
$label->setId(1);
|
||||
$this->labelMapper->expects($this->once())
|
||||
->method('find')
|
||||
->willReturn(new Label());
|
||||
->willReturn($label);
|
||||
$this->labelMapper->expects($this->once())
|
||||
->method('delete')
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->labelService->delete(123));
|
||||
->willReturn($label);
|
||||
$this->assertEquals($label, $this->labelService->delete(1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
@@ -66,6 +67,8 @@ class StackServiceTest extends TestCase {
|
||||
private $cardService;
|
||||
/** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $activityManager;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -79,6 +82,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->attachmentService = $this->createMock(AttachmentService::class);
|
||||
$this->labelMapper = $this->createMock(LabelMapper::class);
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->changeHelper = $this->createMock(ChangeHelper::class);
|
||||
|
||||
$this->stackService = new StackService(
|
||||
$this->stackMapper,
|
||||
@@ -90,7 +94,8 @@ class StackServiceTest extends TestCase {
|
||||
$this->cardService,
|
||||
$this->assignedUsersMapper,
|
||||
$this->attachmentService,
|
||||
$this->activityManager
|
||||
$this->activityManager,
|
||||
$this->changeHelper
|
||||
);
|
||||
}
|
||||
|
||||
@@ -185,6 +190,7 @@ class StackServiceTest extends TestCase {
|
||||
$stackToBeDeleted->setId(1);
|
||||
$this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted);
|
||||
$this->stackMapper->expects($this->once())->method('update')->willReturn($stackToBeDeleted);
|
||||
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([]);
|
||||
$this->stackService->delete(123);
|
||||
$this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past");
|
||||
$this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set");
|
||||
|
||||
Reference in New Issue
Block a user