Compare commits

...

10 Commits

Author SHA1 Message Date
Jakob Röhrl
65650691b3 test
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-10-16 12:52:47 +02:00
Jakob Röhrl
caa201dc6c faq
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-10-16 11:42:54 +02:00
Jakob
083cd207af Merge branch 'master' into enh/cloneStack 2020-09-16 10:42:07 +02:00
Jakob Röhrl
24f83b875b test adjustments
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-16 10:09:58 +02:00
Jakob Röhrl
14d90e2ff2 format json
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-07 14:11:35 +02:00
Jakob Röhrl
2a4b0a3ed3 security and api
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-02 08:40:19 +02:00
Jakob Röhrl
71780b5578 some small changes
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-02 08:09:15 +02:00
Julius Härtl
c39fd43b6c Fix label assignment insertion and enrich result of clone
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2020-09-01 08:58:30 +02:00
Jakob Röhrl
e763ce1fb7 assign label
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-01 08:58:30 +02:00
Jakob Röhrl
003df010dd clone stacks
Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
2020-09-01 08:58:29 +02:00
10 changed files with 363 additions and 6 deletions

View File

@@ -47,6 +47,7 @@ return [
['name' => 'stack#delete', 'url' => '/stacks/{stackId}', 'verb' => 'DELETE'],
['name' => 'stack#deleted', 'url' => '/{boardId}/stacks/deleted', 'verb' => 'GET'],
['name' => 'stack#archived', 'url' => '/stacks/{boardId}/archived', 'verb' => 'GET'],
['name' => 'stack#clone', 'url' => '/stacks/{stackId}/clone', 'verb' => 'POST'],
// cards
['name' => 'card#read', 'url' => '/cards/{cardId}', 'verb' => 'GET'],
@@ -97,6 +98,7 @@ return [
['name' => 'stack_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks', 'verb' => 'POST'],
['name' => 'stack_api#update', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'PUT'],
['name' => 'stack_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}', 'verb' => 'DELETE'],
['name' => 'stack_api#clone', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/clone', 'verb' => 'POST'],
['name' => 'card_api#get', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}', 'verb' => 'GET'],
['name' => 'card_api#create', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards', 'verb' => 'POST'],

View File

@@ -492,6 +492,93 @@ The board list endpoint supports setting an `If-Modified-Since` header to limit
##### 200 Success
### POST /boards/{boardId}/stacks/{stackId}/clone - Clone a stack
#### Request parameters
| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------------------- |
| boardId | Integer | The id of the board where the stack should be cloned to |
| stackId | Integer | The id of the stack |
#### Response
It will return an object of the new stack containing the new cards as well.
```json
{
"title":"l1 (copy)",
"boardId":6,
"deletedAt":0,
"lastModified":0,
"cards":[
{
"title":"ME",
"description":"123",
"stackId":73,
"type":"plain",
"lastModified":1599028559,
"lastEditor":null,
"createdAt":1599028559,
"labels":[
],
"assignedUsers":[
],
"attachments":null,
"attachmentCount":0,
"owner":{
"primaryKey":"root",
"uid":"root",
"displayname":"root",
"type":0
},
"order":0,
"archived":false,
"duedate":null,
"deletedAt":0,
"commentsUnread":0,
"id":109,
"overdue":0
},
{
"title":"ka",
"description":"",
"stackId":73,
"type":"plain",
"lastModified":1599028559,
"lastEditor":null,
"createdAt":1599028559,
"labels":[
],
"assignedUsers":[
],
"attachments":null,
"attachmentCount":0,
"owner":{
"primaryKey":"root",
"uid":"root",
"displayname":"root",
"type":0
},
"order":1,
"archived":false,
"duedate":"2020-08-26T22:00:00+00:00",
"deletedAt":0,
"commentsUnread":0,
"id":110,
"overdue":3
}
],
"order":999,
"id":73
}
```
##### 200 Success
## Cards
### GET /boards/{boardId}/stacks/{stackId}/cards/{cardId} - Get card details

View File

@@ -107,4 +107,13 @@ class StackController extends Controller {
public function deleted($boardId) {
return $this->stackService->fetchDeleted($boardId);
}
/**
* @NoAdminRequired
* @param $boardId
* @return \OCP\Deck\DB\Board
*/
public function clone($stackId, $boardId) {
return $this->stackService->clone($stackId, $boardId, $this->userId);
}
}

38
lib/Db/AssignedLabels.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
/**
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @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 JsonSerializable;
class AssignedLabels extends RelationalEntity implements JsonSerializable {
public $id;
protected $labelId;
protected $cardId;
public function __construct() {
$this->addType('id', 'integer');
$this->addType('cardId', 'integer');
$this->addType('labelId', 'integer');
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @copyright Copyright (c) 2020 Jakob Röhrl <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
*
* @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\Entity;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
class AssignedLabelsMapper extends DeckMapper {
private $cardMapper;
private $userManager;
/**
* @var IGroupManager
*/
private $groupManager;
public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager, IGroupManager $groupManager) {
parent::__construct($db, 'deck_assigned_labels', AssignedLabels::class);
$this->cardMapper = $cardMapper;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}
/**
*
* @param $cardId
* @return array|Entity
*/
public function find($cardId) {
$sql = 'SELECT * from `*PREFIX*deck_assigned_labels` where `card_id` = ?';
$labels = $this->findEntities($sql, [$cardId]);
return $labels;
}
}

View File

@@ -29,7 +29,11 @@ use OCA\Deck\Activity\ChangeSet;
use OCA\Deck\BadRequestException;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedLabelsMapper;
use OCA\Deck\Db\AssignedLabels;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper;
@@ -38,6 +42,8 @@ use OCA\Deck\Db\StackMapper;
use OCA\Deck\StatusException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\IL10N;
use OCA\Deck\Event\FTSEvent;
class StackService {
private $stackMapper;
@@ -48,11 +54,15 @@ class StackService {
private $boardService;
private $cardService;
private $assignedUsersMapper;
private $assignedLabelsMapper;
private $attachmentService;
private $activityManager;
/** @var EventDispatcherInterface */
private $eventDispatcher;
private $changeHelper;
private $l10n;
private $userId;
public function __construct(
StackMapper $stackMapper,
@@ -63,10 +73,13 @@ class StackService {
BoardService $boardService,
CardService $cardService,
AssignedUsersMapper $assignedUsersMapper,
AssignedLabelsMapper $assignedLabelsMapper,
AttachmentService $attachmentService,
ActivityManager $activityManager,
EventDispatcherInterface $eventDispatcher,
ChangeHelper $changeHelper
ChangeHelper $changeHelper,
IL10N $l10n,
$userId
) {
$this->stackMapper = $stackMapper;
$this->boardMapper = $boardMapper;
@@ -76,10 +89,13 @@ class StackService {
$this->boardService = $boardService;
$this->cardService = $cardService;
$this->assignedUsersMapper = $assignedUsersMapper;
$this->assignedLabelsMapper = $assignedLabelsMapper;
$this->attachmentService = $attachmentService;
$this->activityManager = $activityManager;
$this->eventDispatcher = $eventDispatcher;
$this->changeHelper = $changeHelper;
$this->l10n = $l10n;
$this->userId = $userId;
}
private function enrichStackWithCards($stack, $since = -1) {
@@ -365,4 +381,106 @@ class StackService {
return $result;
}
/**
* @param $id
* @param $boardId
* @return Stack
* @throws StatusException
* @throws BadRequestException
*/
public function clone($id, $boardId) {
if (is_numeric($id) === false) {
throw new BadRequestException('stack id must be a number');
}
if (is_numeric($boardId) === false) {
throw new BadRequestException('board id must be a number');
}
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
$this->permissionService->checkPermission(null, $id, Acl::PERMISSION_READ);
if ($this->boardService->isArchived(null, $boardId)) {
throw new StatusException('Operation not allowed. This board is archived.');
}
$stack = $this->stackMapper->find($id);
$board = $this->boardMapper->find($boardId);
if ($stack->getBoardId() !== $board->getId()) {
throw new StatusException('Operation not allowed. Stack is not part of this board');
}
$newStack = new Stack();
// TODO: Currently cloing is only possible on the same board.
// If we change this and its possible to clone to other boards the 'copy' should be removed from title
$newStack->setTitle($stack->getTitle() . ' (' . $this->l10n->t('copy') . ')');
$newStack->setBoardId($boardId);
$newStack->setOrder(999);
$newStack = $this->stackMapper->insert($newStack);
$this->activityManager->triggerEvent(
ActivityManager::DECK_OBJECT_BOARD, $newStack, ActivityManager::SUBJECT_STACK_CREATE
);
$this->changeHelper->boardChanged($boardId);
$this->eventDispatcher->dispatch(
'\OCA\Deck\Stack::onCreate',
new GenericEvent(null, ['id' => $newStack->getId(), 'stack' => $newStack])
);
$cards = $this->cardMapper->findAll($id);
foreach ($cards as $card) {
$newCard = new Card();
$newCard->setTitle($card->getTitle());
$newCard->setStackId($newStack->getId());
$newCard->setType($card->getType());
$newCard->setOrder($card->getOrder());
$newCard->setOwner($this->userId);
$newCard->setDescription($card->getDescription());
$newCard->setDuedate($card->getDuedate());
$newCard = $this->cardMapper->insert($newCard);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_CREATE);
$this->changeHelper->cardChanged($newCard->getId(), false);
$this->eventDispatcher->dispatch('\OCA\Deck\Card::onCreate',
new FTSEvent(
null, ['id' => $newCard->getId(), 'card' => $newCard, 'userId' => $this->userId, 'stackId' => $stackId]
)
);
if ($boardId === $stack->getBoardId()) {
$assignedLabels = $this->assignedLabelsMapper->find($card->getId());
$newLabelArray = [];
foreach ($assignedLabels as $assignedLabel) {
$assignment = new AssignedLabels();
$assignment->setCardId($newCard->getId());
$assignment->setLabelId($assignedLabel->getLabelId());
$assignment = $this->assignedLabelsMapper->insert($assignment);
$newLabelArray[] = $assignment;
}
$newCard->setLabels($newLabelArray);
$assignedUsers = $this->assignedUsersMapper->find($card->getId());
$newUserArray = [];
foreach ($assignedUsers as $assignedUser) {
$assignment = new AssignedUsers();
$assignment->setCardId($newCard->getId());
$assignment->setParticipant($assignedUser->getParticipant());
$assignment->setType($assignedUser->getType());
$assignment = $this->assignedUsersMapper->insert($assignment);
$newUserArray[] = $assignment;
}
$newCard->setAssignedUsers($newUserArray);
}
}
$this->enrichStackWithCards($newStack);
return $newStack;
}
}

View File

@@ -42,11 +42,14 @@
value="">
</form>
</transition>
<Actions v-if="canManage && !isArchived" :force-menu="true">
<ActionButton icon="icon-archive" @click="modalArchivAllCardsShow=true">
<Actions v-if="!isArchived" :force-menu="true">
<ActionButton v-if="canEdit" icon="icon-archive" @click="modalArchivAllCardsShow=true">
{{ t('deck', 'Archive all cards') }}
</ActionButton>
<ActionButton icon="icon-delete" @click="deleteStack(stack)">
<ActionButton v-if="canManage" icon="icon-clone" @click="cloneStack(stack)">
{{ t('deck', 'Clone list') }}
</ActionButton>
<ActionButton v-if="canManage" icon="icon-delete" @click="deleteStack(stack)">
{{ t('deck', 'Delete list') }}
</ActionButton>
</Actions>
@@ -212,7 +215,6 @@ export default {
this.$store.dispatch('deleteStack', stack)
},
archiveAllCardsFromStack(stack) {
this.stackTransfer.total = this.cardsByStack.length
this.cardsByStack.forEach((card, index) => {
this.stackTransfer.current = index
@@ -220,6 +222,13 @@ export default {
})
this.modalArchivAllCardsShow = false
},
cloneStack(stack) {
try {
this.$store.dispatch('cloneStack', stack)
} catch (e) {
showError('Could not clone stack: ' + e.response.data.message)
}
},
startEditing(stack) {
this.copiedStack = Object.assign({}, stack)
this.editing = true

View File

@@ -140,4 +140,19 @@ export class StackApi {
})
}
cloneStack(stack) {
return axios.post(this.url(`/stacks/${stack.id}/clone`), stack)
.then(
(response) => {
return Promise.resolve(response.data)
},
(err) => {
return Promise.reject(err)
}
)
.catch((err) => {
return Promise.reject(err)
})
}
}

View File

@@ -97,6 +97,15 @@ export default {
commit('addStack', createdStack)
})
},
cloneStack({ commit }, stack) {
apiClient.cloneStack(stack)
.then((stack) => {
for (const j in stack.cards) {
commit('addCard', stack.cards[j])
}
commit('addStack', stack)
})
},
deleteStack({ commit }, stack) {
apiClient.deleteStack(stack.id)
.then((stack) => {

View File

@@ -33,8 +33,10 @@ use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\AssignedLabelsMapper;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use \Test\TestCase;
use OCP\IL10N;
/**
* Class StackServiceTest
@@ -70,6 +72,9 @@ class StackServiceTest extends TestCase {
private $changeHelper;
/** @var EventDispatcherInterface */
private $eventDispatcher;
private $l10n;
private $userId;
private $assignedLabelsMapper;
public function setUp(): void {
parent::setUp();
@@ -85,6 +90,10 @@ class StackServiceTest extends TestCase {
$this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->l10n = $this->createMock(IL10N::class);
$this->userId = "admin";
$this->assignedLabelsMapper = $this->createMock(AssignedLabelsMapper::class);
$this->stackService = new StackService(
$this->stackMapper,
@@ -98,7 +107,10 @@ class StackServiceTest extends TestCase {
$this->attachmentService,
$this->activityManager,
$this->eventDispatcher,
$this->changeHelper
$this->changeHelper,
$this->l10n,
$this->userId,
$this->assassignedLabelsMapper
);
}