@@ -23,9 +23,12 @@
|
||||
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\ArchivedItemException;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\IPermissionMapper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IL10N;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
@@ -80,6 +83,23 @@ class BoardService {
|
||||
return $board;
|
||||
}
|
||||
|
||||
public function isArchived($mapper, $id) {
|
||||
try {
|
||||
if ($mapper instanceof IPermissionMapper) {
|
||||
$boardId = $mapper->findBoardId($id);
|
||||
} else {
|
||||
$boardId = $id;
|
||||
}
|
||||
if ($boardId === null) {
|
||||
return false;
|
||||
}
|
||||
} catch (DoesNotExistException $exception) {
|
||||
return false;
|
||||
}
|
||||
$board = $this->find($boardId);
|
||||
return $board->getArchived();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function create($title, $userId, $color) {
|
||||
@@ -115,11 +135,12 @@ class BoardService {
|
||||
return $this->boardMapper->delete($this->find($id));
|
||||
}
|
||||
|
||||
public function update($id, $title, $color) {
|
||||
public function update($id, $title, $color, $archived) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
$board->setTitle($title);
|
||||
$board->setColor($color);
|
||||
$board->setArchived($archived);
|
||||
$this->boardMapper->mapOwner($board);
|
||||
return $this->boardMapper->update($board);
|
||||
}
|
||||
|
||||
@@ -26,18 +26,22 @@ namespace OCA\Deck\Service;
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\CardArchivedException;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
|
||||
|
||||
class CardService {
|
||||
|
||||
private $cardMapper;
|
||||
private $stackMapper;
|
||||
private $permissionService;
|
||||
private $boardService;
|
||||
|
||||
public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService) {
|
||||
public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService) {
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->stackMapper = $stackMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->boardService = $boardService;
|
||||
}
|
||||
|
||||
public function find($cardId) {
|
||||
@@ -51,6 +55,9 @@ class CardService {
|
||||
*/
|
||||
public function create($title, $stackId, $type, $order, $owner) {
|
||||
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->stackMapper, $stackId)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = new Card();
|
||||
$card->setTitle($title);
|
||||
$card->setStackId($stackId);
|
||||
@@ -63,14 +70,20 @@ class CardService {
|
||||
|
||||
public function delete($id) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
return $this->cardMapper->delete($this->cardMapper->find($id));
|
||||
}
|
||||
|
||||
public function update($id, $title, $stackId, $type, $order, $description, $owner) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($id);
|
||||
if ($card->getArchived()) {
|
||||
throw new CardArchivedException();
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
$card->setTitle($title);
|
||||
$card->setStackId($stackId);
|
||||
@@ -83,9 +96,12 @@ class CardService {
|
||||
|
||||
public function rename($id, $title) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($id);
|
||||
if ($card->getArchived()) {
|
||||
throw new CardArchivedException();
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
$card->setTitle($title);
|
||||
return $this->cardMapper->update($card);
|
||||
@@ -93,12 +109,15 @@ class CardService {
|
||||
|
||||
public function reorder($id, $stackId, $order) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$cards = $this->cardMapper->findAll($stackId);
|
||||
$result = [];
|
||||
$i = 0;
|
||||
foreach ($cards as $card) {
|
||||
if ($card->getArchived()) {
|
||||
throw new CardArchivedException();
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
if ($card->id === $id) {
|
||||
$card->setOrder($order);
|
||||
@@ -121,6 +140,9 @@ class CardService {
|
||||
|
||||
public function archive($id) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($id);
|
||||
$card->setArchived(true);
|
||||
return $this->cardMapper->update($card);
|
||||
@@ -128,6 +150,9 @@ class CardService {
|
||||
|
||||
public function unarchive($id) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($id);
|
||||
$card->setArchived(false);
|
||||
return $this->cardMapper->update($card);
|
||||
@@ -135,18 +160,24 @@ class CardService {
|
||||
|
||||
public function assignLabel($cardId, $labelId) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $cardId)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($cardId);
|
||||
if ($card->getArchived()) {
|
||||
throw new CardArchivedException();
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
$this->cardMapper->assignLabel($cardId, $labelId);
|
||||
}
|
||||
|
||||
public function removeLabel($cardId, $labelId) {
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
if($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$card = $this->cardMapper->find($cardId);
|
||||
if ($card->getArchived()) {
|
||||
throw new CardArchivedException();
|
||||
throw new StatusException('Operation not allowed. This card is archived.');
|
||||
}
|
||||
$this->cardMapper->removeLabel($cardId, $labelId);
|
||||
}
|
||||
|
||||
@@ -26,15 +26,22 @@ namespace OCA\Deck\Service;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
|
||||
|
||||
class LabelService {
|
||||
|
||||
/** @var LabelMapper */
|
||||
private $labelMapper;
|
||||
/** @var PermissionService */
|
||||
private $permissionService;
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
|
||||
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService) {
|
||||
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService) {
|
||||
$this->labelMapper = $labelMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->boardService = $boardService;
|
||||
}
|
||||
|
||||
public function find($labelId) {
|
||||
@@ -44,6 +51,9 @@ class LabelService {
|
||||
|
||||
public function create($title, $color, $boardId) {
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
|
||||
if($this->boardService->isArchived(null, $boardId)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$label = new Label();
|
||||
$label->setTitle($title);
|
||||
$label->setColor($color);
|
||||
@@ -53,11 +63,17 @@ class LabelService {
|
||||
|
||||
public function delete($id) {
|
||||
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
if($this->boardService->isArchived($this->labelMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
return $this->labelMapper->delete($this->find($id));
|
||||
}
|
||||
|
||||
public function update($id, $title, $color) {
|
||||
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
if($this->boardService->isArchived($this->labelMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$label = $this->find($id);
|
||||
$label->setTitle($title);
|
||||
$label->setColor($color);
|
||||
|
||||
@@ -31,6 +31,7 @@ use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Db\Stack;
|
||||
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
|
||||
|
||||
class StackService {
|
||||
@@ -39,12 +40,14 @@ class StackService {
|
||||
private $cardMapper;
|
||||
private $labelMapper;
|
||||
private $permissionService;
|
||||
private $boardService;
|
||||
|
||||
public function __construct(StackMapper $stackMapper, CardMapper $cardMapper, LabelMapper $labelMapper, PermissionService $permissionService) {
|
||||
public function __construct(StackMapper $stackMapper, CardMapper $cardMapper, LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService) {
|
||||
$this->stackMapper = $stackMapper;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->labelMapper = $labelMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->boardService = $boardService;
|
||||
}
|
||||
|
||||
public function findAll($boardId) {
|
||||
@@ -81,6 +84,9 @@ class StackService {
|
||||
|
||||
public function create($title, $boardId, $order) {
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
|
||||
if($this->boardService->isArchived(null, $boardId)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$stack = new Stack();
|
||||
$stack->setTitle($title);
|
||||
$stack->setBoardId($boardId);
|
||||
@@ -96,6 +102,9 @@ class StackService {
|
||||
|
||||
public function update($id, $title, $boardId, $order) {
|
||||
$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
if($this->boardService->isArchived($this->stackMapper, $id)) {
|
||||
throw new StatusException('Operation not allowed. This board is archived.');
|
||||
}
|
||||
$stack = $this->stackMapper->find($id);
|
||||
$stack->setTitle($title);
|
||||
$stack->setBoardId($boardId);
|
||||
|
||||
Reference in New Issue
Block a user