mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 03:59:24 +02:00
See #432: can now suggest tags on tracks/albums/artists (API)
This commit is contained in:
parent
1b34ae2335
commit
2bbb2f3239
4 changed files with 54 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
|||
from funkwhale_api.common import mutations
|
||||
from funkwhale_api.federation import routes
|
||||
from funkwhale_api.tags import models as tags_models
|
||||
from funkwhale_api.tags import serializers as tags_serializers
|
||||
|
||||
from . import models
|
||||
|
||||
|
@ -12,17 +14,32 @@ def can_approve(obj, actor):
|
|||
return obj.is_local and actor.user and actor.user.get_permissions()["library"]
|
||||
|
||||
|
||||
class TagMutation(mutations.UpdateMutationSerializer):
|
||||
tags = tags_serializers.TagsListField()
|
||||
previous_state_handlers = {
|
||||
"tags": lambda obj: list(
|
||||
sorted(obj.tagged_items.values_list("tag__name", flat=True))
|
||||
)
|
||||
}
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
tags = validated_data.pop("tags", [])
|
||||
r = super().update(instance, validated_data)
|
||||
tags_models.set_tags(instance, *tags)
|
||||
return r
|
||||
|
||||
|
||||
@mutations.registry.connect(
|
||||
"update",
|
||||
models.Track,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class TrackMutationSerializer(mutations.UpdateMutationSerializer):
|
||||
class TrackMutationSerializer(TagMutation):
|
||||
serialized_relations = {"license": "code"}
|
||||
|
||||
class Meta:
|
||||
model = models.Track
|
||||
fields = ["license", "title", "position", "copyright"]
|
||||
fields = ["license", "title", "position", "copyright", "tags"]
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
@ -35,10 +52,10 @@ class TrackMutationSerializer(mutations.UpdateMutationSerializer):
|
|||
models.Artist,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class ArtistMutationSerializer(mutations.UpdateMutationSerializer):
|
||||
class ArtistMutationSerializer(TagMutation):
|
||||
class Meta:
|
||||
model = models.Artist
|
||||
fields = ["name"]
|
||||
fields = ["name", "tags"]
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
@ -51,10 +68,10 @@ class ArtistMutationSerializer(mutations.UpdateMutationSerializer):
|
|||
models.Album,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class AlbumMutationSerializer(mutations.UpdateMutationSerializer):
|
||||
class AlbumMutationSerializer(TagMutation):
|
||||
class Meta:
|
||||
model = models.Album
|
||||
fields = ["title", "release_date"]
|
||||
fields = ["title", "release_date", "tags"]
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue