Skip to content

Fix disable auditing before model initialization #758

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

Merged
merged 1 commit into from
Mar 10, 2023
Merged

Fix disable auditing before model initialization #758

merged 1 commit into from
Mar 10, 2023

Conversation

evgeek
Copy link
Contributor

@evgeek evgeek commented Jan 18, 2023

The Auditable::bootAuditable() trait loader on the model works only once, at the very first initialization of the class. Thus, at the moment, if auditing is disabled on the model during initialization, an observer will not be booted on the model, and a further call to Model::enableAudit() will not change anything - there is no observer, no events are registered.

The itDisablesAndEnablesAuditingBackAgain test skipped this behavior because the model was first initialized before auditing was disabled.

I suggest init observer on the model, regardless of the $auditingDisabled flag. I made the appropriate changes, and the itDisablesAndEnablesAuditingBackAgainViaFacade test, where auditing is disabled before initialization.

@anteriovieira
Copy link
Member

@parallels999 @erikn69 @MortenDHansen any comments here?

@erikn69
Copy link
Contributor

erikn69 commented Mar 10, 2023

Makes a lot of sense to me, this would only happen in this specific case, it makes me think that no one has ever used disableAuditing() in that way before.

So bootAuditable from Model A class is called once after disableAuditing() and after enableAuditing() the same Model A stops auditing because there is no observer

@anteriovieira anteriovieira merged commit b200968 into owen-it:master Mar 10, 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.

3 participants