feat: add validators to check values in services
Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
committed by
Julius Härtl
parent
357f30464d
commit
ff77c45a50
@@ -35,6 +35,7 @@ use OCA\Deck\Event\CardUpdatedEvent;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\NotFoundException;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCA\Deck\Validators\AssignmentServiceValidator;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
@@ -76,6 +77,11 @@ class AssignmentService {
|
||||
private $eventDispatcher;
|
||||
/** @var string|null */
|
||||
private $currentUser;
|
||||
/**
|
||||
* @var AssignmentServiceValidator
|
||||
*/
|
||||
private $assignmentServiceValidator;
|
||||
|
||||
|
||||
public function __construct(
|
||||
PermissionService $permissionService,
|
||||
@@ -86,8 +92,10 @@ class AssignmentService {
|
||||
ActivityManager $activityManager,
|
||||
ChangeHelper $changeHelper,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
AssignmentServiceValidator $assignmentServiceValidator,
|
||||
$userId
|
||||
) {
|
||||
$this->assignmentServiceValidator = $assignmentServiceValidator;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->assignedUsersMapper = $assignedUsersMapper;
|
||||
@@ -96,6 +104,8 @@ class AssignmentService {
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
|
||||
$this->assignmentServiceValidator->check(compact('userId'));
|
||||
$this->currentUser = $userId;
|
||||
}
|
||||
|
||||
@@ -109,13 +119,7 @@ class AssignmentService {
|
||||
* @throws DoesNotExistException
|
||||
*/
|
||||
public function assignUser($cardId, $userId, int $type = Assignment::TYPE_USER) {
|
||||
if (is_numeric($cardId) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
|
||||
if ($userId === false || $userId === null) {
|
||||
throw new BadRequestException('user id must be provided');
|
||||
}
|
||||
$this->assignmentServiceValidator->check(compact('cardId', 'userId'));
|
||||
|
||||
if ($type !== Assignment::TYPE_USER && $type !== Assignment::TYPE_GROUP) {
|
||||
throw new BadRequestException('Invalid type provided for assignemnt');
|
||||
@@ -168,16 +172,9 @@ class AssignmentService {
|
||||
* @throws MultipleObjectsReturnedException
|
||||
*/
|
||||
public function unassignUser($cardId, $userId, $type = 0) {
|
||||
$this->assignmentServiceValidator->check(compact('cardId', 'userId'));
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
|
||||
if (is_numeric($cardId) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
|
||||
if ($userId === false || $userId === null) {
|
||||
throw new BadRequestException('user must be provided');
|
||||
}
|
||||
|
||||
$assignments = $this->assignedUsersMapper->findAll($cardId);
|
||||
foreach ($assignments as $assignment) {
|
||||
if ($assignment->getParticipant() === $userId && $assignment->getType() === $type) {
|
||||
|
||||
@@ -36,6 +36,7 @@ use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\NotFoundException;
|
||||
use OCA\Deck\Cache\AttachmentCacheHelper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Validators\AttachmentServiceValidator;
|
||||
use OCP\AppFramework\Db\IMapperException;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IL10N;
|
||||
@@ -58,8 +59,10 @@ class AttachmentService {
|
||||
private $activityManager;
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
/** @var AttachmentServiceValidator */
|
||||
private $attachmentServiceValidator;
|
||||
|
||||
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, AttachmentCacheHelper $attachmentCacheHelper, $userId, IL10N $l10n, ActivityManager $activityManager) {
|
||||
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, AttachmentCacheHelper $attachmentCacheHelper, $userId, IL10N $l10n, ActivityManager $activityManager, AttachmentServiceValidator $attachmentServiceValidator) {
|
||||
$this->attachmentMapper = $attachmentMapper;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
@@ -69,6 +72,7 @@ class AttachmentService {
|
||||
$this->l10n = $l10n;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->attachmentServiceValidator = $attachmentServiceValidator;
|
||||
|
||||
// Register shipped attachment services
|
||||
// TODO: move this to a plugin based approach once we have different types of attachments
|
||||
@@ -174,17 +178,7 @@ class AttachmentService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function create($cardId, $type, $data) {
|
||||
if (is_numeric($cardId) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
|
||||
if ($type === false || $type === null) {
|
||||
throw new BadRequestException('type must be provided');
|
||||
}
|
||||
|
||||
if ($data === false || $data === null) {
|
||||
//throw new BadRequestException('data must be provided');
|
||||
}
|
||||
$this->attachmentServiceValidator->check(compact('cardId', 'type', 'data'));
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
|
||||
@@ -269,6 +263,8 @@ class AttachmentService {
|
||||
* @throws NoPermissionException
|
||||
*/
|
||||
public function update($cardId, $attachmentId, $data, $type = 'deck_file') {
|
||||
$this->attachmentServiceValidator->check(compact('cardId', 'type', 'data'));
|
||||
|
||||
try {
|
||||
$service = $this->getService($type);
|
||||
} catch (InvalidAttachmentType $e) {
|
||||
@@ -290,9 +286,6 @@ class AttachmentService {
|
||||
}
|
||||
}
|
||||
|
||||
if ($data === false || $data === null) {
|
||||
//throw new BadRequestException('data must be provided');
|
||||
}
|
||||
try {
|
||||
$attachment = $this->attachmentMapper->find($attachmentId);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -52,6 +52,7 @@ use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCP\IUserManager;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCA\Deck\Validators\BoardServiceValidator;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class BoardService {
|
||||
@@ -75,6 +76,7 @@ class BoardService {
|
||||
|
||||
private $boardsCache = null;
|
||||
private $urlGenerator;
|
||||
private $boardServiceValidator;
|
||||
|
||||
|
||||
public function __construct(
|
||||
@@ -94,6 +96,7 @@ class BoardService {
|
||||
IEventDispatcher $eventDispatcher,
|
||||
ChangeHelper $changeHelper,
|
||||
IURLGenerator $urlGenerator,
|
||||
BoardServiceValidator $boardServiceValidator,
|
||||
$userId
|
||||
) {
|
||||
$this->boardMapper = $boardMapper;
|
||||
@@ -113,6 +116,7 @@ class BoardService {
|
||||
$this->userId = $userId;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->boardServiceValidator = $boardServiceValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,6 +181,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function find($boardId) {
|
||||
$this->boardServiceValidator->check(compact('boardId'));
|
||||
if ($this->boardsCache && isset($this->boardsCache[$boardId])) {
|
||||
return $this->boardsCache[$boardId];
|
||||
}
|
||||
@@ -231,9 +236,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function isArchived($mapper, $id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id'));
|
||||
|
||||
try {
|
||||
$boardId = $id;
|
||||
@@ -260,13 +263,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function isDeleted($mapper, $id) {
|
||||
if ($mapper === false || $mapper === null) {
|
||||
throw new BadRequestException('mapper must be provided');
|
||||
}
|
||||
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('mapper', 'id'));
|
||||
|
||||
try {
|
||||
$boardId = $id;
|
||||
@@ -292,17 +289,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function create($title, $userId, $color) {
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if ($userId === false || $userId === null) {
|
||||
throw new BadRequestException('userId must be provided');
|
||||
}
|
||||
|
||||
if ($color === false || $color === null) {
|
||||
throw new BadRequestException('color must be provided');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('title', 'userId', 'color'));
|
||||
|
||||
if (!$this->permissionService->canCreate()) {
|
||||
throw new NoPermissionException('Creating boards has been disabled for your account.');
|
||||
@@ -353,9 +340,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function delete($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
@@ -378,9 +363,7 @@ class BoardService {
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
*/
|
||||
public function deleteUndo($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
@@ -401,9 +384,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function deleteForce($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
@@ -424,21 +405,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function update($id, $title, $color, $archived) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if ($color === false || $color === null) {
|
||||
throw new BadRequestException('color must be provided');
|
||||
}
|
||||
|
||||
if (is_bool($archived) === false) {
|
||||
throw new BadRequestException('archived must be a boolean');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id', 'title', 'color', 'archived'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
@@ -488,29 +455,7 @@ class BoardService {
|
||||
* @throws \OCA\Deck\NoPermissionException
|
||||
*/
|
||||
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
if ($type === false || $type === null) {
|
||||
throw new BadRequestException('type must be provided');
|
||||
}
|
||||
|
||||
if ($participant === false || $participant === null) {
|
||||
throw new BadRequestException('participant must be provided');
|
||||
}
|
||||
|
||||
if ($edit === null) {
|
||||
throw new BadRequestException('edit must be provided');
|
||||
}
|
||||
|
||||
if ($share === null) {
|
||||
throw new BadRequestException('share must be provided');
|
||||
}
|
||||
|
||||
if ($manage === null) {
|
||||
throw new BadRequestException('manage must be provided');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('boardId', 'type', 'participant', 'edit', 'share', 'manage'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_SHARE);
|
||||
[$edit, $share, $manage] = $this->applyPermissions($boardId, $edit, $share, $manage);
|
||||
@@ -556,21 +501,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function updateAcl($id, $edit, $share, $manage) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
|
||||
if ($edit === null) {
|
||||
throw new BadRequestException('edit must be provided');
|
||||
}
|
||||
|
||||
if ($share === null) {
|
||||
throw new BadRequestException('share must be provided');
|
||||
}
|
||||
|
||||
if ($manage === null) {
|
||||
throw new BadRequestException('manage must be provided');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id', 'edit', 'share', 'manage'));
|
||||
|
||||
$this->permissionService->checkPermission($this->aclMapper, $id, Acl::PERMISSION_SHARE);
|
||||
|
||||
@@ -642,9 +573,7 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function clone($id, $userId) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
$this->boardServiceValidator->check(compact('id', 'userId'));
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCA\Deck\Validators\CardServiceValidator;
|
||||
use OCP\Comments\ICommentsManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IUserManager;
|
||||
@@ -65,6 +66,7 @@ class CardService {
|
||||
private $eventDispatcher;
|
||||
private $userManager;
|
||||
private $urlGenerator;
|
||||
private $cardServiceValidator;
|
||||
|
||||
public function __construct(
|
||||
CardMapper $cardMapper,
|
||||
@@ -82,6 +84,7 @@ class CardService {
|
||||
ChangeHelper $changeHelper,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
IURLGenerator $urlGenerator,
|
||||
CardServiceValidator $cardServiceValidator,
|
||||
$userId
|
||||
) {
|
||||
$this->cardMapper = $cardMapper;
|
||||
@@ -100,6 +103,7 @@ class CardService {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->currentUser = $userId;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->cardServiceValidator = $cardServiceValidator;
|
||||
}
|
||||
|
||||
public function enrich($card) {
|
||||
@@ -122,6 +126,7 @@ class CardService {
|
||||
}
|
||||
|
||||
public function fetchDeleted($boardId) {
|
||||
$this->cardServiceValidator->check(compact('boardId'));
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$cards = $this->cardMapper->findDeleted($boardId);
|
||||
foreach ($cards as $card) {
|
||||
@@ -187,29 +192,7 @@ class CardService {
|
||||
* @throws BadrequestException
|
||||
*/
|
||||
public function create($title, $stackId, $type, $order, $owner, $description = '', $duedate = null) {
|
||||
if ($title === 'false' || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
|
||||
throw new BadRequestException('The title cannot exceed 255 characters');
|
||||
}
|
||||
|
||||
if (is_numeric($stackId) === false) {
|
||||
throw new BadRequestException('stack id must be a number');
|
||||
}
|
||||
|
||||
if ($type === 'false' || $type === null) {
|
||||
throw new BadRequestException('type must be provided');
|
||||
}
|
||||
|
||||
if (is_numeric($order) === false) {
|
||||
throw new BadRequestException('order must be a number');
|
||||
}
|
||||
|
||||
if ($owner === false || $owner === null) {
|
||||
throw new BadRequestException('owner must be provided');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('title', 'stackId', 'type', 'order', 'owner'));
|
||||
|
||||
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->stackMapper, $stackId)) {
|
||||
@@ -279,29 +262,7 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function update($id, $title, $stackId, $type, $owner, $description = '', $order = 0, $duedate = null, $deletedAt = null, $archived = null) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
|
||||
throw new BadRequestException('The title cannot exceed 255 characters');
|
||||
}
|
||||
|
||||
if (is_numeric($stackId) === false) {
|
||||
throw new BadRequestException('stack id must be a number $$$');
|
||||
}
|
||||
|
||||
if ($type === false || $type === null) {
|
||||
throw new BadRequestException('type must be provided');
|
||||
}
|
||||
|
||||
if ($owner === false || $owner === null) {
|
||||
throw new BadRequestException('owner must be provided');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('id', 'title', 'stackId', 'type', 'owner', 'order'));
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
|
||||
@@ -384,17 +345,7 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function rename($id, $title) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if (mb_strlen($title) > Card::TITLE_MAX_LENGTH) {
|
||||
throw new BadRequestException('The title cannot exceed 255 characters');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('id', 'title'));
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
@@ -425,17 +376,8 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function reorder($id, $stackId, $order) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('id', 'stackId', 'order'));
|
||||
|
||||
if (is_numeric($stackId) === false) {
|
||||
throw new BadRequestException('stack id must be a number');
|
||||
}
|
||||
|
||||
if (is_numeric($order) === false) {
|
||||
throw new BadRequestException('order must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
|
||||
@@ -490,9 +432,8 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function archive($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('id'));
|
||||
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
@@ -520,9 +461,8 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function unarchive($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('id'));
|
||||
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->cardMapper, $id)) {
|
||||
@@ -549,13 +489,8 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function assignLabel($cardId, $labelId) {
|
||||
if (is_numeric($cardId) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('cardId', 'labelId'));
|
||||
|
||||
if (is_numeric($labelId) === false) {
|
||||
throw new BadRequestException('label id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
|
||||
@@ -583,13 +518,8 @@ class CardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function removeLabel($cardId, $labelId) {
|
||||
if (is_numeric($cardId) === false) {
|
||||
throw new BadRequestException('card id must be a number');
|
||||
}
|
||||
$this->cardServiceValidator->check(compact('cardId', 'labelId'));
|
||||
|
||||
if (is_numeric($labelId) === false) {
|
||||
throw new BadRequestException('label id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);
|
||||
if ($this->boardService->isArchived($this->cardMapper, $cardId)) {
|
||||
|
||||
@@ -29,6 +29,7 @@ use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCA\Deck\Validators\LabelServiceValidator;
|
||||
|
||||
class LabelService {
|
||||
|
||||
@@ -40,12 +41,21 @@ class LabelService {
|
||||
private $boardService;
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
/** @var LabelServiceValidator */
|
||||
private LabelServiceValidator $labelServiceValidator;
|
||||
|
||||
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService, ChangeHelper $changeHelper) {
|
||||
public function __construct(
|
||||
LabelMapper $labelMapper,
|
||||
PermissionService $permissionService,
|
||||
BoardService $boardService,
|
||||
ChangeHelper $changeHelper,
|
||||
LabelServiceValidator $labelServiceValidator
|
||||
) {
|
||||
$this->labelMapper = $labelMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->boardService = $boardService;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->labelServiceValidator = $labelServiceValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,17 +86,7 @@ class LabelService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function create($title, $color, $boardId) {
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if ($color === false || $color === null) {
|
||||
throw new BadRequestException('color must be provided');
|
||||
}
|
||||
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
$this->labelServiceValidator->check(compact('title', 'color', 'boardId'));
|
||||
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
|
||||
|
||||
@@ -121,9 +121,7 @@ class LabelService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function delete($id) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('label id must be a number');
|
||||
}
|
||||
$this->labelServiceValidator->check(compact('id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
if ($this->boardService->isArchived($this->labelMapper, $id)) {
|
||||
@@ -146,17 +144,7 @@ class LabelService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function update($id, $title, $color) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('label id must be a number');
|
||||
}
|
||||
|
||||
if ($title === false || $title === null || $title === "") {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if ($color === false || $color === null) {
|
||||
throw new BadRequestException('color must be provided');
|
||||
}
|
||||
$this->labelServiceValidator->check(compact('title', 'color', 'id'));
|
||||
|
||||
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCA\Deck\Validators\StackServiceValidator;
|
||||
|
||||
class StackService {
|
||||
private $stackMapper;
|
||||
@@ -50,6 +51,7 @@ class StackService {
|
||||
private $attachmentService;
|
||||
private $activityManager;
|
||||
private $changeHelper;
|
||||
private $stackServiceValidator;
|
||||
|
||||
public function __construct(
|
||||
StackMapper $stackMapper,
|
||||
@@ -62,6 +64,7 @@ class StackService {
|
||||
AssignmentMapper $assignedUsersMapper,
|
||||
AttachmentService $attachmentService,
|
||||
ActivityManager $activityManager,
|
||||
StackServiceValidator $stackServiceValidator,
|
||||
ChangeHelper $changeHelper
|
||||
) {
|
||||
$this->stackMapper = $stackMapper;
|
||||
@@ -75,6 +78,7 @@ class StackService {
|
||||
$this->attachmentService = $attachmentService;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->changeHelper = $changeHelper;
|
||||
$this->stackServiceValidator = $stackServiceValidator;
|
||||
}
|
||||
|
||||
private function enrichStackWithCards($stack, $since = -1) {
|
||||
@@ -202,17 +206,7 @@ class StackService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function create($title, $boardId, $order) {
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if (is_numeric($order) === false) {
|
||||
throw new BadRequestException('order must be a number');
|
||||
}
|
||||
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
$this->stackServiceValidator->check(compact('title', 'boardId', 'order'));
|
||||
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
|
||||
if ($this->boardService->isArchived(null, $boardId)) {
|
||||
@@ -275,21 +269,7 @@ class StackService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function update($id, $title, $boardId, $order, $deletedAt) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRequestException('stack id must be a number');
|
||||
}
|
||||
|
||||
if ($title === false || $title === null) {
|
||||
throw new BadRequestException('title must be provided');
|
||||
}
|
||||
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
if (is_numeric($order) === false) {
|
||||
throw new BadRequestException('order must be a number');
|
||||
}
|
||||
$this->stackServiceValidator->check(compact('id', 'title', 'boardId', 'order'));
|
||||
|
||||
$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_MANAGE);
|
||||
@@ -325,13 +305,7 @@ class StackService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function reorder($id, $order) {
|
||||
if (is_numeric($id) === false) {
|
||||
throw new BadRquestException('id must be a number');
|
||||
}
|
||||
|
||||
if ($order === false || $order === null) {
|
||||
throw new BadRequestException('order must be provided');
|
||||
}
|
||||
$this->stackServiceValidator->check(compact('id', 'order'));
|
||||
|
||||
$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$stackToSort = $this->stackMapper->find($id);
|
||||
|
||||
Reference in New Issue
Block a user