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

Incorrect user associated with audit when changing users dynamically #953

Closed
dariusvelavicius opened this issue Jul 2, 2024 · 3 comments

Comments

@dariusvelavicius
Copy link

PHP Version

8.1

Laravel Version

8.x

Package Version

13.6.8

Description

Hello guys,

When changing user on-the-fly and performing a few changes on the same model, all audits have the same associated user because of this change - 66498a9#diff-682a5b02fc6acf79eda6201541882897f0f0a3fca0d35f02e3398021fd77c63eR368-R372

Is there a reason why the user is always preloaded? Can we discuss an approach where it would be possible to control when the user should be preloaded and when it should be re-resolved?

Steps To Reproduce

  • Set up Auditable for any model
  • On the same request:
    • Update the model
    • Dynamically change the user (Auth::setUser())
    • Update the model some more

Possible Solutions

No response

@erikn69
Copy link
Contributor

erikn69 commented Jul 2, 2024

because of this change - 66498a9#diff-682a5b02fc6acf79eda6201541882897f0f0a3fca0d35f02e3398021fd77c63eR368-R372

Is there a reason why the user is always preloaded?

You could ask the author of that change, maybe he will give you an answer.
You could also clear that variable to return to the old functionality.

Can we discuss an approach where it would be possible to control when the user should be preloaded and when it should be re-resolved?

Feel free to open a PR for that feature

@erikn69 erikn69 closed this as completed Jul 2, 2024
@parallels999
Copy link
Contributor

Dynamically change the user (Auth::setUser())

Why??
Are you doing some type of impersonalization? like 404labfr/laravel-impersonate

@willpower232
Copy link
Contributor

If you have multiple users within a single request to your code doing auditable activity as well as changing users, it would probably be easier to make use of transformAudit rather than rely on observers which won't match your particular use case

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

No branches or pull requests

4 participants