2018-02-17 20:21:08 +00:00
|
|
|
from dynamic_preferences.api import serializers
|
2018-05-17 21:39:34 +00:00
|
|
|
from dynamic_preferences.api import viewsets as preferences_viewsets
|
2018-02-17 20:21:08 +00:00
|
|
|
from dynamic_preferences.registries import global_preferences_registry
|
2018-06-10 08:55:16 +00:00
|
|
|
from rest_framework import views
|
|
|
|
from rest_framework.response import Response
|
2018-02-17 20:21:08 +00:00
|
|
|
|
2018-05-07 20:09:03 +00:00
|
|
|
from funkwhale_api.common import preferences
|
2018-05-18 16:48:46 +00:00
|
|
|
from funkwhale_api.users.permissions import HasUserPermission
|
2018-05-07 20:09:03 +00:00
|
|
|
|
|
|
|
from . import nodeinfo
|
2018-02-27 21:38:55 +00:00
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
NODEINFO_2_CONTENT_TYPE = "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" # noqa
|
2018-05-07 21:29:07 +00:00
|
|
|
|
|
|
|
|
2018-05-17 21:39:34 +00:00
|
|
|
class AdminSettings(preferences_viewsets.GlobalPreferencesViewSet):
|
|
|
|
pagination_class = None
|
2018-05-18 16:48:46 +00:00
|
|
|
permission_classes = (HasUserPermission,)
|
2018-06-09 13:36:16 +00:00
|
|
|
required_permissions = ["settings"]
|
|
|
|
|
2018-05-17 21:39:34 +00:00
|
|
|
|
2018-02-17 20:21:08 +00:00
|
|
|
class InstanceSettings(views.APIView):
|
|
|
|
permission_classes = []
|
|
|
|
authentication_classes = []
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
manager = global_preferences_registry.manager()
|
|
|
|
manager.all()
|
2018-06-09 13:36:16 +00:00
|
|
|
all_preferences = manager.model.objects.all().order_by("section", "name")
|
2018-02-17 20:21:08 +00:00
|
|
|
api_preferences = [
|
2018-06-09 13:36:16 +00:00
|
|
|
p for p in all_preferences if getattr(p.preference, "show_in_api", False)
|
2018-02-17 20:21:08 +00:00
|
|
|
]
|
2018-06-09 13:36:16 +00:00
|
|
|
data = serializers.GlobalPreferenceSerializer(api_preferences, many=True).data
|
2018-02-17 20:21:08 +00:00
|
|
|
return Response(data, status=200)
|
2018-02-27 21:38:55 +00:00
|
|
|
|
|
|
|
|
2018-05-07 20:09:03 +00:00
|
|
|
class NodeInfo(views.APIView):
|
2018-02-27 21:38:55 +00:00
|
|
|
permission_classes = []
|
|
|
|
authentication_classes = []
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2018-06-09 13:36:16 +00:00
|
|
|
if not preferences.get("instance__nodeinfo_enabled"):
|
2018-05-07 20:09:03 +00:00
|
|
|
return Response(status=404)
|
|
|
|
data = nodeinfo.get()
|
2018-06-09 13:36:16 +00:00
|
|
|
return Response(data, status=200, content_type=NODEINFO_2_CONTENT_TYPE)
|