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

Don't double audit on touch for create / update actions #660

Conversation

mcyoung
Copy link
Contributor

@mcyoung mcyoung commented Feb 19, 2023

When introducing the touch audit, we overlooked touch on association (belongs_to :model, touch: true) and this PR resolves that. This comes up when a model has an association setup w/ a touch, which could possibly be behind the scenes like when it comes to ActiveStorage objects.

E.g. W/ a basic model setup

module Company < ApplicationRecord
  has_many :employees
end

module Employee < ApplicationRecord
  belongs_to :company, touch: true
end

If a company is created w/ an employee included...

company = Company.create!(name: "Company A", employees_attributes: [{ name: "Employee 1", hired_at: Time.zone.current }])

Before this update we would end up with a "create" and an "update" audit for the company where the "update" audit is essentially the same data as the "create" audit. This PR essentially scrubs out the attributes if they match the prior audit during a touch audit.

@mcyoung mcyoung changed the title Mcy/feature/audit only touchable touches Only audit touch on date, time, datetime columns and fix related touch Feb 19, 2023
@mcyoung mcyoung changed the title Only audit touch on date, time, datetime columns and fix related touch [WIP] Only audit touch on date, time, datetime columns and fix related touch Feb 19, 2023
@mcyoung mcyoung force-pushed the mcy/feature/audit-only-touchable-touches branch 3 times, most recently from 69d8f2b to 01a91f8 Compare February 21, 2023 04:51
Added specs


Handle for update/create


Remove unused
@mcyoung mcyoung force-pushed the mcy/feature/audit-only-touchable-touches branch from 01a91f8 to b773b4a Compare February 21, 2023 04:54
@mcyoung mcyoung changed the title [WIP] Only audit touch on date, time, datetime columns and fix related touch Don't double audit on touch for create / update actions Feb 21, 2023
@mcyoung mcyoung marked this pull request as ready for review February 21, 2023 04:59
@mcyoung mcyoung mentioned this pull request Feb 21, 2023
@mcyoung
Copy link
Contributor Author

mcyoung commented Feb 21, 2023

@danielmorrison Just wanted to alert you to this, as it might be worth getting in as a minor update 🤷🏼

@danielmorrison danielmorrison merged commit 443d5f2 into collectiveidea:main Feb 21, 2023
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