See #170: exclude by default all channels-related entities from /artists, /albums and /tracks endpoints results, for backward compatibility

This commit is contained in:
Eliot Berriot 2019-11-25 09:49:49 +01:00
parent 32c0afab4f
commit 6bbe48598e
23 changed files with 649 additions and 9 deletions

View file

@ -1,6 +1,8 @@
import operator
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
from rest_framework.permissions import BasePermission
from funkwhale_api.common import preferences
@ -46,7 +48,12 @@ class OwnerPermission(BasePermission):
return True
owner_field = getattr(view, "owner_field", "user")
owner = operator.attrgetter(owner_field)(obj)
owner_exception = getattr(view, "owner_exception", Http404)
try:
owner = operator.attrgetter(owner_field)(obj)
except ObjectDoesNotExist:
raise owner_exception
if not owner or not request.user.is_authenticated or owner != request.user:
raise Http404
raise owner_exception
return True