bullet-train-co / bullet_train-core

The Open Source Ruby on Rails SaaS Framework
35 stars 42 forks source link

Setting abilities based on user.current_team introduces bugs for multiple browser windows opened on different teams #916

Open pascallaliberte opened 3 days ago

pascallaliberte commented 3 days ago

Scenario to reproduce

Expected result

Reloading each page should show only the resources boxes allowed

Actual result

Reloading each page shows the wrong resource boxes, as if the <% if can? :read... %> blocks don't work properly

Possible source of the bug

I think the source of the bug is that on each request, Ability.new(user) is called before current_team is set to the team of the page's context. The can? helper will make its determination based on the current_team stored in the latest page request, and not the current page request.

https://github.com/bullet-train-co/bullet_train-core/blob/397cb8111b4af97afe979be0dba982c3250ee9a1/bullet_train/app/models/concerns/current_attributes/base.rb#L12-L24

pascallaliberte commented 3 days ago

There's probably a way to not rely on current_team in ability.rb at all that I should know about, or a way that relies on current_team evaluation at run-time, like smarter role definitions or something.