funkwhale/api/funkwhale_api/music/mutations.py

63 wiersze
1.7 KiB
Python
Czysty Zwykły widok Historia

from funkwhale_api.common import mutations
2019-04-11 08:17:10 +00:00
from funkwhale_api.federation import routes
from . import models
def can_suggest(obj, actor):
2019-04-11 08:17:10 +00:00
return obj.is_local
def can_approve(obj, actor):
2019-04-11 08:17:10 +00:00
return obj.is_local and actor.user and actor.user.get_permissions()["library"]
@mutations.registry.connect(
"update",
models.Track,
perm_checkers={"suggest": can_suggest, "approve": can_approve},
)
class TrackMutationSerializer(mutations.UpdateMutationSerializer):
serialized_relations = {"license": "code"}
class Meta:
model = models.Track
fields = ["license", "title", "position", "copyright"]
2019-04-11 08:17:10 +00:00
def post_apply(self, obj, validated_data):
routes.outbox.dispatch(
{"type": "Update", "object": {"type": "Track"}}, context={"track": obj}
)
2019-04-17 14:11:24 +00:00
@mutations.registry.connect(
"update",
models.Artist,
perm_checkers={"suggest": can_suggest, "approve": can_approve},
)
class ArtistMutationSerializer(mutations.UpdateMutationSerializer):
class Meta:
model = models.Artist
fields = ["name"]
def post_apply(self, obj, validated_data):
routes.outbox.dispatch(
{"type": "Update", "object": {"type": "Artist"}}, context={"artist": obj}
)
@mutations.registry.connect(
"update",
models.Album,
perm_checkers={"suggest": can_suggest, "approve": can_approve},
)
class AlbumMutationSerializer(mutations.UpdateMutationSerializer):
class Meta:
model = models.Album
fields = ["title", "release_date"]
def post_apply(self, obj, validated_data):
routes.outbox.dispatch(
{"type": "Update", "object": {"type": "Album"}}, context={"album": obj}
)