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

Are there permissions available? #12

Open
rafaellehmkuhl opened this issue Oct 30, 2020 · 4 comments
Open

Are there permissions available? #12

rafaellehmkuhl opened this issue Oct 30, 2020 · 4 comments

Comments

@rafaellehmkuhl
Copy link
Contributor

rafaellehmkuhl commented Oct 30, 2020

On the example client (example/client/src/index.js) you use permissions for displaying or not the users section:

{permissions => [
    <Resource name="posts" {...posts} />,
    <Resource name="comments" {...comments} />,
    permissions ? <Resource name="users" {...users} /> : null,
    <Resource name="tags" {...tags} />,
]}

Are those permissions available? Because as far as I could see on the tokenAuthProvider.ts, only the authentication token is stored locally.

@rafaellehmkuhl rafaellehmkuhl changed the title Are there any permissions available? Are there permissions available? Oct 30, 2020
@rafaellehmkuhl
Copy link
Contributor Author

If you like the idea, I'm thinking about submitting a PR adding the user groups to the token response, like this:

from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response

class CustomAuthToken(ObtainAuthToken):

    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data,
                                           context={'request': request})
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data['user']
        token, created = Token.objects.get_or_create(user=user)
        return Response({
            'token': token.key,
            'roles': [g.name for g in user.groups.all()]
        })

which would substitute the default ObtainAuthToken view, and making the corresponding changes on the tokenAuthProvider to make the roles available at the permissions.

@mmodenesi
Copy link

Would love to have this.

@vahidqo
Copy link

vahidqo commented Apr 6, 2022

@rafaellehmkuhl could you please explain your method for permission more?

@rafaellehmkuhl
Copy link
Contributor Author

Sorry, but it has been a long time since I've worked with this and I honest have no clue 😅

@rafaellehmkuhl could you please explain your method for permission more?

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