-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from 1 commit
a876e08
3c6af91
80430d1
fc92fdb
1a42f89
1e977bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class ClientFile < GrdaWarehouse::File | |
belongs_to :vispdat, class_name: 'GrdaWarehouse::Vispdat::Base', optional: true | ||
belongs_to :enrollment, class_name: 'GrdaWarehouse::Hud::Enrollment', optional: true | ||
belongs_to :data_source, class_name: 'GrdaWarehouse::DataSource', optional: true | ||
belongs_to :consent_revoked_by_user, class_name: 'User', optional: true | ||
validates_inclusion_of :visible_in_window, in: [true, false] | ||
validates_presence_of :expiration_date, on: :requires_expiration_date, message: 'Expiration date is required' | ||
validates_presence_of :effective_date, on: :requires_effective_date, message: 'Effective date is required' | ||
|
@@ -233,15 +234,21 @@ class ClientFile < GrdaWarehouse::File | |
#################### | ||
# Callbacks | ||
#################### | ||
after_create_commit :notify_users, if: ->(m) { m.should_run_callbacks? } | ||
before_save :adjust_consent_date, if: ->(m) { m.should_run_callbacks? } | ||
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? } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 While we're in here, it might be worth adding There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
before_save :adjust_consent_date, if: ->(m) { m.should_run_callbacks? } # rubocop:disable Style/SymbolProc | ||
after_save :note_changes_in_consent, if: ->(m) { m.should_run_callbacks? } # rubocop:disable Style/SymbolProc | ||
after_commit :set_client_consent, on: [:create, :update], if: ->(m) { m.should_run_callbacks? } # rubocop:disable Style/SymbolProc | ||
|
||
def should_run_callbacks? | ||
callbacks_skipped.nil? || ! callbacks_skipped | ||
end | ||
|
||
def adjust_revoked_by | ||
revoked_by_id = user&.id if consent_revoked_at.present? | ||
self.consent_revoked_by_user_id = revoked_by_id | ||
end | ||
|
||
#################### | ||
# Access | ||
#################### | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddRevokedByToFile < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :files, :consent_revoked_by_user_id, :integer, null: true | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.