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

[feat] add superuser session authentication only #351

Merged
merged 8 commits into from
Jun 25, 2022

Conversation

areski
Copy link
Contributor

@areski areski commented Feb 8, 2022

I have some use cases where some APIs are only for some privileged root user and it quite helpful to have an helper to add this extra security.

Let me know

@areski
Copy link
Contributor Author

areski commented Feb 8, 2022

@SmileyChris
Copy link
Contributor

Well, mypy is correct -- AbstractBaseUser doesn't provide an is_superuser attribute. You're making the assumption that all user backends need to provide is_superuser (inferred from the base class, they don't).

I'd just do:

if request.user.is_authenticated and getattr(request.user, 'is_superuser', None):

@areski
Copy link
Contributor Author

areski commented Feb 15, 2022

Thanks for the pointer @SmileyChris

All tests are now passing: https://github.com/areski/django-ninja/actions/runs/1847443859

@vitalik vitalik merged commit 821d473 into vitalik:master Jun 25, 2022
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.

3 participants