feat: add validators to check values in services
Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
committed by
backportbot-nextcloud[bot]
parent
f250d9956b
commit
9d09916c17
@@ -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);
|
||||
|
||||
@@ -119,9 +119,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)) {
|
||||
@@ -144,17 +142,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user