Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter returned entity result by view columns #881

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading