mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
prune sensitive data from failed_import_rows data
This commit is contained in:
@@ -78,6 +78,8 @@ class ImportColumn extends Component
|
||||
|
||||
protected string | Htmlable | Closure | null $helperText = null;
|
||||
|
||||
protected bool | Closure $isSensitive = false;
|
||||
|
||||
final public function __construct(string $name)
|
||||
{
|
||||
$this->name($name);
|
||||
@@ -606,4 +608,16 @@ class ImportColumn extends Component
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType),
|
||||
};
|
||||
}
|
||||
|
||||
public function sensitive(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSensitive = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSensitive(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSensitive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,11 +143,30 @@ class ImportCsv implements ShouldQueue
|
||||
{
|
||||
$failedRow = app(FailedImportRow::class);
|
||||
$failedRow->import()->associate($this->import);
|
||||
$failedRow->data = $data;
|
||||
$failedRow->data = $this->filterSensitiveData($data, $this->columnMap);
|
||||
|
||||
$failedRow->validation_error = $validationError;
|
||||
$failedRow->save();
|
||||
}
|
||||
|
||||
protected function filterSensitiveData(array $data, array $columnMap): array
|
||||
{
|
||||
$sensitiveColumns = [];
|
||||
|
||||
foreach ($this->importer->getColumns() as $column) {
|
||||
if ($column->isSensitive()) {
|
||||
$csvHeader = $columnMap[$column->getName()] ?? null;
|
||||
if ($csvHeader !== null) {
|
||||
$sensitiveColumns[] = $csvHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter($data, function ($key) use ($sensitiveColumns) {
|
||||
return ! in_array($key, $sensitiveColumns, true);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
|
||||
protected function utf8Encode(mixed $value): mixed
|
||||
{
|
||||
if (is_array($value)) {
|
||||
|
||||
Reference in New Issue
Block a user