Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Service/ColumnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCA\Tables\Helper\UserHelper;
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\ValueObject\ViewColumnInformation;
use OCA\Tables\Validation\ColumnDtoValidator;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IL10N;
Expand All @@ -43,6 +44,8 @@ class ColumnService extends SuperService {

private UserHelper $userHelper;

private ColumnDtoValidator $columnDtoValidator;

public function __construct(
PermissionsService $permissionsService,
LoggerInterface $logger,
Expand All @@ -53,6 +56,7 @@ public function __construct(
RowService $rowService,
IL10N $l,
UserHelper $userHelper,
ColumnDtoValidator $columnDtoValidator,
) {
parent::__construct($logger, $userId, $permissionsService);
$this->mapper = $mapper;
Expand All @@ -61,6 +65,7 @@ public function __construct(
$this->rowService = $rowService;
$this->l = $l;
$this->userHelper = $userHelper;
$this->columnDtoValidator = $columnDtoValidator;
}

/**
Expand Down Expand Up @@ -181,6 +186,7 @@ public function create(
if (ColumnType::tryFrom($columnDto->getType()) === null) {
throw new BadRequestError('Column type ' . $columnDto->getType() . ' does not exist.');
}
$this->columnDtoValidator->validate($columnDto);
// security
if ($viewId) {
try {
Expand Down Expand Up @@ -298,6 +304,7 @@ public function update(
if (!$this->permissionsService->canUpdateColumnsByTableId($item->getTableId())) {
throw new PermissionError('update column id = ' . $columnId . ' is not allowed.');
}
$this->columnDtoValidator->validate($columnDto);

if ($columnDto->getTitle() !== null) {
$item->setTitle($columnDto->getTitle());
Expand Down
29 changes: 29 additions & 0 deletions lib/Validation/ColumnDtoValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Tables\Validation;

use OCA\Tables\Dto\Column as ColumnDto;
use OCA\Tables\Errors\BadRequestError;

class ColumnDtoValidator {
/**
* @throws BadRequestError
*/
public function validate(ColumnDto $columnDto): void {
$textMaxLength = $columnDto->getTextMaxLength();
if ($textMaxLength !== null && $textMaxLength < -1) {
throw new BadRequestError('Maximum text length must be greater than or equal to 0, or -1 for no limit.');
}

$numberMin = $columnDto->getNumberMin();
$numberMax = $columnDto->getNumberMax();
if ($numberMin !== null && $numberMax !== null && $numberMin > $numberMax) {
throw new BadRequestError('Minimum number must be less than or equal to maximum number.');
}
}
}
Loading