Skip to content

Commit

Permalink
remove deprecated fields from models
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsachs committed Dec 11, 2023
1 parent 57126b1 commit 799bb1b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 293 deletions.
155 changes: 0 additions & 155 deletions src/fideslang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from enum import Enum
from typing import Any, Dict, List, Optional, Union
from warnings import warn

from pydantic import (
AnyUrl,
Expand All @@ -23,7 +22,6 @@
from fideslang.validation import (
FidesKey,
FidesVersion,
check_valid_country_code,
deprecated_version_later_than_added,
has_versioning_if_default,
is_deprecated_if_replaced,
Expand All @@ -35,10 +33,6 @@
valid_data_type,
)

# Reusable Validators
country_code_validator = validator("third_country_transfers", allow_reuse=True)(
check_valid_country_code
)
matching_parent_key_validator = validator("parent_key", allow_reuse=True, always=True)(
matching_parent_key
)
Expand Down Expand Up @@ -188,19 +182,6 @@ class DataSubjectRightsEnum(str, Enum):
OBJECT_TO_AUTOMATED_PROCESSING = "Object to Automated Processing"


class LegalBasisEnum(str, Enum):
"""
Deprecated. The model for allowable legal basis categories on data uses.
"""

CONSENT = "Consent"
CONTRACT = "Contract"
LEGAL_OBLIGATION = "Legal Obligation"
VITAL_INTEREST = "Vital Interest"
PUBLIC_INTEREST = "Public Interest"
LEGITIMATE_INTEREST = "Legitimate Interests"


class LegalBasisForProcessingEnum(str, Enum):
"""
The model for allowable legal basis categories on privacy declarations.
Expand Down Expand Up @@ -240,21 +221,6 @@ class LegalBasisForTransfersEnum(str, Enum):
OTHER = "Other"


class SpecialCategoriesEnum(str, Enum):
"""
Deprecated. Special Categories Enum that was used on Data Uses.
"""

CONSENT = "Consent"
EMPLOYMENT = "Employment"
VITAL_INTEREST = "Vital Interests"
NON_PROFIT_BODIES = "Non-profit Bodies"
PUBLIC_BY_DATA_SUBJECT = "Public by Data Subject"
LEGAL_CLAIMS = "Legal Claims"
PUBLIC_INTEREST = "Substantial Public Interest"
MEDICAL = "Medical"
PUBLIC_HEALTH_INTEREST = "Public Health Interest"


class SpecialCategoryLegalBasisEnum(str, Enum):
"""
Expand Down Expand Up @@ -343,67 +309,9 @@ class DataUse(FidesModel, DefaultModel):
"""The DataUse resource model."""

parent_key: Optional[FidesKey] = None
legal_basis: Optional[LegalBasisEnum] = Field(
description="Deprecated. The legal basis category of which the data use falls under. This field is used as part of the creation of an exportable data map.",
)
special_category: Optional[SpecialCategoriesEnum] = Field(
description="Deprecated. The special category for processing of which the data use falls under. This field is used as part of the creation of an exportable data map.",
)
recipients: Optional[List[str]] = Field(
description="Deprecated. An array of recipients when sharing personal data outside of your organization.",
)
legitimate_interest: Optional[bool] = Field(
description="Deprecated. A boolean representation of if the legal basis used is `Legitimate Interest`. Validated at run time and looks for a `legitimate_interest_impact_assessment` to exist if true.",
)
legitimate_interest_impact_assessment: Optional[AnyUrl] = Field(
description="Deprecated. A url pointing to the legitimate interest impact assessment. Required if the legal bases used is legitimate interest.",
)

_matching_parent_key: classmethod = matching_parent_key_validator
_no_self_reference: classmethod = no_self_reference_validator

@root_validator
@classmethod
def deprecate_fields(cls, values: Dict) -> Dict:
"""
Warn of Data Use fields pending deprecation.
"""
deprecated_fields = [
"legal_basis",
"recipients",
"special_category",
"legitimate_interest",
"legitimate_interest_impact_assessment",
]
for field in deprecated_fields:
if values.get(field) is not None:
warn(
f"The {field} field is deprecated, and will be removed in a future version of fideslang.",
DeprecationWarning,
)
return values

@validator("legitimate_interest", always=True)
@classmethod
def set_legitimate_interest(cls, value: bool, values: Dict) -> bool:
"""Sets if a legitimate interest is used."""
if values["legal_basis"] == "Legitimate Interests":
value = True
return value

@validator("legitimate_interest_impact_assessment", always=True)
@classmethod
def ensure_impact_assessment(cls, value: AnyUrl, values: Dict) -> AnyUrl:
"""
Validates an impact assessment is applied if a
legitimate interest has been defined.
"""
if values["legitimate_interest"]:
assert (
value is not None
), "Impact assessment cannot be null for a legitimate interest, please provide a valid url"
return value


# Dataset
class DatasetFieldBase(BaseModel):
Expand Down Expand Up @@ -673,47 +581,17 @@ class Dataset(FidesModel, FidesopsMetaBackwardsCompat):
fides_meta: Optional[DatasetMetadata] = Field(
description=DatasetMetadata.__doc__, default=None
)
joint_controller: Optional[ContactDetails] = Field(
description="Deprecated. " + ContactDetails.__doc__,
)
retention: Optional[str] = Field(
description="Deprecated. An optional string to describe the retention policy for a dataset. This field can also be applied more granularly at either the Collection or field level of a Dataset.",
)
third_country_transfers: Optional[List[str]] = Field(
description="Deprecated. An optional array to identify any third countries where data is transited to. For consistency purposes, these fields are required to follow the Alpha-3 code set in [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3).",
)
collections: List[DatasetCollection] = Field(
description="An array of objects that describe the Dataset's collections.",
)

_sort_collections: classmethod = validator("collections", allow_reuse=True)(
sort_list_objects_by_name
)
_check_valid_country_code: classmethod = country_code_validator
_unique_items_in_list: classmethod = validator("collections", allow_reuse=True)(
unique_items_in_list
)

@root_validator
@classmethod
def deprecate_fields(cls, values: Dict) -> Dict:
"""
Warn of Dataset fields pending deprecation.
"""
# TODO: Do we want to remove these for Fideslang 3?
deprecated_fields = [
"joint_controller",
"retention",
"third_country_transfers",
]
for field in deprecated_fields:
if values.get(field) is not None:
warn(
f"The {field} field is deprecated, and will be removed in a future version of fideslang.",
DeprecationWarning,
)
return values


# Evaluation
class ViolationAttributes(BaseModel):
Expand Down Expand Up @@ -1094,9 +972,6 @@ class System(FidesModel):
system_type: str = Field(
description="A required value to describe the type of system being modeled, examples include: Service, Application, Third Party, etc.",
)
data_responsibility_title: Optional[DataResponsibilityTitle] = Field(
description="Deprecated. The responsibility or role over the system that processes personal data",
)
egress: Optional[List[DataFlow]] = Field(
description="The resources to which the system sends data."
)
Expand All @@ -1106,19 +981,10 @@ class System(FidesModel):
privacy_declarations: List[PrivacyDeclaration] = Field(
description=PrivacyDeclaration.__doc__,
)
joint_controller: Optional[ContactDetails] = Field(
description="Deprecated. " + ContactDetails.__doc__,
)
third_country_transfers: Optional[List[str]] = Field(
description="Deprecated. An optional array to identify any third countries where data is transited to. For consistency purposes, these fields are required to follow the Alpha-3 code set in ISO 3166-1.",
)
administrating_department: Optional[str] = Field(
default="Not defined",
description="An optional value to identify the owning department or group of the system within your organization",
)
data_protection_impact_assessment: Optional[DataProtectionImpactAssessment] = Field(
description="Deprecated. " + DataProtectionImpactAssessment.__doc__,
)
vendor_id: Optional[str] = Field(
description="The unique identifier for the vendor that's associated with this system."
)
Expand Down Expand Up @@ -1213,27 +1079,6 @@ class System(FidesModel):
"privacy_declarations", allow_reuse=True
)(sort_list_objects_by_name)

