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

Add setting for permission_classes for views #201

Open
brycekellogg opened this issue Feb 7, 2020 · 1 comment
Open

Add setting for permission_classes for views #201

brycekellogg opened this issue Feb 7, 2020 · 1 comment

Comments

@brycekellogg
Copy link

Currently the LoginView, LogoutView, and LogoutAllView all have hardcoded permission_classes to IsAuthenticated. While this is definitely the minimum needed as discussed in issues #64 and #9, sometimes additional permissions are required. For our use case, we are using API keys and only want a user to be able to login/out/etc if they have an API key. Currently we solve this like so:

class LoginView(KnoxLoginView):
    permission_classes = (IsAuthenticated,HasAPIKey)

class LogoutView(KnoxLogoutView):
    permission_classes = (IsAuthenticated,HasAPIKey)

class LogoutAllView(KnoxLogoutAllView):
    permission_classes = (IsAuthenticated,HasAPIKey)

One possible solution could be similar to how Djoser does it:

class UserViewSet(viewsets.ModelViewSet):
    permission_classes = settings.PERMISSIONS.user

where we set the permissions in settings.py like so:

DJOSER = {
    'PERMISSIONS': {
        'user':  ['baas.auth.permissions.HasAPIKey', 'djoser.permissions.CurrentUserOrAdmin'],
    }
}
@johnraz
Copy link
Collaborator

johnraz commented Feb 7, 2020

I agree this is a valid option but introducing a new settings means new documentation, more complexity in the code base and more tests. As this is a small project with very limited resources I think we should keep it as is.

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

2 participants