diff --git a/.annotation_safe_list.yml b/.annotation_safe_list.yml index a410180..2465ff8 100644 --- a/.annotation_safe_list.yml +++ b/.annotation_safe_list.yml @@ -17,6 +17,10 @@ contenttypes.ContentType: ".. no_pii:": "This model has no PII" sanctions.SanctionsCheckFailure: ".. no_pii:": "This model has no PII" +sanctions.SanctionsFallbackMetadata: + ".. no_pii:": "This model has no PII" +sanctions.SanctionsFallbackData: + ".. no_pii:": "This model has no PII" sessions.Session: ".. no_pii:": "This model has no PII" social_django.Association: diff --git a/sanctions/apps/api/models.py b/sanctions/apps/api/models.py index 4566b3b..8fdadd3 100644 --- a/sanctions/apps/api/models.py +++ b/sanctions/apps/api/models.py @@ -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 _ @@ -28,3 +29,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)