Fakultas Ilmu Komputer UI

Commit 974b0aa4 authored by sirinbaisa's avatar sirinbaisa
Browse files

Merge branch 'Features/SupervisorStudentApplications' of...

Merge branch 'Features/SupervisorStudentApplications' of https://gitlab.com/PPL2017csui/PPLA1 into Features/HomeDosen
parents 19c3fe93 af9c0563
......@@ -145,3 +145,8 @@ class IsAdminOrVacancyOwner(permissions.BasePermission):
raise PermissionDenied(
"Checking owner permission on non-application object"
)
class AsAdminOrSupervisor(permissions.BasePermission):
def has_permission(self, request, view):
return is_admin_or_supervisor(request.user)
......@@ -58,3 +58,21 @@ class ApplicationStatusSerializer(serializers.ModelSerializer):
class Meta:
model = Application
fields = ['status']
class SupervisorStudentApplicationSerializer(serializers.ModelSerializer):
def to_representation(self, instance):
status_map = ["new", "read", "bookmarked", "rejected", "accepted" ]
return {
'name' : instance.student.full_name,
'npm' : instance.student.npm,
'vacancy_name' : instance.vacancy.name,
'company_name' : instance.vacancy.company.name,
'status' : status_map[instance.status]
}
class Meta:
model = Application
fields = ['name', 'npm', 'vacancy_name', 'company_name', 'status']
read_only_fields = ['name', 'npm', 'vacancy_name', 'company_name', 'status']
......@@ -5,7 +5,7 @@ from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
from core.models.accounts import Company
from core.models.accounts import Company, Supervisor
from core.models.vacancies import Vacancy
......@@ -186,3 +186,23 @@ class CompanyListsTests(APITestCase):
url = '/api/companies/' + str(new_company.pk) + '/applications'
response = self.client.post(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
class SupervisorStudentApplicationTests(APITestCase):
def test_list_student_application(self):
new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
new_supervisor = Supervisor.objects.create(user=new_user, nip=1212121212)
self.client.force_authenticate(user=new_user)
url = '/api/student-applications/'
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_list_student_application_unauthorized(self):
new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
self.client.force_authenticate(user=new_user)
url = '/api/student-applications/'
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
......@@ -8,11 +8,11 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.pagination import PageNumberPagination
from core.lib.mixins import MultiSerializerViewSetMixin
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany, IsAdminOrVacancyOwner
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany, IsAdminOrVacancyOwner, AsAdminOrSupervisor
from core.models import Student, Company
from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer, ApplicationStatusSerializer, \
PostVacancySerializer
PostVacancySerializer, SupervisorStudentApplicationSerializer
class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
......@@ -206,3 +206,17 @@ class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet):
student = get_object_or_404(Student.objects.all(), pk=student_id)
student.bookmarked_vacancies.remove(vacancy)
return Response(self.serializer_class(student.bookmarked_vacancies, many=True, context={'request': request}).data)
class SupervisorStudentApplicationViewSet(viewsets.GenericViewSet):
queryset = Student.objects.all()
serializer_class = SupervisorStudentApplicationSerializer
pagination_class = PageNumberPagination
permission_classes = [AsAdminOrSupervisor]
def list(self, request):
applications = Application.objects.order_by('student')
page = self.paginate_queryset(applications)
if page is not None:
return self.get_paginated_response(self.serializer_class(applications, many=True, context={'request': request}).data)
return Response(self.serializer_class(applications, many=True, context={'request': request}).data)
......@@ -25,7 +25,8 @@ from core import apps
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, \
CompanyRegisterViewSet, StudentProfileViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet, \
CompanyApplicationViewSet, CompanyVacanciesViewSet, CompanyApplicationStatusViewSet
CompanyApplicationViewSet, CompanyVacanciesViewSet, CompanyApplicationStatusViewSet, \
SupervisorStudentApplicationViewSet
schema_view = get_swagger_view()
router = routers.DefaultRouter()
......@@ -38,6 +39,7 @@ router.register(r'register', CompanyRegisterViewSet)
router.register(r'vacancies', VacancyViewSet)
router.register(r'profiles/students', StudentProfileViewSet)
router.register(r'applications', CompanyApplicationStatusViewSet)
router.register(r'student-applications', SupervisorStudentApplicationViewSet)
router.register(r'students/(?P<student_id>\d+)/bookmarked-vacancies', BookmarkedVacancyByStudentViewSet,
base_name='bookmarked-vacancy-list')
router.register(r'students/(?P<student_id>\d+)/applied-vacancies', ApplicationViewSet,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment