Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning GVL.JSON through Experiences API #4143

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
get_fides_user_device_id_provided_identity,
)
from fides.api.util.endpoint_utils import fides_limiter, transform_fields
from fides.api.util.tcf_util import TCF_COMPONENT_MAPPING, TCFExperienceContents
from fides.api.util.tcf_util import (
TCF_COMPONENT_MAPPING,
TCFExperienceContents,
load_gvl,
)
from fides.common.api.v1 import urn_registry as urls
from fides.config import CONFIG

Expand Down Expand Up @@ -264,6 +268,9 @@ def embed_experience_details(
has_tcf_contents: bool = any(
getattr(tcf_contents, component) for component in TCF_COMPONENT_MAPPING
)
if has_tcf_contents:
privacy_experience.gvl = load_gvl()
pattisdr marked this conversation as resolved.
Show resolved Hide resolved

# Add fetched TCF contents to the Privacy Experience if applicable
for component in TCF_COMPONENT_MAPPING:
setattr(privacy_experience, component, getattr(tcf_contents, component))
Expand Down
1 change: 1 addition & 0 deletions src/fides/api/models/privacy_experience.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class PrivacyExperience(Base):
tcf_features: List = []
tcf_special_features: List = []
tcf_systems: List = []
gvl: Optional[Dict] = {}

# Attribute that is cached on the PrivacyExperience object by "get_should_show_banner", calculated at runtime
show_banner: bool
Expand Down
1 change: 1 addition & 0 deletions src/fides/api/schemas/privacy_experience.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,4 @@ class PrivacyExperienceResponse(PrivacyExperienceWithId):
experience_config: Optional[ExperienceConfigResponse] = Field(
description="The Experience copy or language"
)
gvl: Optional[Dict] = None
25 changes: 25 additions & 0 deletions src/fides/api/util/tcf_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from enum import Enum
from os.path import dirname, join
from typing import Callable, Dict, List, Optional, Set, Tuple, Type, Union

from fideslang.gvl import (
Expand All @@ -14,6 +16,7 @@
from fideslang.gvl.models import Feature, Purpose
from fideslang.models import LegalBasisForProcessingEnum
from fideslang.validation import FidesKey
from loguru import logger
from sqlalchemy.engine.row import Row # type:ignore[import]
from sqlalchemy.orm import Query, Session

Expand All @@ -27,6 +30,16 @@
TCFPurposeRecord,
TCFVendorRecord,
)
from fides.config.helpers import load_file

_gvl: Optional[Dict] = None

GVL_PATH = join(
dirname(__file__),
"../../data",
"gvl.json",
allisonking marked this conversation as resolved.
Show resolved Hide resolved
)


TCFPurposeOrFeature = Union[TCFPurposeRecord, TCFFeatureRecord]

Expand Down Expand Up @@ -614,3 +627,15 @@ def systems_that_match_system_id(
)
}
)


def load_gvl() -> Dict:
global _gvl # pylint: disable=W0603
if _gvl is None:
with open(load_file([GVL_PATH]), "r", encoding="utf-8") as file:
logger.info("Loading GVL from file")
_gvl = json.load(file)
return _gvl

logger.info("Loading GVL from memory")
return _gvl
Loading
Loading