django-unfold icon indicating copy to clipboard operation
django-unfold copied to clipboard

The sidebar navigation link callback gets called once, and the request probably gets cached

Open summerthe opened this issue 10 months ago • 0 comments

Hi @lukasvinclav this issue is related to #300 where the request was getting cached.

I have a link callback in the sidebar navigation. The URL path of it changes based on the type of user. But there are possibly two problems:

def reverse_callback(request):
    print("request.user.is_superuser",request.user.is_superuser)
    if request.user.is_superuser:
        return reverse_lazy("admin:formula_driver_changelist")
    else:
        return reverse_lazy("admin:auth_group_changelist")

--------
{
 "title": _("Drivers"),
 "icon": "sports_motorsports",
 "link": reverse_callback,
}
  • The callback gets called only once after the user logs into the platform. The callback doesn't get called for further requests. Hence the url path doesn't change based on the callback.
  • It is possible the request might be getting cached as well. I couldn't test if the request is getting cached or not because the callback doesn't run the second time ever.

I have reproduced this issue in Formula Fork with latest unfold version 0.22. Check here https://github.com/summerthe/formula/commit/b23d552a3e1d17068aef6bbc105413f682950d43

As a fix, for the superadmin, the callback should return the driver's URL with a print in the terminal. For the staff user group url and print in the terminal on each request.

summerthe avatar Apr 17 '24 12:04 summerthe