2015-02-12 18:48:14 +01:00
|
|
|
from openslides.utils.rest_api import ModelViewSet
|
2013-02-16 16:19:20 +01:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from .models import Mediafile
|
2015-01-24 16:35:50 +01:00
|
|
|
from .serializers import MediafileSerializer
|
2013-02-16 16:19:20 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MediafileViewSet(ModelViewSet):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
API endpoint to list, retrieve, create, update and destroy mediafile
|
|
|
|
objects.
|
|
|
|
"""
|
|
|
|
queryset = Mediafile.objects.all()
|
|
|
|
serializer_class = MediafileSerializer
|
|
|
|
|
|
|
|
def check_permissions(self, request):
|
|
|
|
"""
|
|
|
|
Calls self.permission_denied() if the requesting user has not the
|
|
|
|
permission to see mediafile objects and in case of create, update or
|
|
|
|
destroy requests the permission to manage mediafile objects.
|
|
|
|
"""
|
2015-03-26 05:36:10 +01:00
|
|
|
# TODO: Use mediafiles.can_upload permission to create and update some
|
2015-01-24 16:35:50 +01:00
|
|
|
# objects but restricted concerning the uploader.
|
2015-03-26 05:36:10 +01:00
|
|
|
if (not request.user.has_perm('mediafiles.can_see') or
|
2015-01-24 16:35:50 +01:00
|
|
|
(self.action in ('create', 'update', 'destroy') and not
|
2015-03-26 05:36:10 +01:00
|
|
|
request.user.has_perm('mediafiles.can_manage'))):
|
2015-01-24 16:35:50 +01:00
|
|
|
self.permission_denied(request)
|