Skip to content

Commit

Permalink
feat: Add SanctionsFallbackData and Metadata models
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Oct 16, 2023
1 parent a08d4a4 commit 217cbc6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .annotation_safe_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ contenttypes.ContentType:
".. no_pii:": "This model has no PII"
sanctions.SDNCheckFailure:
".. no_pii:": "This model has no PII"
sanctions.SDNFallbackMetadata:
".. no_pii:": "This model has no PII"
sanctions.SDNFallbackData:
".. no_pii:": "This model has no PII"
sessions.Session:
".. no_pii:": "This model has no PII"
social_django.Association:
Expand Down
55 changes: 55 additions & 0 deletions sanctions/apps/api/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from simple_history.models import HistoricalRecords

from django.core.validators import MinLengthValidator
from django.db import models
from django_extensions.db.models import TimeStampedModel
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -27,3 +28,57 @@ def __str__(self):
return 'Sanctions check failure [{username}]'.format(
username=self.username
)

class SanctionsFallbackMetadata(TimeStampedModel):
"""
Record metadata about the SDN fallback CSV file download. This table is used to track the state of the SDN CSV file data that are currently
being used or about to be updated/deprecated. This table does not keep track of the SDN files over time.
"""
history = HistoricalRecords()
file_checksum = models.CharField(max_length=255, validators=[MinLengthValidator(1)])
download_timestamp = models.DateTimeField()
import_timestamp = models.DateTimeField(null=True, blank=True)

IMPORT_STATES = [
('New', 'New'),
('Current', 'Current'),
('Discard', 'Discard'),
]

import_state = models.CharField(
max_length=255,
validators=[MinLengthValidator(1)],
unique=True,
choices=IMPORT_STATES,
default='New',
)

class SanctionsFallbackData(models.Model):
"""
Model used to record and process one row received from SanctionsFallbackMetadata.
Fields:
sanctions_fallback_metadata (ForeignKey): Foreign Key field with the CSV import Primary Key
referenced in SanctionsFallbackMetadata.
source (CharField): Origin of where the data comes from, since the CSV consolidates
export screening lists of the Departments of Commerce, State and the Treasury.
sdn_type (CharField): For a person with source 'Specially Designated Nationals (SDN)
- Treasury Department', the type is 'Individual'. Other options include 'Entity' and
'Vessel'. Other lists do not have a type.
names (TextField): A space separated list of all lowercased names and alt names with
punctuation also replaced by spaces.
addresses (TextField): A space separated list of all lowercased addresses combined into one
string. There are records that don't have an address, but because city is a required field
in the Payment MFE, those records would not be matched in the API/fallback.
countries (CharField): A space separated list of all countries combined into one string.
Countries are extracted from the addresses field and in some instances the ID field in their
2 letter abbreviation. There are records that don't have a country, but because country is a
required field in billing information form, those records would not be matched in the API/fallback.
"""
history = HistoricalRecords()
sanctions_fallback_metadata = models.ForeignKey('sanctions.SanctionsFallbackMetadata', on_delete=models.CASCADE)
source = models.CharField(default='', max_length=255, db_index=True)
sdn_type = models.CharField(default='', max_length=255, db_index=True)
names = models.TextField(default='')
addresses = models.TextField(default='')
countries = models.CharField(default='', max_length=255)

0 comments on commit 217cbc6

Please sign in to comment.