2019-02-28 08:31:04 +00:00
|
|
|
from funkwhale_api.common import mutations
|
2019-04-11 08:17:10 +00:00
|
|
|
from funkwhale_api.federation import routes
|
2019-02-28 08:31:04 +00:00
|
|
|
|
|
|
|
from . import models
|
|
|
|
|
|
|
|
|
|
|
|
def can_suggest(obj, actor):
|
2019-04-11 08:17:10 +00:00
|
|
|
return obj.is_local
|
2019-02-28 08:31:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"]
|
2019-02-28 08:31:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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
|
2019-04-09 09:11:05 +00:00
|
|
|
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}
|
|
|
|
)
|