permissions.py 556 Bytes
Newer Older
1
2
3

from rest_framework.permissions import BasePermission

4
from funkwhale_api.common import preferences
5
6
7
8
9
from . import actors


class LibraryFollower(BasePermission):
    def has_permission(self, request, view):
Eliot Berriot's avatar
Eliot Berriot committed
10
        if not preferences.get("federation__music_needs_approval"):
11
12
            return True

Eliot Berriot's avatar
Eliot Berriot committed
13
        actor = getattr(request, "actor", None)
14
15
16
        if actor is None:
            return False

Eliot Berriot's avatar
Eliot Berriot committed
17
18
        library = actors.SYSTEM_ACTORS["library"].get_actor_instance()
        return library.received_follows.filter(approved=True, actor=actor).exists()