63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
from django.shortcuts import render
|
|
|
|
from django.http import Http404
|
|
from django.shortcuts import render
|
|
from oauth2_provider.contrib.rest_framework import TokenMatchesOASRequirements
|
|
from rest_framework import viewsets, mixins
|
|
from rest_framework.generics import get_object_or_404
|
|
from rest_framework.viewsets import GenericViewSet
|
|
|
|
from .models import PushUser, PushMessage
|
|
from .serializers import PushUserSerializer, PushMessageSerializer
|
|
from apps.gooyal_oauth2.models import Application
|
|
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
|
from apps.gooyal_oauth2.utils import get_application
|
|
from ..users.models import User
|
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import Http404
|
|
from django.shortcuts import render
|
|
from django.urls import reverse
|
|
from oauth2_provider.contrib.rest_framework import TokenMatchesOASRequirements
|
|
from rest_framework import viewsets, mixins
|
|
from rest_framework.generics import get_object_or_404
|
|
from rest_framework.viewsets import GenericViewSet
|
|
|
|
from .models import Sample
|
|
from .serializers import SampleSerializer
|
|
from apps.gooyal_oauth2.models import Application
|
|
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
|
from apps.gooyal_oauth2.utils import get_application
|
|
from ..users.models import User
|
|
|
|
|
|
class ApplicationSampleViewSet(mixins.ListModelMixin,
|
|
mixins.CreateModelMixin,
|
|
GenericViewSet):
|
|
queryset = Sample.objects.all()
|
|
serializer_class = SampleSerializer
|
|
|
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
|
required_alternate_scopes = {
|
|
"POST": [["service_template.application.user-sample:submit"]],
|
|
"GET": [["service_template.application.user-sample:list-retrieve"]],
|
|
}
|
|
|
|
def perform_create(self, serializer):
|
|
user_uuid = self.kwargs.get('user_uuid')
|
|
user = User.objects.get(uuid=user_uuid)
|
|
application = get_application(self.request)
|
|
instance = serializer.save(user=user, application=application)
|
|
|
|
|
|
class UserSampleViewSet(mixins.RetrieveModelMixin,
|
|
GenericViewSet):
|
|
queryset = Sample.objects.all()
|
|
serializer_class = SampleSerializer
|
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
|
required_alternate_scopes = {
|
|
"GET": [["service_template.user.self-sample:list-retrieve"]],
|
|
}
|
|
|