Skip to content

Commit 1cd0b5a

Browse files
authored
Merge pull request #2715 from nextcloud/backport/2414/stable1.0
[stable1.0] fix: add validation for columnDto
2 parents 20096f2 + 2fe2f34 commit 1cd0b5a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

lib/Service/ColumnService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCA\Tables\Helper\UserHelper;
2323
use OCA\Tables\ResponseDefinitions;
2424
use OCA\Tables\Service\ValueObject\ViewColumnInformation;
25+
use OCA\Tables\Validation\ColumnDtoValidator;
2526
use OCP\AppFramework\Db\DoesNotExistException;
2627
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
2728
use OCP\IL10N;
@@ -43,6 +44,8 @@ class ColumnService extends SuperService {
4344

4445
private UserHelper $userHelper;
4546

47+
private ColumnDtoValidator $columnDtoValidator;
48+
4649
public function __construct(
4750
PermissionsService $permissionsService,
4851
LoggerInterface $logger,
@@ -53,6 +56,7 @@ public function __construct(
5356
RowService $rowService,
5457
IL10N $l,
5558
UserHelper $userHelper,
59+
ColumnDtoValidator $columnDtoValidator,
5660
) {
5761
parent::__construct($logger, $userId, $permissionsService);
5862
$this->mapper = $mapper;
@@ -61,6 +65,7 @@ public function __construct(
6165
$this->rowService = $rowService;
6266
$this->l = $l;
6367
$this->userHelper = $userHelper;
68+
$this->columnDtoValidator = $columnDtoValidator;
6469
}
6570

6671
/**
@@ -181,6 +186,7 @@ public function create(
181186
if (ColumnType::tryFrom($columnDto->getType()) === null) {
182187
throw new BadRequestError('Column type ' . $columnDto->getType() . ' does not exist.');
183188
}
189+
$this->columnDtoValidator->validate($columnDto);
184190
// security
185191
if ($viewId) {
186192
try {
@@ -298,6 +304,7 @@ public function update(
298304
if (!$this->permissionsService->canUpdateColumnsByTableId($item->getTableId())) {
299305
throw new PermissionError('update column id = ' . $columnId . ' is not allowed.');
300306
}
307+
$this->columnDtoValidator->validate($columnDto);
301308

302309
if ($columnDto->getTitle() !== null) {
303310
$item->setTitle($columnDto->getTitle());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Tables\Validation;
9+
10+
use OCA\Tables\Dto\Column as ColumnDto;
11+
use OCA\Tables\Errors\BadRequestError;
12+
13+
class ColumnDtoValidator {
14+
/**
15+
* @throws BadRequestError
16+
*/
17+
public function validate(ColumnDto $columnDto): void {
18+
$textMaxLength = $columnDto->getTextMaxLength();
19+
if ($textMaxLength !== null && $textMaxLength < -1) {
20+
throw new BadRequestError('Maximum text length must be greater than or equal to 0, or -1 for no limit.');
21+
}
22+
23+
$numberMin = $columnDto->getNumberMin();
24+
$numberMax = $columnDto->getNumberMax();
25+
if ($numberMin !== null && $numberMax !== null && $numberMin > $numberMax) {
26+
throw new BadRequestError('Minimum number must be less than or equal to maximum number.');
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)