From aaced60ec1ee0436992647c951d71e4293ed9efa Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Thu, 25 Jul 2019 10:17:31 +0200 Subject: [PATCH] See #432: added /action endpoint to manage tags in batch --- api/funkwhale_api/manage/serializers.py | 10 ++++++++++ api/funkwhale_api/manage/views.py | 10 ++++++++++ api/tests/manage/test_serializers.py | 1 + 3 files changed, 21 insertions(+) diff --git a/api/funkwhale_api/manage/serializers.py b/api/funkwhale_api/manage/serializers.py index eab3b87f0..6eecdd900 100644 --- a/api/funkwhale_api/manage/serializers.py +++ b/api/funkwhale_api/manage/serializers.py @@ -592,3 +592,13 @@ class ManageTagSerializer(ManageBaseAlbumSerializer): def get_artists_count(self, obj): return getattr(obj, "_artists_count", None) + + +class ManageTagActionSerializer(common_serializers.ActionSerializer): + actions = [common_serializers.Action("delete", allow_all=False)] + filterset_class = filters.ManageTagFilterSet + pk_field = "name" + + @transaction.atomic + def handle_delete(self, objects): + return objects.delete() diff --git a/api/funkwhale_api/manage/views.py b/api/funkwhale_api/manage/views.py index 09737a7a8..9ecd1fee2 100644 --- a/api/funkwhale_api/manage/views.py +++ b/api/funkwhale_api/manage/views.py @@ -493,3 +493,13 @@ class ManageTagViewSet( ), ) return queryset + + @rest_decorators.action(methods=["post"], detail=False) + def action(self, request, *args, **kwargs): + queryset = self.get_queryset() + serializer = serializers.ManageTagActionSerializer( + request.data, queryset=queryset + ) + serializer.is_valid(raise_exception=True) + result = serializer.save() + return response.Response(result, status=200) diff --git a/api/tests/manage/test_serializers.py b/api/tests/manage/test_serializers.py index c1c532fac..af2a214a6 100644 --- a/api/tests/manage/test_serializers.py +++ b/api/tests/manage/test_serializers.py @@ -487,6 +487,7 @@ def test_manage_upload_serializer(factories, now): ("music.Artist", serializers.ManageArtistActionSerializer), ("music.Library", serializers.ManageLibraryActionSerializer), ("music.Upload", serializers.ManageUploadActionSerializer), + ("tags.Tag", serializers.ManageTagActionSerializer), ], ) def test_action_serializer_delete(factory, serializer_class, factories):