Check for archived cards before action in backend
This commit is contained in:
@@ -58,8 +58,6 @@ return [
|
|||||||
['name' => 'public#board', 'url' => '/public/board/ajax/:hash', 'verb' => 'GET'],
|
['name' => 'public#board', 'url' => '/public/board/ajax/:hash', 'verb' => 'GET'],
|
||||||
|
|
||||||
// TODO: API for external access
|
// TODO: API for external access
|
||||||
//['name' => 'api#index', 'url' => '/api/', 'verb' => 'GET'],
|
|
||||||
// ['name' => 'note_api#preflighted_cors', 'url' => '/api/v1/{path}/', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']]
|
|
||||||
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\Deck\Controller;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
|
||||||
use OCP\AppFramework\ApiController as BaseApiController;
|
|
||||||
|
|
||||||
class ApiController extends BaseApiController {
|
|
||||||
public function __construct($appName,
|
|
||||||
IRequest $request){
|
|
||||||
parent::__construct($appName, $request);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @PublicPage
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @CORS
|
|
||||||
*/
|
|
||||||
public function index() {
|
|
||||||
return [
|
|
||||||
'apiLevels' => ['v1']
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// TODO: Implement LATER
|
|
||||||
namespace OCA\Deck\Controller;
|
|
||||||
|
|
||||||
use OCA\Deck\Service\BoardService;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
|
||||||
|
|
||||||
use OCP\AppFramework\ApiController as BaseApiController;
|
|
||||||
|
|
||||||
class BoardApiController extends BaseApiController {
|
|
||||||
private $userId;
|
|
||||||
public function __construct($appName,
|
|
||||||
IRequest $request,
|
|
||||||
BoardService $cardService,
|
|
||||||
$userId){
|
|
||||||
parent::__construct($appName, $request);
|
|
||||||
$this->userId = $userId;
|
|
||||||
$this->boardService = $cardService;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @CORS
|
|
||||||
*/
|
|
||||||
public function index() {
|
|
||||||
return new DataResponse($this->boardService->findAll($this->userId));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @CORS
|
|
||||||
*/
|
|
||||||
public function create($title, $color) {
|
|
||||||
return new DataResponse($this->boardService->create($title, $this->userId, $color));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @CORS
|
|
||||||
*/
|
|
||||||
public function update($id, $title, $color) {
|
|
||||||
return new DataResponse($this->boardService->create($title, $this->userId, $color));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
* @CORS
|
|
||||||
*/
|
|
||||||
public function delete($id) {
|
|
||||||
return new DataResponse($this->boardService->create($title, $this->userId, $color));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,5 +17,15 @@ class AclMapper extends DeckMapper {
|
|||||||
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 as owner FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? UNION SELECT 0, id, \'user\', owner, 1, 1, 1, 1 FROM `*PREFIX*deck_boards` WHERE `id` = ? ';
|
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 as owner FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? UNION SELECT 0, id, \'user\', owner, 1, 1, 1, 1 FROM `*PREFIX*deck_boards` WHERE `id` = ? ';
|
||||||
return $this->findEntities($sql, [$boardId, $boardId], $limit, $offset);
|
return $this->findEntities($sql, [$boardId, $boardId], $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findAllForCard($cardId, $userId) {
|
||||||
|
$findBoardId = "(SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))";
|
||||||
|
$sql = "SELECT 0, id, 'user', owner, 1, 1, 1, 1 as owner FROM `oc_deck_boards` WHERE `id` IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))
|
||||||
|
UNION
|
||||||
|
SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 FROM oc_deck_board_acl
|
||||||
|
WHERE participant = 'admin' AND board_id IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15));";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,4 +86,5 @@ class CardMapper extends Mapper {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
13
service/cardarchivedexception.php
Normal file
13
service/cardarchivedexception.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
|
class CardArchivedException extends \Exception {
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param string $msg the error message
|
||||||
|
*/
|
||||||
|
public function __construct($msg){
|
||||||
|
parent::__construct($msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\Service;
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
|
use OC\OCS\Exception;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
@@ -41,6 +42,9 @@ class CardService {
|
|||||||
|
|
||||||
public function update($id, $title, $stackId, $type, $order, $description, $owner) {
|
public function update($id, $title, $stackId, $type, $order, $description, $owner) {
|
||||||
$card = $this->cardMapper->find($id);
|
$card = $this->cardMapper->find($id);
|
||||||
|
if($card->getArchived()) {
|
||||||
|
throw new CardArchivedException();
|
||||||
|
}
|
||||||
$card->setTitle($title);
|
$card->setTitle($title);
|
||||||
$card->setStackId($stackId);
|
$card->setStackId($stackId);
|
||||||
$card->setType($type);
|
$card->setType($type);
|
||||||
@@ -52,6 +56,9 @@ class CardService {
|
|||||||
|
|
||||||
public function rename($id, $title) {
|
public function rename($id, $title) {
|
||||||
$card = $this->cardMapper->find($id);
|
$card = $this->cardMapper->find($id);
|
||||||
|
if($card->getArchived()) {
|
||||||
|
throw new CardArchivedException();
|
||||||
|
}
|
||||||
$card->setTitle($title);
|
$card->setTitle($title);
|
||||||
return $this->cardMapper->update($card);
|
return $this->cardMapper->update($card);
|
||||||
}
|
}
|
||||||
@@ -59,6 +66,9 @@ class CardService {
|
|||||||
$cards = $this->cardMapper->findAll($stackId);
|
$cards = $this->cardMapper->findAll($stackId);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($cards as $card) {
|
foreach ($cards as $card) {
|
||||||
|
if($card->getArchived()) {
|
||||||
|
throw new CardArchivedException();
|
||||||
|
}
|
||||||
if($card->id === $id) {
|
if($card->id === $id) {
|
||||||
$card->setOrder($order);
|
$card->setOrder($order);
|
||||||
}
|
}
|
||||||
@@ -90,10 +100,18 @@ class CardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function assignLabel($userId, $cardId, $labelId) {
|
public function assignLabel($userId, $cardId, $labelId) {
|
||||||
|
$card = $this->cardMapper->find($cardId);
|
||||||
|
if($card->getArchived()) {
|
||||||
|
throw new CardArchivedException();
|
||||||
|
}
|
||||||
$this->cardMapper->assignLabel($cardId, $labelId);
|
$this->cardMapper->assignLabel($cardId, $labelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeLabel($userId, $cardId, $labelId) {
|
public function removeLabel($userId, $cardId, $labelId) {
|
||||||
|
$card = $this->cardMapper->find($cardId);
|
||||||
|
if($card->getArchived()) {
|
||||||
|
throw new CardArchivedException();
|
||||||
|
}
|
||||||
$this->cardMapper->removeLabel($cardId, $labelId);
|
$this->cardMapper->removeLabel($cardId, $labelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
service/servicepermissionexception.php
Normal file
13
service/servicepermissionexception.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Deck\Service;
|
||||||
|
|
||||||
|
class ServicePermissionException extends \Exception {
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param string $msg the error message
|
||||||
|
*/
|
||||||
|
public function __construct($msg){
|
||||||
|
parent::__construct($msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user