Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zwordi
funkwhale
Commits
657bd4b0
Verified
Commit
657bd4b0
authored
7 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Follow serializer
parent
f19418d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/federation/serializers.py
+29
-5
29 additions, 5 deletions
api/funkwhale_api/federation/serializers.py
api/tests/federation/test_serializers.py
+19
-0
19 additions, 0 deletions
api/tests/federation/test_serializers.py
with
48 additions
and
5 deletions
api/funkwhale_api/federation/serializers.py
+
29
−
5
View file @
657bd4b0
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
api/tests/federation/test_serializers.py
+
19
−
0
View file @
657bd4b0
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment