Skip to content
Snippets Groups Projects
Verified Commit 6152b3bb authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added API endpoint for listing public instance settings

parent 0944ef2a
No related branches found
No related tags found
No related merge requests found
from rest_framework import routers
from django.conf.urls import include, url
from funkwhale_api.instance import views as instance_views
from funkwhale_api.music import views
from funkwhale_api.playlists import views as playlists_views
from rest_framework_jwt import views as jwt_views
......@@ -25,6 +26,10 @@ router.register(
v1_patterns = router.urls
v1_patterns += [
url(r'^instance/',
include(
('funkwhale_api.instance.urls', 'instance'),
namespace='instance')),
url(r'^providers/',
include(
('funkwhale_api.providers.urls', 'providers'),
......
......@@ -60,6 +60,7 @@ THIRD_PARTY_APPS = (
LOCAL_APPS = (
'funkwhale_api.users', # custom users app
# Your stuff: custom apps go here
'funkwhale_api.instance',
'funkwhale_api.music',
'funkwhale_api.favorites',
'funkwhale_api.radios',
......
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^settings/$', views.InstanceSettings.as_view(), name='settings'),
]
from rest_framework import views
from rest_framework.response import Response
from dynamic_preferences.api import serializers
from dynamic_preferences.registries import global_preferences_registry
class InstanceSettings(views.APIView):
permission_classes = []
authentication_classes = []
def get(self, request, *args, **kwargs):
manager = global_preferences_registry.manager()
manager.all()
all_preferences = manager.model.objects.all().order_by(
'section', 'name'
)
api_preferences = [
p
for p in all_preferences
if getattr(p.preference, 'show_in_api', False)
]
data = serializers.GlobalPreferenceSerializer(
api_preferences, many=True).data
return Response(data, status=200)
......@@ -3,6 +3,7 @@ import shutil
import pytest
from django.core.cache import cache as django_cache
from dynamic_preferences.registries import global_preferences_registry
from rest_framework.test import APIClient
from funkwhale_api.taskapp import celery
......@@ -29,7 +30,9 @@ def factories(db):
@pytest.fixture
def preferences(db):
yield global_preferences_registry.manager()
manager = global_preferences_registry.manager()
manager.all()
yield manager
@pytest.fixture
......@@ -48,6 +51,11 @@ def logged_in_client(db, factories, client):
delattr(client, 'user')
@pytest.fixture
def api_client(client):
return APIClient()
@pytest.fixture
def superuser_client(db, factories, client):
user = factories['users.SuperUser']()
......
from django.urls import reverse
from dynamic_preferences.api import serializers
def test_can_list_settings_via_api(preferences, api_client):
url = reverse('api:v1:instance:settings')
all_preferences = preferences.model.objects.all()
expected_preferences = {
p.preference.identifier(): p
for p in all_preferences
if getattr(p.preference, 'show_in_api', False)}
assert len(expected_preferences) > 0
response = api_client.get(url)
assert response.status_code == 200
assert len(response.data) == len(expected_preferences)
for p in response.data:
i = '__'.join([p['section'], p['name']])
assert i in expected_preferences
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment