Team-Tea-Time / laravel-forum

A slim, lean forum package designed for quick and easy integration in Laravel projects
https://laravel-forum.teamteatime.net/
MIT License
601 stars 165 forks source link

Policy / permission error #179

Closed richlove1 closed 6 years ago

richlove1 commented 7 years ago

https://github.com/Riari/laravel-forum/blob/4.0/src/Policies/PostPolicy.php#L29

Hi not sure if this is OK to post here. Basically I get peculiar behaviour in one of the policy check functions. I'm logged in as a user with only one defined role attached of 'Authenticated User'.

However in viewTrashedThreads($user) if I dump out the result of $roles = $user->roles()->pluck('name'); it shows me all available roles for a user model not the assigned role for the user instance.

All other policy checks return only the roles defined for the current user instance (not all available roles for a user model).

Really fantastic work by the way on the forums, it's a great starter tool for a forum implementation in Laravel.

Riari commented 7 years ago

That is very odd, but I'm pretty sure there's nothing in the package that should (or even could) interfere with your user model like that, especially as ->roles() is in Eloquent territory. It might be worth dumping a stack trace to get an idea of what may be interfering with it.

richlove1 commented 7 years ago

Thanks for the reply. I can't figure out exactly what's going on but there's something different happening causing the issue when viewing the overall forum index page. If you go in to a category index page you get the correct user role back.

I've done a couple of screenshots of each situation. On the main index page you can see that the initial call to the user roles brings back all roles available for the user model. It looks like the entry point and calls to functions in the CategoryController is different in each case, hopefully you can see a bit of the stack trace from this on the screenshots.

screenshot 2017-08-02 10 22 19 screenshot 2017-08-02 10 22 11

Riari commented 6 years ago

Going to close this as I haven't seen the issue show up anywhere since. Feel free to open a new issue if it's still relevant.

VyacheslavVV commented 5 years ago

It is the same for me. The one solution I found is to reload relations: $user->load('roles')

but it would be nice to fix it, though I don`t know if this is related to the forum.

Gummibeer commented 5 years ago

The second screenshot query is the issue. It doesn't has a where so it loads all role names which have at least one occurrence in the model_has_role table. But if I take a look in ForumPolicy::L69 there is no DB call!? There is just a simple return true. 🤔