Replies: 5 comments 1 reply
-
Hi @VetalM84 Could you show code example (at least how you applied decorator ? ) |
Beta Was this translation helpful? Give feedback.
-
Hi, @vitalik
|
Beta Was this translation helpful? Give feedback.
-
@VetalM84 so far so good... now can you show the |
Beta Was this translation helpful? Give feedback.
-
@VetalM84 I've made a simple permissions decorator here: https://github.com/OtherBarry/django-ninja-decorators/blob/master/ninja_decorators/permissions.py I'm working on turning it into an actual package with tests and everything, but I'm using something similar in production code currently so the concept works. |
Beta Was this translation helpful? Give feedback.
-
I guess you need to keep in mind that ninja auth sets the so in order to reuse some django auth related decorators you need to set as well from ninja.security import HttpBearer
from django.contrib.auth.models import User
class AuthBearer(HttpBearer):
def authenticate(self, request, token):
if token == "supersecret":
user = User.objects.get(id=1)
request.user = user # <---------------- !!!!!
return user
api = NinjaAPI(auth=AuthBearer())
@api.get('/some')
@permission_required('auth.add_user')
def someview(request, param: int = 0):
return param |
Beta Was this translation helpful? Give feedback.
-
Hi, added this decorator to endpoint
@permission_required("currency.add_currency", raise_exception=True)
but Ninja ignores it.The main idea is like in DRF is to apply something like
permission_classes = [IsAuthenticatedOrReadOnly]
Ho do you handle permissions?
Beta Was this translation helpful? Give feedback.
All reactions