b48a99f21b
Only users with the 'mediafiles.can_see_private' permission can create and view these private mediafiles.
32 lines
925 B
Python
32 lines
925 B
Python
from ..utils.access_permissions import BaseAccessPermissions
|
|
|
|
|
|
class MediafileAccessPermissions(BaseAccessPermissions):
|
|
"""
|
|
Access permissions container for Mediafile and MediafileViewSet.
|
|
"""
|
|
def check_permissions(self, user):
|
|
"""
|
|
Returns True if the user has read access model instances.
|
|
"""
|
|
return user.has_perm('mediafiles.can_see')
|
|
|
|
def get_serializer_class(self, user=None):
|
|
"""
|
|
Returns serializer class.
|
|
"""
|
|
from .serializers import MediafileSerializer
|
|
|
|
return MediafileSerializer
|
|
|
|
def get_restricted_data(self, full_data, user):
|
|
"""
|
|
Returns the restricted serialized data for the instance prepared
|
|
for the user.
|
|
"""
|
|
if (not full_data['private'] or user.has_perm('mediafiles.can_see_private')):
|
|
data = full_data
|
|
else:
|
|
data = None
|
|
return data
|