Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Allow OAuth Applications Access (#60)
Browse files Browse the repository at this point in the history
This commit allows OAuth Applications that are not bound to a specific
user access to the /api/v1/users and /api/v1/courses endpoints.
  • Loading branch information
tkw1536 authored Oct 18, 2017
1 parent dbfe3a7 commit b1f4140
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers, views, viewsets, filters, decorators
from rest_framework import serializers, views, viewsets, filters, decorators, \
permissions
from django_filters.rest_framework import DjangoFilterBackend
from django import shortcuts
from django import conf
Expand All @@ -8,6 +9,12 @@
from api.filters import extended as extended_filters


class UserOrOAuthApplication(permissions.BasePermission):
def has_permission(self, request, view):
return (request.user and request.user.is_authenticated) or \
(request.auth and request.auth.application)


class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = core_models.Student
Expand All @@ -29,6 +36,7 @@ class Meta:
class StudentViewSet(viewsets.ReadOnlyModelViewSet):
# Permissions
required_scopes = []
permission_classes = [UserOrOAuthApplication]

# Content
queryset = core_models.Student.objects.all()
Expand Down Expand Up @@ -67,6 +75,7 @@ def image(self, request, username=None):
class CourseView(viewsets.ReadOnlyModelViewSet):
# Permissions
required_scopes = []
permission_classes = [UserOrOAuthApplication]

# Content
queryset = core_models.Course.objects.all()
Expand Down

0 comments on commit b1f4140

Please sign in to comment.