Commit 439d4fd6 authored by Eliot Berriot's avatar Eliot Berriot 💬

See #574: Implemented getUser view

parent d3e411fa
......@@ -226,6 +226,30 @@ def get_music_directory_data(artist):
return data
def get_folders(user):
return []
def get_user_detail_data(user):
return {
"username": user.username,
"email": user.email,
"scrobblingEnabled": "true",
"adminRole": "false",
"settingsRole": "false",
"commentRole": "false",
"podcastRole": "false",
"coverArtRole": "false",
"shareRole": "false",
"uploadRole": "true",
"downloadRole": "true",
"playlistRole": "true",
"streamRole": "true",
"jukeboxRole": "true",
"folder": [f["id"] for f in get_folders(user)],
}
class ScrobbleSerializer(serializers.Serializer):
submission = serializers.BooleanField(default=True, required=False)
id = serializers.PrimaryKeyRelatedField(
......
......@@ -444,6 +444,17 @@ class SubsonicViewSet(viewsets.GenericViewSet):
r[file_header] = path
return r
@list_route(methods=["get", "post"], url_name="get_user", url_path="getUser")
@find_object(
queryset=lambda request: users_models.User.objects.filter(pk=request.user.pk),
model_field="username__iexact",
field="username",
cast=str,
)
def get_user(self, request, *args, **kwargs):
data = {"user": serializers.get_user_detail_data(request.user)}
return response.Response(data)
@list_route(
methods=["get", "post"],
url_name="get_music_folders",
......
......@@ -481,3 +481,34 @@ def test_scrobble(factories, logged_in_api_client):
listening = logged_in_api_client.user.listenings.latest("id")
assert listening.track == track
@pytest.mark.parametrize("f", ["json"])
def test_get_user(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-get-user")
assert url.endswith("getUser") is True
response = logged_in_api_client.get(
url, {"f": f, "username": logged_in_api_client.user.username}
)
assert response.status_code == 200
assert response.data == {
"user": {
"username": logged_in_api_client.user.username,
"email": logged_in_api_client.user.email,
"scrobblingEnabled": "true",
"adminRole": "false",
"downloadRole": "true",
"uploadRole": "true",
"settingsRole": "false",
"playlistRole": "true",
"commentRole": "false",
"podcastRole": "false",
"streamRole": "true",
"jukeboxRole": "true",
"coverArtRole": "false",
"shareRole": "false",
"folder": [
f["id"] for f in serializers.get_folders(logged_in_api_client.user)
],
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment