Skip to content

Commit

Permalink
Merge pull request #1526 from nextcloud/fix/1499/allow-metadata-views
Browse files Browse the repository at this point in the history
fix: allow adding meta data columns to views again
  • Loading branch information
juliusknorr authored Jan 7, 2025
2 parents 5364410 + 6dde229 commit 98aacbc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Column extends Entity implements JsonSerializable {
public const TYPE_META_UPDATED_BY = -3;
public const TYPE_META_CREATED_AT = -4;
public const TYPE_META_UPDATED_AT = -5;
// In case a new one is added, add it to isValidMetaTypeId() as well.
// When we drop PHP 8.0, we can switch to enums.

public const TYPE_SELECTION = 'selection';
public const TYPE_TEXT = 'text';
Expand Down Expand Up @@ -153,6 +155,16 @@ public function __construct() {
$this->addType('showUserStatus', 'boolean');
}

public static function isValidMetaTypeId(int $metaTypeId): bool {
return in_array($metaTypeId, [
self::TYPE_META_ID,
self::TYPE_META_CREATED_BY,
self::TYPE_META_UPDATED_BY,
self::TYPE_META_CREATED_AT,
self::TYPE_META_UPDATED_AT,
], true);
}

public static function fromDto(ColumnDto $data): self {
$column = new self();
$column->setTitle($data->getTitle());
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function update(int $id, array $data, ?string $userId = null, bool $skipT
$availableColumns = $columnService->findAllByTable($view->getTableId(), $view->getId(), $this->userId);
$availableColumns = array_map(static fn (Column $column) => $column->getId(), $availableColumns);
foreach ($columnIds as $columnId) {
if (!in_array($columnId, $availableColumns, true)) {
if (!Column::isValidMetaTypeId($columnId) && !in_array($columnId, $availableColumns, true)) {
throw new InvalidArgumentException('Invalid column ID provided');
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/APIv1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Feature: APIv1
| mandatory | 0 |
| description | Note me a thing |
And user "participant1" create view "Simple View" with emoji "🙃" for "table_p1" as "simple-view"
When user "participant1" sets columns "Volatile Notes" to view "simple-view"
When user "participant1" sets columns "Volatile Notes,-1" to view "simple-view"
Then the reported status is "200"

@api1 @views
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ public function applyColumnsToView(string $user, string $columnList, string $vie

$columns = explode(',', $columnList);
$columns = array_map(function (string $columnAlias) {
if (is_numeric($columnAlias)) {
return (int)$columnAlias;
}
$col = $this->collectionManager->getByAlias('column', $columnAlias);
return $col['id'];
}, $columns);
Expand Down

0 comments on commit 98aacbc

Please sign in to comment.