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

Track consent revoked by and display it on the file card #4857

Merged
merged 6 commits into from
Oct 25, 2024

Conversation

dtgreiner
Copy link
Contributor

@dtgreiner dtgreiner commented Oct 23, 2024

Merging this PR

  • use the squash-merge strategy for PRs targeting a release-X branch
  • use a merge-commit or rebase strategy for PRs targeting the stable branch

Description

Track consent revoked by and display the data on the file card the file has been revoked.

Type of change

New feature

Checklist before requesting review

  • I have performed a self-review of my code
  • I have run the code that is being changed under ideal conditions, and it doesn't fail
  • If adding a new endpoint / exposing data in a new way, I have:
    • ensured the API can't leak data from other data sources
    • ensured this does not introduce N+1s
    • ensured permissions and visibility checks are performed in the right places
  • I have updated the documentation (or not applicable)
  • I have added spec tests (or not applicable)
  • I have provided testing instructions in this PR or the related issue (or not applicable)

@dtgreiner dtgreiner requested a review from eanders October 23, 2024 15:17
@@ -249,6 +252,11 @@ def batch_params
params.require(:batch_download).permit(:file_ids)
end

def set_user
# binding.pry
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# binding.pry

after_save :note_changes_in_consent, if: ->(m) { m.should_run_callbacks? }
after_commit :set_client_consent, on: [:create, :update], if: ->(m) { m.should_run_callbacks? }
after_create_commit :notify_users, if: ->(m) { m.should_run_callbacks? } # rubocop:disable Style/SymbolProc
before_update :adjust_revoked_by, if: ->(m) { m.should_run_callbacks? && consent_revoked_at_changed? }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some reason we can't just call this from the controller? There are a bunch of callbacks, but the controller should know the user that made the change, so should be able to set consent_revoked_by_user_id: current_user.id when creating or updating the record. (There is significant complexity here, so I may be missing something.)

While we're in here, it might be worth adding has_paper_trail. I was going to suggest we pull the user out of the versions table, but it appears these aren't being logged.

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 was mentioned in the ticket that this may be a good way to go. At the time, it felt like capturing it at a deeper level may good if we are working with files in multiple controllers, but I see what you are saying and it does feel less complex to just have the controller handle it. I'll adjust the PR.

Copy link
Contributor

@eanders eanders left a comment

Choose a reason for hiding this comment

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

Happy to discuss if you already looked at these ideas, but dropped a few questions inline.

@dtgreiner
Copy link
Contributor Author

dtgreiner commented Oct 25, 2024

@eanders I just pushed an update to pull the logic out of the callbacks and into the controllers. It should be good for another look whenever you have the chance. Thanks!

Edit - missed adding paper_trail here. Working on that now.

Comment on lines 111 to 112
revoked_by_id = current_user.id if @file.consent_revoked_at.present?
@file.consent_revoked_by_user_id = revoked_by_id if @file.consent_revoked_at_changed?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
revoked_by_id = current_user.id if @file.consent_revoked_at.present?
@file.consent_revoked_by_user_id = revoked_by_id if @file.consent_revoked_at_changed?
if @file.consent_revoked_at_changed?
@file.consent_revoked_by_user_id = if @file.consent_revoked_at.present?
current_user.id
else
nil
end
end

Copy link
Contributor

Choose a reason for hiding this comment

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

The above can go in a method on ClientFile so you can call @file.set_revocation_info(current_user)

@@ -230,6 +233,7 @@ def file_params
:effective_date,
:expiration_date,
:consent_revoked_at,
:consent_revoked_by_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think you need this since we aren't passing it as a parameter.

Copy link
Contributor

@eanders eanders left a comment

Choose a reason for hiding this comment

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

Thanks @dtgreiner, this is way cleaner.

@eanders eanders merged commit 7247110 into release-139 Oct 25, 2024
11 of 12 checks passed
@eanders eanders deleted the dg/file_consent_revoked_by-6422 branch October 25, 2024 20:44
@@ -7,6 +7,7 @@
module GrdaWarehouse
class File < GrdaWarehouseBase
acts_as_paranoid
has_paper_trail
Copy link
Contributor

@gigxz gigxz Oct 29, 2024

Choose a reason for hiding this comment

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

This caused a test regression on HMIS, because duplicate versions are being created for HMIS files. https://github.com/greenriver/hmis-warehouse/actions/runs/11525170831/job/32086897713

The problem is that Hmis::File also calls has_paper_trail (and attaches some metadata).

Paper Trail has an unreleased (breaking) change that will actually cause this to fail https://github.com/paper-trail-gem/paper_trail/blob/master/CHANGELOG.md#breaking-changes / paper-trail-gem/paper_trail#1479. They acknowledge that this can create duplicates. Glad we caught it with the test first!

I don't have much context on this PR, so not sure what the best course of action is. This class is pretty lightweight, so one approach is for Hmis::File to just not subclass it. I did that here #4872 and the tests pass, but it needed some weirdness to get type set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch @gigxz ! I believe our intent was actually to add has_paper_trail to ClientFile. Not sure we need it in the base class. I'll give that a try and see if tests still fail.

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.

3 participants