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

Badge not changing between super user and staff user. #300

Closed
summerthe opened this issue Feb 24, 2024 · 6 comments
Closed

Badge not changing between super user and staff user. #300

summerthe opened this issue Feb 24, 2024 · 6 comments

Comments

@summerthe
Copy link

summerthe commented Feb 24, 2024

I created a repository and recorded a video to demonstrate that badge values are not changing between users. The values only update when the server restarts and then get cached for the user.

Steps to reproduce:

  • Create a superuser and a staff user.
  • Log in with both users in two different browsers or windows.
  • Initially, the values will be the same for both users, depending on whoever logged in first.
  • Restart the server and refresh the staff user's window first.

Here is repo link: https://github.com/summerthe/unfold-demo

simplescreenrecorder-2024-02-24_14 22 27

@lukasvinclav Let me know if you need anything else to reproduce this issue.

@lukasvinclav
Copy link
Contributor

@summerthe This is something what I already checked multiple times and it was always working for me BUT maybe I'm missing something. In our demo application at https://demo.unfoldadmin.com there is a badge in sidebar which is changing on each reload so the dynamic loading works at least in our demo.

Would you mind to check our demo repository https://github.com/unfoldadmin/formula and try to replicate the issue there? If there is a problem, I can take a look.

@summerthe
Copy link
Author

@lukasvinclav I was able to replicate the same issue in the formula. I forked the formula and updated the badge callback to return a random integer or UUID based on the user type.

For staff user login, use the following username/password: demostaff/demostaff.

Check code here:
summerthe/formula@29532bc

The callback's return value is changing, and it is possible that the request is being cached by whoever sends the first request after the server starts.

  • Log in with the superuser first and then with a staff member in another browser/incognito; you will see an integer for both users.
  • Restart the server.
  • Log in with a staff member first this time and then with the superuser in another browser/incognito; you will see a UUID for both users.

@jSdmeman
Copy link

jSdmeman commented Apr 2, 2024

@lukasvinclav same issue, looks like it depends on request, even if you trying to get some staff user related data it will display only data of first login user.
Is it possible that request is being cached as @summerthe sad?

Also noticed that ENVIRONMENT callback works without this issue, here some examples:
Using this callback with badge not showing actual id for some users:

def badge_callback(request):
    if request.user:
        return str(request.user.id)
    return ''

But using this callback with ENVIRONMENT works well:

def environment_callback(request):
    if request.user:
        return [str(request.user.id), 'warning' ]
    return ''

@lukasvinclav
Copy link
Contributor

@jSdmeman @summerthe thank you very much for the report. Now, I was able to replicate the issue locally. I created new PR #342 fixing the issue. Would you mind to test it locally if it works for you?

@summerthe
Copy link
Author

@lukasvinclav just tested in local, it fixes the issue.

@jSdmeman
Copy link

jSdmeman commented Apr 4, 2024

@lukasvinclav thanks for so fast answer
Tested your PR locally and on my project's dev server, looks like it works well. Thanks again!

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

3 participants