diff --git a/src/fides/api/alembic/migrations/versions/4fba24045fec_add_property_id_indices.py b/src/fides/api/alembic/migrations/versions/4fba24045fec_add_property_id_indices.py index 04c56237fc..3ae7d898c8 100644 --- a/src/fides/api/alembic/migrations/versions/4fba24045fec_add_property_id_indices.py +++ b/src/fides/api/alembic/migrations/versions/4fba24045fec_add_property_id_indices.py @@ -16,6 +16,7 @@ branch_labels = None depends_on = None + def upgrade(): connection = op.get_bind() @@ -56,6 +57,7 @@ def upgrade(): "ON servednoticehistory (property_id)'" ) + def downgrade(): op.drop_index( op.f("ix_servednoticehistory_property_id"), table_name="servednoticehistory" diff --git a/src/fides/api/models/privacy_preference.py b/src/fides/api/models/privacy_preference.py index 594d652a52..822e2cf0eb 100644 --- a/src/fides/api/models/privacy_preference.py +++ b/src/fides/api/models/privacy_preference.py @@ -258,6 +258,12 @@ class ConsentReportingMixinV2(ConsentIdentitiesMixin): notice_name = Column(String, index=True) # Privacy Notice name or "TCF" + property_id = Column( + String, + index=True, + nullable=True, + ) + # The specific version of the experience config the user was shown to present the relevant notice # Contains the version, language, button labels, description, etc. @declared_attr @@ -327,12 +333,6 @@ def __tablename__(self) -> str: MutableDict.as_mutable(JSONB) ) # Dict of all the TCF attributes served if applicable - property_id = Column( - String, - index=True, - nullable=True, - ) - @staticmethod def get_by_served_id(db: Session, served_id: str) -> Query: """Retrieves all ServedNoticeHistory records with a common served_notice_history_id - generated @@ -394,12 +394,6 @@ def __tablename__(self) -> str: MutableDict.as_mutable(JSONB) ) # Dict of TCF attributes saved, for a TCF notice - property_id = Column( - String, - index=True, - nullable=True, - ) - privacy_request = relationship(PrivacyRequest, backref="privacy_preferences") def cache_system_status( diff --git a/tests/fixtures/application_fixtures.py b/tests/fixtures/application_fixtures.py index 765648ce39..018841df5a 100644 --- a/tests/fixtures/application_fixtures.py +++ b/tests/fixtures/application_fixtures.py @@ -64,6 +64,7 @@ ProvidedIdentity, RequestTask, ) +from fides.api.models.property import Property from fides.api.models.registration import UserRegistration from fides.api.models.sql_models import DataCategory as DataCategoryDbModel from fides.api.models.sql_models import Dataset as CtlDataset @@ -81,6 +82,8 @@ MessagingServiceSecrets, MessagingServiceType, ) +from fides.api.schemas.property import Property as PropertySchema +from fides.api.schemas.property import PropertyType from fides.api.schemas.redis_cache import CustomPrivacyRequestField, Identity from fides.api.schemas.storage.storage import ( FileNaming, @@ -3245,3 +3248,15 @@ def postgres_and_mongo_dataset_graph( dataset_mongo = Dataset(**example_datasets[1]) mongo_graph = convert_dataset_to_graph(dataset_mongo, mongo_connection_config.key) return DatasetGraph(*[graph, mongo_graph]) + + +@pytest.fixture(scope="function") +def property_a(db) -> Generator: + prop_a = Property.create( + db=db, + data=PropertySchema( + name="New Property", type=PropertyType.website, experiences=[] + ).dict(), + ) + yield prop_a + prop_a.delete(db=db) diff --git a/tests/ops/models/test_privacy_preference.py b/tests/ops/models/test_privacy_preference.py index 3f4b2c8161..17afd05101 100644 --- a/tests/ops/models/test_privacy_preference.py +++ b/tests/ops/models/test_privacy_preference.py @@ -8,12 +8,14 @@ class TestPrivacyPreference: + def test_privacy_notice_preference( self, db, privacy_experience_privacy_center, privacy_notice_us_ca_provide, served_notice_history, + property_a, ): preference_history_record = PrivacyPreferenceHistory.create( db=db, @@ -33,6 +35,7 @@ def test_privacy_notice_preference( "user_geography": "us_ca", "url_recorded": "https://example.com/privacy_center", "served_notice_history_id": served_notice_history.served_notice_history_id, + "property_id": property_a.id, }, check_name=False, ) @@ -46,14 +49,11 @@ def test_privacy_notice_preference( preference_history_record.privacy_notice_history == privacy_notice_us_ca_provide.translations[0].histories[0] ) + assert preference_history_record.property_id == property_a.id preference_history_record.delete(db) - def test_tcf_preference( - self, - db, - privacy_experience_france_overlay, - ): + def test_tcf_preference(self, db, privacy_experience_france_overlay, property_a): preference_history_record = PrivacyPreferenceHistory.create( db=db, data={ @@ -83,6 +83,7 @@ def test_tcf_preference( "feature_preferences": [], "system_legitimate_interests_preferences": [], }, + "property_id": property_a.id, }, ) assert preference_history_record.preference == UserConsentPreference.tcf @@ -100,6 +101,7 @@ def test_tcf_preference( "feature_preferences": [], "system_legitimate_interests_preferences": [], } + assert preference_history_record.property_id == property_a.id preference_history_record.delete(db) diff --git a/tests/ops/models/test_property.py b/tests/ops/models/test_property.py index ef203e726b..e5e40fc229 100644 --- a/tests/ops/models/test_property.py +++ b/tests/ops/models/test_property.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Generator +from typing import Any, Dict import pytest from sqlalchemy.orm import Session @@ -9,17 +9,6 @@ class TestProperty: - @pytest.fixture(scope="function") - def property_a(self, db) -> Generator: - prop_a = Property.create( - db=db, - data=PropertySchema( - name="New Property", type=PropertyType.website, experiences=[] - ).dict(), - ) - yield prop_a - prop_a.delete(db=db) - @pytest.fixture(scope="function") def minimal_experience( self, db, privacy_experience_privacy_center