Skip to content

Commit 98aacbc

Browse files
authored
Merge pull request #1526 from nextcloud/fix/1499/allow-metadata-views
fix: allow adding meta data columns to views again
2 parents 5364410 + 6dde229 commit 98aacbc

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/Db/Column.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class Column extends Entity implements JsonSerializable {
8484
public const TYPE_META_UPDATED_BY = -3;
8585
public const TYPE_META_CREATED_AT = -4;
8686
public const TYPE_META_UPDATED_AT = -5;
87+
// In case a new one is added, add it to isValidMetaTypeId() as well.
88+
// When we drop PHP 8.0, we can switch to enums.
8789

8890
public const TYPE_SELECTION = 'selection';
8991
public const TYPE_TEXT = 'text';
@@ -153,6 +155,16 @@ public function __construct() {
153155
$this->addType('showUserStatus', 'boolean');
154156
}
155157

158+
public static function isValidMetaTypeId(int $metaTypeId): bool {
159+
return in_array($metaTypeId, [
160+
self::TYPE_META_ID,
161+
self::TYPE_META_CREATED_BY,
162+
self::TYPE_META_UPDATED_BY,
163+
self::TYPE_META_CREATED_AT,
164+
self::TYPE_META_UPDATED_AT,
165+
], true);
166+
}
167+
156168
public static function fromDto(ColumnDto $data): self {
157169
$column = new self();
158170
$column->setTitle($data->getTitle());

lib/Service/ViewService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function update(int $id, array $data, ?string $userId = null, bool $skipT
271271
$availableColumns = $columnService->findAllByTable($view->getTableId(), $view->getId(), $this->userId);
272272
$availableColumns = array_map(static fn (Column $column) => $column->getId(), $availableColumns);
273273
foreach ($columnIds as $columnId) {
274-
if (!in_array($columnId, $availableColumns, true)) {
274+
if (!Column::isValidMetaTypeId($columnId) && !in_array($columnId, $availableColumns, true)) {
275275
throw new InvalidArgumentException('Invalid column ID provided');
276276
}
277277
}

tests/integration/features/APIv1.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Feature: APIv1
243243
| mandatory | 0 |
244244
| description | Note me a thing |
245245
And user "participant1" create view "Simple View" with emoji "🙃" for "table_p1" as "simple-view"
246-
When user "participant1" sets columns "Volatile Notes" to view "simple-view"
246+
When user "participant1" sets columns "Volatile Notes,-1" to view "simple-view"
247247
Then the reported status is "200"
248248

249249
@api1 @views

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ public function applyColumnsToView(string $user, string $columnList, string $vie
868868

869869
$columns = explode(',', $columnList);
870870
$columns = array_map(function (string $columnAlias) {
871+
if (is_numeric($columnAlias)) {
872+
return (int)$columnAlias;
873+
}
871874
$col = $this->collectionManager->getByAlias('column', $columnAlias);
872875
return $col['id'];
873876
}, $columns);

0 commit comments

Comments
 (0)