_check_valid_country_code: classmethod = country_code_validator

@root_validator
@classmethod
def deprecate_fields(cls, values: Dict) -> Dict:
"""
Warn of System fields pending deprecation.
"""
deprecated_fields = [
"joint_controller",
"third_country_transfers",
"data_responsibility_title",
"data_protection_impact_assessment",
]
for field in deprecated_fields:
if values.get(field) is not None:
warn(
f"The {field} field is deprecated, and will be removed in a future version of fideslang.",
DeprecationWarning,
)
return values

@validator("privacy_declarations", each_item=True)
@classmethod
Expand Down
18 changes: 0 additions & 18 deletions src/fideslang/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from packaging.version import Version
from pydantic import ConstrainedStr

from fideslang.default_fixtures import COUNTRY_CODES

VALID_COUNTRY_CODES = [country["alpha3Code"] for country in COUNTRY_CODES]


class FidesValidationError(ValueError):
"""Custom exception for when the pydantic ValidationError can't be used."""
Expand Down Expand Up @@ -174,20 +170,6 @@ def matching_parent_key(parent_key: FidesKey, values: Dict) -> FidesKey:
return parent_key


def check_valid_country_code(country_code_list: List) -> List:
"""
Validate all listed countries (if present) are valid country codes.
"""
if country_code_list is not None:
for country_code in country_code_list:
if country_code not in VALID_COUNTRY_CODES:
raise FidesValidationError(
"The country identified as {} is not a valid Alpha-3 code per ISO 3166.".format(
country_code
)
)
return country_code_list


def parse_data_type_string(type_string: Optional[str]) -> Tuple[Optional[str], bool]:
"""Parse the data type string. Arrays are expressed in the form 'type[]'.
Expand Down
71 changes: 1 addition & 70 deletions tests/fideslang/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pytest import deprecated_call, mark, raises
from pytest import mark, raises

from fideslang import DataFlow, Dataset, Organization, PrivacyDeclaration, System
from fideslang.models import (
Expand Down Expand Up @@ -423,44 +423,6 @@ def test_flexible_legal_basis_default(self):
)
assert pd.flexible_legal_basis_for_processing

@mark.parametrize(
"deprecated_field,value",
[
("data_responsibility_title", "Controller"),
(
"joint_controller",
{
"name": "Jane Doe",
"address": "104 Test Lane; Test Town, TX, 32522",
"email": "jane@example.com",
"phone": "345-255-2555",
},
),
("third_country_transfers", ["GBR"]),
(
"data_protection_impact_assessment",
{
"is_required": True,
"progress": "pending",
"link": "https://www.example.com/dpia",
},
),
],
)
def test_system_deprecated_fields(self, deprecated_field, value) -> None:
with deprecated_call(match=deprecated_field):
assert System(
**{
"description": "Test System",
"fides_key": "test_system",
"name": "Test System",
"registry": 1,
"system_type": "SYSTEM",
"privacy_declarations": [],
deprecated_field: value,
}
)


class TestDataset:
def test_valid_dataset(self):
Expand Down Expand Up @@ -522,24 +484,6 @@ def test_valid_dataset(self):
],
)

@mark.parametrize(
"deprecated_field,value",
[
("joint_controller", {"name": "Controller_name"}),
("retention", "90 days"),
("third_country_transfers", ["IRL"]),
],
)
def test_dataset_deprecated_fields(self, deprecated_field, value) -> None:
with deprecated_call(match=deprecated_field):
assert Dataset(
**{
"fides_key": "test_dataset",
"collections": [],
deprecated_field: value,
}
)

def test_dataset_collection_skip_processing(self):
collection = DatasetCollection(
name="dataset_collection_1",
Expand Down Expand Up @@ -571,16 +515,3 @@ class TestDataUse:
def test_minimal_data_use(self):
assert DataUse(fides_key="new_use")

@mark.parametrize(
"deprecated_field,value",
[
("legal_basis", "Legal Obligation"),
("special_category", "Substantial Public Interest"),
("recipients", ["Advertising Bureau"]),
("legitimate_interest", False),
("legitimate_interest_impact_assessment", "https://www.example.com"),
],
)
def test_datause_deprecated_fields(self, deprecated_field, value) -> None:
with deprecated_call(match=deprecated_field):
assert DataUse(**{"fides_key": "new_use", deprecated_field: value})
Loading

0 comments on commit 799bb1b

Please sign in to comment.