-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for consent management report (#4452)
- Loading branch information
Showing
7 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/fides/api/alembic/migrations/versions/7f7c2b098f5d_add_name_index_to_ctl_systems.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""add indexes to ctl_systems and privacydeclaration | ||
Revision ID: 7f7c2b098f5d | ||
Revises: 1af6950f4625 | ||
Create Date: 2023-11-21 18:52:34.508076 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "7f7c2b098f5d" | ||
down_revision = "1af6950f4625" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm;") | ||
op.create_index( | ||
"ix_ctl_systems_name", | ||
"ctl_systems", | ||
[sa.text("name gin_trgm_ops")], | ||
postgresql_using="gin", | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_index("ix_ctl_systems_name", table_name="ctl_systems") | ||
op.execute("DROP EXTENSION IF EXISTS pg_trgm;") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from fastapi import Depends, Security | ||
from fideslang.gvl import MAPPED_PURPOSES, MAPPED_SPECIAL_PURPOSES | ||
from sqlalchemy.orm import Session | ||
from starlette.status import HTTP_200_OK | ||
|
||
from fides.api.api import deps | ||
from fides.api.oauth.utils import verify_oauth_client | ||
from fides.api.schemas.tcf import PurposesResponse | ||
from fides.api.util.api_router import APIRouter | ||
from fides.common.api.v1 import urn_registry as urls | ||
|
||
router = APIRouter(tags=["Purposes"], prefix=urls.V1_URL_PREFIX) | ||
|
||
|
||
@router.get( | ||
"/purposes", | ||
dependencies=[Security(verify_oauth_client)], | ||
status_code=HTTP_200_OK, | ||
response_model=PurposesResponse, | ||
) | ||
def get_purposes( | ||
db: Session = Depends(deps.get_db), | ||
) -> PurposesResponse: | ||
""" | ||
Return a map of purpose and special purpose IDs to mapped purposes which include data uses. | ||
""" | ||
|
||
purposes = {} | ||
special_purposes = {} | ||
for purpose in MAPPED_PURPOSES.values(): | ||
purposes[purpose.id] = purpose | ||
for special_purpose in MAPPED_SPECIAL_PURPOSES.values(): | ||
special_purposes[special_purpose.id] = special_purpose | ||
return PurposesResponse(purposes=purposes, special_purposes=special_purposes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from starlette.status import HTTP_200_OK, HTTP_401_UNAUTHORIZED | ||
|
||
from fides.common.api.v1.urn_registry import PURPOSES, V1_URL_PREFIX | ||
|
||
|
||
class TestGetPurposes: | ||
@pytest.fixture(scope="function") | ||
def url(self) -> str: | ||
return V1_URL_PREFIX + PURPOSES | ||
|
||
def test_get_purposes_unauthenticated(self, url, api_client): | ||
response = api_client.get(url) | ||
assert response.status_code == HTTP_401_UNAUTHORIZED | ||
|
||
def test_get_purposes(self, url, api_client, generate_auth_header): | ||
auth_header = generate_auth_header([]) | ||
response = api_client.get(url, headers=auth_header) | ||
assert response.status_code == HTTP_200_OK | ||
|
||
data = response.json() | ||
assert "purposes" in data | ||
assert "special_purposes" in data | ||
assert len(data["purposes"]) == 11 | ||
assert len(data["special_purposes"]) == 2 |