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

Changes to support bidirectional consent #5118

Merged
merged 17 commits into from
Jul 31, 2024

Conversation

galvana
Copy link
Contributor

@galvana galvana commented Jul 22, 2024

Closes PROD-2343

Description Of Changes

Core changes to support the PUT and GET /consentable-items endpoints in Fidesplus.

Code Changes

  • Migration script to add the plus_consent_automation and plus_consentable_item tables
  • Adding new SaaSRequestTypes to support new bidirectional consent actions (get_consentable_items, update_consent, process_consent_webhook)

Steps to Confirm

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Documentation:
    • documentation complete, PR opened in fidesdocs
    • documentation issue created in fidesdocs
    • if there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
  • Issue Requirements are Met
  • Update CHANGELOG.md
  • For API changes, the Postman collection has been updated
  • If there are any database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!

Copy link

vercel bot commented Jul 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fides-plus-nightly ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2024 4:44pm

Copy link

cypress bot commented Jul 22, 2024



Test summary

4 0 0 0


Run details

Project fides
Status Passed
Commit ec44f723f2 ℹ️
Started Jul 31, 2024 4:53 PM
Ended Jul 31, 2024 4:54 PM
Duration 00:35 💡
OS Linux Ubuntu -
Browser Electron 106

View run in Cypress Cloud ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 82.31293% with 26 lines in your changes missing coverage. Please review.

Project coverage is 86.52%. Comparing base (c3eae69) to head (622f8d8).

Files Patch % Lines
...vice/saas_request/saas_request_override_factory.py 52.63% 6 Missing and 3 partials ⚠️
src/fides/api/service/connectors/saas_connector.py 42.85% 5 Missing and 3 partials ⚠️
src/fides/api/schemas/consentable_item.py 86.48% 3 Missing and 2 partials ⚠️
src/fides/api/models/consent_automation.py 94.36% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5118      +/-   ##
==========================================
- Coverage   86.55%   86.52%   -0.03%     
==========================================
  Files         357      359       +2     
  Lines       22340    22470     +130     
  Branches     2957     2978      +21     
==========================================
+ Hits        19336    19443     +107     
- Misses       2480     2494      +14     
- Partials      524      533       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@galvana galvana requested a review from eastandwestwind July 28, 2024 00:24
@galvana galvana marked this pull request as ready for review July 28, 2024 00:24
Copy link
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a very clean implementation @galvana , well done! Overall the functionality works as expected, but just a couple items to clarify and some additional tests for some of the DB functionality. Thanks!

["privacynotice.id"],
),
sa.ForeignKeyConstraint(
["parent_id"], ["plus_consentable_item.id"], ondelete="CASCADE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this cascade functionality, too?

sa.ForeignKeyConstraint(
["consent_automation_id"],
["plus_consent_automation.id"],
ondelete="CASCADE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this cascade functionality?

notice_id=item_data.get("notice_id"),
)
db.add(item)
# flush to the DB so we can get the auto-generated ID for this item
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain how flush works? I haven't had to use this manually before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flush() lets you push changes to the database without committing the transaction. In this case, we just called db.add(item) to add a new ConsentableItem to this current DB session, but if we want to get the ID for that new item, we can call flush() and this would be executed in the current transaction

2024-07-30 11:09:21 2024-07-30 18:09:21.081 UTC [148] LOG:  statement: INSERT INTO plus_consentable_item (id, consent_automation_id, external_id, parent_id, notice_id, type, name) VALUES ('plu_16815018-1e85-45f8-beb0-8c1a7998412f', 'plu_6f56003c-610e-4196-8e21-ed6815be9bc8', '1', 'plu_fc600d19-7101-4db4-b148-1849c667fae3', NULL, 'Message type', 'Weekly Ads')

So it's enough for us to get an ID without us having to commit the current transaction. If any exceptions occur during later in the code (after flush()), we can still roll everything back as if nothing happened.

parent: "RelationshipProperty[Optional[ConsentableItem]]" = relationship(
"ConsentableItem",
back_populates="children",
remote_side=[id],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is remote_side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed for self-referential relationships like what we're doing here with ConsentableItem. There's an in-depth explanation here but the way I was able to reason about it was that it's telling SQLAlchemy which side of the relationship is the "parent" or "one" side of a one-to-many relationship. As an example, one ConsentableItem can have an id of 1, but many ConsentableItems can have their parent_id be 1, so id would be the "remote_side".

@galvana galvana requested a review from eastandwestwind July 30, 2024 22:29
.filter(ConsentableItem.consent_automation_id == consent_automation.id)
.all()
)
assert len(consentable_items) == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!

Copy link
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding those tests @galvana !

@eastandwestwind
Copy link
Contributor

Oh, and can we add a CHANGELOG entry here too?

@galvana galvana merged commit 681b39c into main Jul 31, 2024
45 of 47 checks passed
@galvana galvana deleted the PROD-2343-changes-to-support-bidirectional-consent branch July 31, 2024 17:29
Copy link

cypress bot commented Jul 31, 2024



Test summary

4 0 0 0


Run details

Project fides
Status Passed
Commit 681b39c
Started Jul 31, 2024 5:41 PM
Ended Jul 31, 2024 5:42 PM
Duration 00:35 💡
OS Linux Ubuntu -
Browser Electron 106

View run in Cypress Cloud ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants