diff --git a/requirements/production.in b/requirements/production.in index 71c15873ba4e2b7f68f65a9c74e441c669985d70..2ef446c78ccb7cf01c48ff5cee36a04d5f6f6abc 100644 --- a/requirements/production.in +++ b/requirements/production.in @@ -8,3 +8,4 @@ python-language-server==0.28.2 drf-yasg==1.16.1 packaging==19.1 Pillow==7.0.0 +djangorestframework-api-key==1.4.1 \ No newline at end of file diff --git a/requirements/production.txt b/requirements/production.txt index c0742acf8fe223e8fcbca350607d3bf8dddac85c..7cdc80bd945fd1c0c126cfee9d379ae6c4c884f9 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -17,6 +17,7 @@ django-import-export==1.2.0 django-social-authsch==0.1 django-solo==1.1.3 django==2.2.4 +djangorestframework-api-key==1.4.1 djangorestframework==3.10.2 drf-yasg==1.16.1 entrypoints==0.3 # via flake8 diff --git a/src/account/serializers.py b/src/account/serializers.py index e057bbd7f5d7b81ef578a2ba960709ee2ec99419..ffd2a12a78efdc422d9d1be74905b0c0ec157180 100644 --- a/src/account/serializers.py +++ b/src/account/serializers.py @@ -124,3 +124,29 @@ class ProfileSerializer_Staff(serializers.ModelSerializer): def get_full_name(self, obj): return obj.full_name + + +class MonitoringSerializer(serializers.ModelSerializer): + full_name = serializers.SerializerMethodField() + email = serializers.SerializerMethodField() + + class Meta: + model = models.Profile + read_only_fields = ( + 'full_name', + 'email', + 'events_visited', + 'homework_bits', + ) + fields = ( + 'full_name', + 'email', + 'events_visited', + 'homework_bits', + ) + + def get_full_name(self, obj): + return obj.full_name + + def get_email(self, obj): + return obj.user.email diff --git a/src/account/urls.py b/src/account/urls.py index ebf85f3d5bdf9885beb1ad7f28d1bce0e6624575..b46b1984b36192b6a3e6113fd5f0b29b836d8d3e 100644 --- a/src/account/urls.py +++ b/src/account/urls.py @@ -4,4 +4,6 @@ from . import views router = routers.DefaultRouter() router.register(r'profiles', views.ProfileViewSet, base_name='profile') +router.register(r'monitoring/profiles', views.MonitorinViewSet, base_name='monitoring') + urlpatterns = router.urls diff --git a/src/account/views.py b/src/account/views.py index 4f88c5140b7e7c19be08f485d18798be2c627974..b579b83b01af5f27fd9916eabe968527c94a4bbe 100644 --- a/src/account/views.py +++ b/src/account/views.py @@ -3,11 +3,20 @@ from rest_framework import permissions from rest_framework.response import Response from rest_framework.decorators import action from common.permissions import IsSafeOrPatch +from rest_framework_api_key.permissions import HasAPIKey from . import models from . import serializers +class MonitorinViewSet(viewsets.ModelViewSet): + serializer_class = serializers.MonitoringSerializer + permission_classes = (HasAPIKey,) + + def get_queryset(self): + return models.Profile.objects.filter(role='Student') + + class ProfileViewSet(viewsets.ModelViewSet): serializer_class = serializers.ProfileSerializer_User permission_classes = (permissions.IsAuthenticated, IsSafeOrPatch) diff --git a/src/kszkepzes/settings/base.py b/src/kszkepzes/settings/base.py index a1ce1fbb2401262f421c430fb38a57a5e41da32c..fa4afc6fa9a812faa4d6ddd0c096c85cf72c7cdb 100644 --- a/src/kszkepzes/settings/base.py +++ b/src/kszkepzes/settings/base.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ 'django_extensions', 'import_export', 'rest_framework', + "rest_framework_api_key", 'social_django', 'solo', 'authsch',