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

docs: Change admin site workaround documentation #3809

Closed
wants to merge 1 commit into from

Conversation

jkaeske
Copy link

@jkaeske jkaeske commented May 14, 2024

The documented workaround was resulting in ERR_TOO_MANY_REDIRECTS. To solve this issue a workaround using a custom decorator was proposed.

Fixes #3786

Submitting Pull Requests

General

  • Make sure you use semantic commit messages.
    Examples: "fix(google): Fixed foobar bug", "feat(accounts): Added foobar feature".
  • All Python code must formatted using Black, and clean from pep8 and isort issues.
  • JavaScript code should adhere to StandardJS.
  • If your changes are significant, please update ChangeLog.rst.
  • If your change is substantial, feel free to add yourself to AUTHORS.

The documented workaround was resulting in ERR_TOO_MANY_REDIRECTS. To solve this issue a workaround using a custom decorator was proposed.
@coveralls
Copy link

Coverage Status

coverage: 95.55%. remained the same
when pulling d8d1637 on jkaeske:admin-documentation
into a52fb87 on pennersr:main.

@pennersr
Copy link
Owner

IMO protecting the admin is really important, so I think it would make sense to promote that code to an actual decorator that just works out of the box, so that people do not need to copy chunks of code around. How about we add that decorator to allauth.account.decorators?

@jkaeske
Copy link
Author

jkaeske commented May 14, 2024

Sounds great to me!
Let me update the code in the next days.

@pennersr
Copy link
Owner

If I use this decorator, while logged in as a regular user, and then visit an admin page, I am redirected to LOGIN_REDIRECT_URL, but it is not really obvious why that happens. Wouldn't it be more clear to just raise a PermissionDenied ?

@pennersr
Copy link
Owner

Also, perhaps nitpicking, but the name staff_member_required_or_redirect is a bit long. Given that this decorator has only one purpose, securing the admin login, perhaps name it like that, so that we get:

from allauth.account.decorators import secure_admin_login

admin.site.login = secure_admin_login(admin.site.login)

@pennersr
Copy link
Owner

While I was toying with this anyway, I figured I could just as well file a PR right away. Could you take #3818 for a test spin?

@pennersr pennersr closed this May 15, 2024
@joonhyungshin
Copy link
Contributor

If I use this decorator, while logged in as a regular user, and then visit an admin page, I am redirected to LOGIN_REDIRECT_URL, but it is not really obvious why that happens. Wouldn't it be more clear to just raise a PermissionDenied ?

I think both approaches are valid. Sometimes a webmaster may not want to raise 403 or show 403 page to users but instead redirect them to the default login success page. I've seen some webpages doing this. In terms of customizability this looks more flexible.

How about adding an optional argument, something like redirect_url so that if it is given send non-staff users there and otherwise raise 403?

@pennersr
Copy link
Owner

The Django admin also uses PermissionDenied in case you try to access things you don't have access to, so this way the behavior is conform to what the admin is already doing. I am not sure a redirect makes much sense if there is no explanation/message on why you are ending up there...

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

Successfully merging this pull request may close these issues.

Allauth admin integration issues
4 participants