Skip to content

Commit

Permalink
fix: Filter returned entity result by view columns
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Feb 29, 2024
1 parent 12455fd commit 3c039ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/Db/Row2.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public function insertOrUpdateCell(array $entry): string {
return 'inserted';
}

/**
* @param int[] $columns
*/
public function filterDataByColumns(array $columns): array {
$this->data = array_values(array_filter($this->data, function ($entry) use ($columns) {
return in_array($entry['columnId'], $columns);
}));
return $this->data;
}

/**
* @psalm-return TablesRow
*/
Expand Down
14 changes: 12 additions & 2 deletions lib/Service/RowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function updateSet(
}
}

return $this->row2Mapper->update($item, $columns);
return $this->filterRowResult($view ?? null, $this->row2Mapper->update($item, $columns));
}

/**
Expand Down Expand Up @@ -450,7 +450,7 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 {
}

try {
return $this->row2Mapper->delete($item);
return $this->filterRowResult($view ?? null, $this->row2Mapper->delete($item));
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
Expand Down Expand Up @@ -522,4 +522,14 @@ public function getViewRowsCount(View $view, string $userId): int {
throw new PermissionError('no read access for counting to view id = '.$view->getId());
}
}

private function filterRowResult(?View $view, Row2 $row): Row2 {
if ($view === null) {
return $row;
}

$row->filterDataByColumns($view->getColumnsArray());

return $row;
}
}

0 comments on commit 3c039ba

Please sign in to comment.