feat(campaign): enforce attachment delivery policies
This commit is contained in:
@@ -10,6 +10,7 @@ from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from .field_values import ignored_entry_field_overrides
|
||||
from .models import AttachmentConfig, CampaignConfig, EntryConfig, FieldType, SourceType, ZipArchiveConfig, ZipPasswordMode, ZipPasswordScope, ZipRuleMode
|
||||
from ..attachments.resolver import resolve_campaign_attachments
|
||||
|
||||
|
||||
class Severity(StrEnum):
|
||||
@@ -507,6 +508,7 @@ def _entries_source_file_issues(config: CampaignConfig, campaign_path: Path, map
|
||||
def _file_check_issues(config: CampaignConfig, campaign_path: Path) -> list[SemanticIssue]:
|
||||
issues: list[SemanticIssue] = []
|
||||
issues.extend(_attachment_file_check_issues(config, campaign_path))
|
||||
issues.extend(_attachment_resolution_check_issues(config, campaign_path))
|
||||
issues.extend(_template_source_file_issues(config, campaign_path))
|
||||
return issues
|
||||
|
||||
@@ -536,6 +538,37 @@ def _attachment_file_check_issues(config: CampaignConfig, campaign_path: Path) -
|
||||
]
|
||||
|
||||
|
||||
def _attachment_resolution_check_issues(config: CampaignConfig, campaign_path: Path) -> list[SemanticIssue]:
|
||||
try:
|
||||
report = resolve_campaign_attachments(config, campaign_file=campaign_path)
|
||||
except Exception as exc:
|
||||
return [
|
||||
_issue(
|
||||
Severity.ERROR,
|
||||
"attachment_resolution_failed",
|
||||
f"attachment rules could not be resolved: {exc}",
|
||||
"/attachments",
|
||||
)
|
||||
]
|
||||
|
||||
issues: list[SemanticIssue] = []
|
||||
for entry in report.entries:
|
||||
entry_path = f"/entries/{entry.entry_id or entry.entry_index}"
|
||||
for issue in entry.issues:
|
||||
if any(issue is attachment_issue for attachment in entry.attachments for attachment_issue in attachment.issues):
|
||||
continue
|
||||
issues.append(_issue(Severity(issue.severity.value), issue.code, issue.message, entry_path))
|
||||
for attachment in entry.attachments:
|
||||
attachment_path = (
|
||||
f"/attachments/global/{attachment.index}"
|
||||
if attachment.scope.value == "global"
|
||||
else f"{entry_path}/attachments/{attachment.index}"
|
||||
)
|
||||
for issue in attachment.issues:
|
||||
issues.append(_issue(Severity(issue.severity.value), issue.code, issue.message, attachment_path))
|
||||
return issues
|
||||
|
||||
|
||||
def _template_source_file_issues(config: CampaignConfig, campaign_path: Path) -> list[SemanticIssue]:
|
||||
issues: list[SemanticIssue] = []
|
||||
for schema_path, raw_path in _iter_template_source_paths(config):
|
||||
|
||||
Reference in New Issue
Block a user