fix: exclude provider records from source exports
All checks were successful
All checks were successful
This commit is contained in:
@@ -54,6 +54,11 @@ DEFAULT_XLSX_DATA_ROWS_PER_FILE = 100_000
|
||||
DEFAULT_DOWNLOAD_TICKET_TTL_SECONDS = 5 * 60
|
||||
SOURCE_RECORD_EXPORT_TICKET_CACHE_PREFIX = "external-data:source-record-exports:ticket"
|
||||
SOURCE_RECORD_EXPORT_TICKET_PATTERN = re.compile(r"[A-Za-z0-9_-]{43}")
|
||||
EXCLUDED_EXPORT_PROVIDER_PATTERN = re.compile(
|
||||
r"(?<![A-Za-zА-Яа-яЁё0-9])(?:checko(?:\.ru)?|чекало|чекко|чеко)"
|
||||
r"(?![A-Za-zА-Яа-яЁё0-9])",
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
ORGANIZATION_EXPORT_FIELDS = [
|
||||
"Наименование",
|
||||
@@ -737,6 +742,8 @@ def _spool_source_group_rows(
|
||||
is_first_row = True
|
||||
for model_spec in source_spec.models:
|
||||
for record in _iter_source_model_records(model_spec):
|
||||
if _is_excluded_export_provider_record(record, model_spec=model_spec):
|
||||
continue
|
||||
row = _build_record_row(
|
||||
record,
|
||||
source_spec=source_spec,
|
||||
@@ -911,6 +918,32 @@ def _build_record_row(
|
||||
return {key: _serialize_json_value(value) for key, value in row.items()}
|
||||
|
||||
|
||||
def _is_excluded_export_provider_record(
|
||||
record: Any,
|
||||
*,
|
||||
model_spec: SourceModelExportSpec,
|
||||
) -> bool:
|
||||
"""Return whether a provider-backed record must stay out of public files."""
|
||||
return any(
|
||||
_contains_excluded_export_provider(getattr(record, field_name))
|
||||
for field_name in model_spec.fields
|
||||
)
|
||||
|
||||
|
||||
def _contains_excluded_export_provider(value: object) -> bool:
|
||||
if isinstance(value, str):
|
||||
return EXCLUDED_EXPORT_PROVIDER_PATTERN.search(value) is not None
|
||||
if isinstance(value, dict):
|
||||
return any(
|
||||
_contains_excluded_export_provider(key)
|
||||
or _contains_excluded_export_provider(item)
|
||||
for key, item in value.items()
|
||||
)
|
||||
if isinstance(value, list | tuple):
|
||||
return any(_contains_excluded_export_provider(item) for item in value)
|
||||
return False
|
||||
|
||||
|
||||
def _serialize_flat_value(value: Any) -> str | int | float | bool:
|
||||
if value is None:
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user