2016-02-11 22:58:32 +01:00
|
|
|
from ..utils.access_permissions import BaseAccessPermissions
|
|
|
|
|
|
|
|
|
|
|
|
class AssignmentAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for Assignment and AssignmentViewSet.
|
|
|
|
"""
|
|
|
|
def can_retrieve(self, user):
|
|
|
|
"""
|
|
|
|
Returns True if the user has read access model instances.
|
|
|
|
"""
|
|
|
|
return user.has_perm('assignments.can_see')
|
2016-02-11 11:29:19 +01:00
|
|
|
|
|
|
|
def get_serializer_class(self, user):
|
|
|
|
"""
|
|
|
|
Returns different serializer classes according to users permissions.
|
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
from .serializers import AssignmentFullSerializer, AssignmentShortSerializer
|
|
|
|
|
2016-02-11 11:29:19 +01:00
|
|
|
if user.has_perm('assignments.can_manage'):
|
|
|
|
serializer_class = AssignmentFullSerializer
|
|
|
|
else:
|
|
|
|
serializer_class = AssignmentShortSerializer
|
|
|
|
return serializer_class
|