Merge pull request #17544 from marcusmoore/fixes/custom-field-filter

Fixed invalid custom fields being used for filtering
This commit is contained in:
snipe
2025-08-15 14:39:09 +02:00
committed by GitHub

View File

@@ -117,15 +117,21 @@ class AssetsController extends Controller
'jobtitle',
];
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
foreach ($all_custom_fields as $field) {
// custom fields are prefixed with "custom_fields.".
// We'll add them to the allowed columns so they can be searched.
$allowed_columns[] = 'custom_fields.' . $field->db_column_name();
}
$filter = [];
if ($request->filled('filter')) {
$filter = json_decode($request->input('filter'), true);
}
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
foreach ($all_custom_fields as $field) {
$allowed_columns[] = $field->db_column_name();
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
return in_array($key, $allowed_columns);
}, ARRAY_FILTER_USE_KEY);
}
$assets = Asset::select('assets.*')