From 3c039bac901a0d67dd19f16fbbb4755548041497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 29 Feb 2024 08:02:54 +0100 Subject: [PATCH] fix: Filter returned entity result by view columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/Row2.php | 10 ++++++++++ lib/Service/RowService.php | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Db/Row2.php b/lib/Db/Row2.php index 6b1b6adb0..cd7796bdd 100644 --- a/lib/Db/Row2.php +++ b/lib/Db/Row2.php @@ -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 */ diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index 5d89cc652..e8d3ca416 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -397,7 +397,7 @@ public function updateSet( } } - return $this->row2Mapper->update($item, $columns); + return $this->filterRowResult($view ?? null, $this->row2Mapper->update($item, $columns)); } /** @@ -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()); @@ -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; + } }