Laravel-Backpack / activity-log

MIT License
29 stars 7 forks source link

Inferring the Causer of an Activity #17

Closed promatik closed 1 year ago

promatik commented 1 year ago

If we assume that all activity caused by a backpack user is inside backpack admin namespace (crud interface) we could add it in a middleware that checks if the route starts by backpack route prefix.

A middleware seems like something that would be too large of a scope. It would run on all requests, whether it's needed or not. But the idea with the route prefix... THAT I like...

What if we create an Observer for Activity? We can register one in our package's service provider, even if Activity is in the Spatie package. That way... when an activity is created (and only then)... we do some checks.

One way of checking would be:

  • if route is backpack, use the guard configured in Backpack's config
  • else use the guard configured in spatie config

That's if we don't have a way to get the currently-active guard... which... we should, right? Laravel should have a getGuard() on the AuthManager or something... right?

_Originally posted by @tabacitu in https://github.com/Laravel-Backpack/activity-log/pull/8#discussion_r1310410449_

tabacitu commented 1 year ago

https://laravel.com/api/10.x/Illuminate/Auth/AuthManager.html#method_guard

promatik commented 1 year ago

Fixed here; 8d4fc52 (#8) 🎉