Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
Kape
Commits
af9c0563
Commit
af9c0563
authored
May 23, 2017
by
Joshua Casey
Browse files
[
#49
][GREEN] API for supervisor to see students' applications
parent
fcd5a4a7
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/lib/permissions.py
View file @
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
)
core/serializers/vacancies.py
View file @
af9c0563
...
...
@@ -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'
]
core/tests/test_vacancies.py
View file @
af9c0563
...
...
@@ -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
)
core/views/vacancies.py
View file @
af9c0563
...
...
@@ -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
)
kape/urls.py
View file @
af9c0563
...
...
@@ -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
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment