Skip to content

Commit

Permalink
Adding query param key to Privacy Center config
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed May 30, 2024
1 parent 06d373c commit ad9a975
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/fides/api/schemas/privacy_center_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ class CustomPrivacyRequestField(FidesSchema):
required: Optional[bool] = True
default_value: Optional[str] = None
hidden: Optional[bool] = False
query_param_key: Optional[str] = None

@root_validator
def validate_default_value(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values.get("hidden") and values.get("default_value") is None:
raise ValueError("default_value is required when hidden is True")
if (
values.get("hidden")
and values.get("default_value") is None
and values.get("query_param_key") is None
):
raise ValueError(
"default_value or query_param_key are required when hidden is True"
)
return values


Expand Down
10 changes: 9 additions & 1 deletion tests/ops/schemas/test_privacy_center_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ def privacy_center_config(self) -> PrivacyCenterConfig:
def test_valid_custom_privacy_request_field(self):
CustomPrivacyRequestField(label="Tenant ID", default_value="123", hidden=True)

def test_valid_custom_privacy_request_field_with_query_param(self):
CustomPrivacyRequestField(
label="Tenant ID", query_param_key="site_id", hidden=True
)

def test_custom_privacy_request_field_with_missing_default_value(self):
with pytest.raises(ValidationError) as exc:
CustomPrivacyRequestField(label="Tenant ID", hidden=True)
assert "default_value is required when hidden is True" in str(exc.value)
assert (
"default_value or query_param_key are required when hidden is True"
in str(exc.value)
)

def test_custom_privacy_request_fields_with_missing_values(self):
with pytest.raises(ValidationError):
Expand Down

0 comments on commit ad9a975

Please sign in to comment.