Fixed mutation erasing tags and description when other fields are modified
This commit is contained in:
parent
3e902bd89e
commit
f361791c1b
|
@ -9,6 +9,8 @@ from funkwhale_api.tags import serializers as tags_serializers
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
NOOP = object()
|
||||||
|
|
||||||
|
|
||||||
def can_suggest(obj, actor):
|
def can_suggest(obj, actor):
|
||||||
return obj.is_local
|
return obj.is_local
|
||||||
|
@ -34,9 +36,10 @@ class TagMutation(mutations.UpdateMutationSerializer):
|
||||||
return handlers
|
return handlers
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
tags = validated_data.pop("tags", [])
|
tags = validated_data.pop("tags", NOOP)
|
||||||
r = super().update(instance, validated_data)
|
r = super().update(instance, validated_data)
|
||||||
tags_models.set_tags(instance, *tags)
|
if tags != NOOP:
|
||||||
|
tags_models.set_tags(instance, *tags)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,9 +56,10 @@ class DescriptionMutation(mutations.UpdateMutationSerializer):
|
||||||
return handlers
|
return handlers
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
description = validated_data.pop("description", None)
|
description = validated_data.pop("description", NOOP)
|
||||||
r = super().update(instance, validated_data)
|
r = super().update(instance, validated_data)
|
||||||
common_utils.attach_content(instance, "description", description)
|
if description != NOOP:
|
||||||
|
common_utils.attach_content(instance, "description", description)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -220,3 +220,40 @@ def test_album_mutation_description(factory_name, factories, mocker):
|
||||||
mutation.previous_state["description"]
|
mutation.previous_state["description"]
|
||||||
== common_serializers.ContentSerializer(content).data
|
== common_serializers.ContentSerializer(content).data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"factory_name", ["music.Track", "music.Album", "music.Artist"],
|
||||||
|
)
|
||||||
|
def test_mutation_description_keep_tags(factory_name, factories, mocker):
|
||||||
|
mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
|
||||||
|
content = factories["common.Content"]()
|
||||||
|
obj = factories[factory_name](description=content, set_tags=["punk", "rock"])
|
||||||
|
mutation = factories["common.Mutation"](
|
||||||
|
type="update",
|
||||||
|
target=obj,
|
||||||
|
payload={"description": {"content_type": "text/plain", "text": "hello there"}},
|
||||||
|
)
|
||||||
|
mutation.apply()
|
||||||
|
obj.refresh_from_db()
|
||||||
|
|
||||||
|
assert obj.description.content_type == "text/plain"
|
||||||
|
assert obj.description.text == "hello there"
|
||||||
|
assert obj.get_tags() == ["punk", "rock"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"factory_name", ["music.Track", "music.Album", "music.Artist"],
|
||||||
|
)
|
||||||
|
def test_mutation_tags_keep_descriptions(factory_name, factories, mocker):
|
||||||
|
mocker.patch("funkwhale_api.federation.routes.outbox.dispatch")
|
||||||
|
content = factories["common.Content"]()
|
||||||
|
obj = factories[factory_name](description=content)
|
||||||
|
mutation = factories["common.Mutation"](
|
||||||
|
type="update", target=obj, payload={"tags": ["punk", "rock"]},
|
||||||
|
)
|
||||||
|
mutation.apply()
|
||||||
|
obj.refresh_from_db()
|
||||||
|
|
||||||
|
assert obj.description == content
|
||||||
|
assert obj.get_tags() == ["punk", "rock"]
|
||||||
|
|
Loading…
Reference in New Issue