This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Paul Sanders <[email protected]>
- Loading branch information
Paul Sanders
and
Paul Sanders
authored
Sep 14, 2022
1 parent
87ceea3
commit aa9fdbf
Showing
7 changed files
with
122 additions
and
8 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
66 changes: 66 additions & 0 deletions
66
src/fidesops/ops/migrations/versions/a0e6feb5bdc8_add_consent.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,66 @@ | ||
"""Add consent | ||
Revision ID: a0e6feb5bdc8 | ||
Revises: 7a4f4042091e | ||
Create Date: 2022-09-12 14:46:05.443579 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a0e6feb5bdc8" | ||
down_revision = "7a4f4042091e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"consent", | ||
sa.Column("id", sa.String(length=255), nullable=False), | ||
sa.Column( | ||
"created_at", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=True, | ||
), | ||
sa.Column( | ||
"updated_at", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=True, | ||
), | ||
sa.Column("provided_identity_id", sa.String(), nullable=True), | ||
sa.Column("data_use", sa.String(), nullable=False), | ||
sa.Column("data_use_description", sa.String(), nullable=True), | ||
sa.Column("opt_in", sa.Boolean(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["provided_identity_id"], | ||
["providedidentity.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("data_use"), | ||
) | ||
op.create_index(op.f("ix_consent_id"), "consent", ["id"], unique=False) | ||
op.alter_column( | ||
"providedidentity", | ||
"privacy_request_id", | ||
existing_type=sa.VARCHAR(), | ||
nullable=True, | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column( | ||
"providedidentity", | ||
"privacy_request_id", | ||
existing_type=sa.VARCHAR(), | ||
nullable=False, | ||
) | ||
op.drop_index(op.f("ix_consent_id"), table_name="consent") | ||
op.drop_table("consent") | ||
# ### end Alembic commands ### |
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 |
---|---|---|
|
@@ -16,8 +16,10 @@ | |
from fidesops.ops.models.policy import CurrentStep, Policy | ||
from fidesops.ops.models.privacy_request import ( | ||
CheckpointActionRequired, | ||
Consent, | ||
PrivacyRequest, | ||
PrivacyRequestStatus, | ||
ProvidedIdentity, | ||
can_run_checkpoint, | ||
) | ||
from fidesops.ops.schemas.redis_cache import PrivacyRequestIdentity | ||
|
@@ -667,3 +669,35 @@ def test_can_run_if_no_saved_checkpoint(self): | |
) | ||
is True | ||
) | ||
|
||
|
||
def test_consent(db): | ||
provided_identity_data = { | ||
"privacy_request_id": None, | ||
"field_name": "email", | ||
"encrypted_value": {"value": "[email protected]"}, | ||
} | ||
provided_identity = ProvidedIdentity.create(db, data=provided_identity_data) | ||
|
||
consent_data_1 = { | ||
"provided_identity_id": provided_identity.id, | ||
"data_use": "user.biometric_health", | ||
"opt_in": True, | ||
} | ||
consent_1 = Consent.create(db, data=consent_data_1) | ||
|
||
consent_data_2 = { | ||
"provided_identity_id": provided_identity.id, | ||
"data_use": "user.browsing_history", | ||
"opt_in": False, | ||
} | ||
consent_2 = Consent.create(db, data=consent_data_2) | ||
data_uses = [x.data_use for x in provided_identity.consent] | ||
|
||
assert consent_data_1["data_use"] in data_uses | ||
assert consent_data_2["data_use"] in data_uses | ||
|
||
provided_identity.delete(db) | ||
|
||
assert Consent.get(db, object_id=consent_1.id) is None | ||
assert Consent.get(db, object_id=consent_2.id) is None |