X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ff382f6c37063c0c4c5d21c2834a8759e25c5d02..eaf0711613bea8181528d8911b30ef7976b7bb42:/src/catalogue/api/fields.py?ds=inline diff --git a/src/catalogue/api/fields.py b/src/catalogue/api/fields.py index cab947592..371da38ad 100644 --- a/src/catalogue/api/fields.py +++ b/src/catalogue/api/fields.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from rest_framework import serializers +from api.fields import AbsoluteURLField from catalogue.models import Book +from club.models import Membership class BookLiked(serializers.ReadOnlyField): @@ -19,3 +20,13 @@ class BookLiked(serializers.ReadOnlyField): request.liked_books = None if request.liked_books is not None: return value in request.liked_books + + +class EmbargoURLField(AbsoluteURLField): + def to_representation(self, value): + request = self.context['request'] + # FIXME: See #3955. + if True or Membership.is_active_for(request.user): + return super().to_representation(value) + else: + return None