kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Follow serializer
rodzic
f19418d2c2
commit
657bd4b01a
|
@ -11,6 +11,12 @@ from . import models
|
|||
from . import utils
|
||||
|
||||
|
||||
AP_CONTEXT = [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
{},
|
||||
]
|
||||
|
||||
class ActorSerializer(serializers.ModelSerializer):
|
||||
# left maps to activitypub fields, right to our internal models
|
||||
id = serializers.URLField(source='url')
|
||||
|
@ -43,11 +49,7 @@ class ActorSerializer(serializers.ModelSerializer):
|
|||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
ret['@context'] = [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
{},
|
||||
]
|
||||
ret['@context'] = AP_CONTEXT
|
||||
if instance.public_key:
|
||||
ret['publicKey'] = {
|
||||
'owner': instance.url,
|
||||
|
@ -87,6 +89,28 @@ class ActorSerializer(serializers.ModelSerializer):
|
|||
return value[:500]
|
||||
|
||||
|
||||
class FollowSerializer(serializers.ModelSerializer):
|
||||
# left maps to activitypub fields, right to our internal models
|
||||
id = serializers.URLField(source='get_federation_url')
|
||||
object = serializers.URLField(source='target.url')
|
||||
actor = serializers.URLField(source='actor.url')
|
||||
type = serializers.CharField(source='ap_type')
|
||||
|
||||
class Meta:
|
||||
model = models.Actor
|
||||
fields = [
|
||||
'id',
|
||||
'object',
|
||||
'actor',
|
||||
'type'
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
ret = super().to_representation(instance)
|
||||
ret['@context'] = AP_CONTEXT
|
||||
return ret
|
||||
|
||||
|
||||
class ActorWebfingerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Actor
|
||||
|
|
|
@ -144,3 +144,22 @@ def test_webfinger_serializer():
|
|||
serializer = serializers.ActorWebfingerSerializer(actor)
|
||||
|
||||
assert serializer.data == expected
|
||||
|
||||
|
||||
def test_follow_serializer_to_ap(factories):
|
||||
follow = factories['federation.Follow'](local=True)
|
||||
serializer = serializers.FollowSerializer(follow)
|
||||
|
||||
expected = {
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
{},
|
||||
],
|
||||
'id': follow.get_federation_url(),
|
||||
'type': 'Follow',
|
||||
'actor': follow.actor.url,
|
||||
'object': follow.target.url,
|
||||
}
|
||||
|
||||
assert serializer.data == expected
|
||||
|
|
Ładowanie…
Reference in New Issue