See #890: initial admin serializer for reports

environments/review-docs-rate-jr6phc/deployments/2479
Eliot Berriot 2019-08-26 14:37:48 +02:00
rodzic 19b8adb358
commit b659eec4df
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
4 zmienionych plików z 102 dodań i 19 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ from funkwhale_api.federation import models as federation_models
from funkwhale_api.federation import fields as federation_fields
from funkwhale_api.federation import tasks as federation_tasks
from funkwhale_api.moderation import models as moderation_models
from funkwhale_api.moderation import serializers as moderation_serializers
from funkwhale_api.music import models as music_models
from funkwhale_api.music import serializers as music_serializers
from funkwhale_api.tags import models as tags_models
@ -629,3 +630,42 @@ class ManageTagActionSerializer(common_serializers.ActionSerializer):
@transaction.atomic
def handle_delete(self, objects):
return objects.delete()
class ManageReportSerializer(serializers.ModelSerializer):
assigned_to = ManageBaseActorSerializer()
target_owner = ManageBaseActorSerializer()
submitter = ManageBaseActorSerializer()
target = moderation_serializers.TARGET_FIELD
class Meta:
model = moderation_models.Report
fields = [
"id",
"uuid",
"fid",
"creation_date",
"handled_date",
"summary",
"type",
"target",
"target_state",
"is_handled",
"assigned_to",
"target_owner",
"submitter",
"submitter_email",
]
read_only_fields = [
"id",
"uuid",
"fid",
"submitter",
"submitter_email",
"creation_date",
"handled_date",
"target",
"target_state",
"target_owner",
"summary",
]

Wyświetl plik

@ -5,6 +5,8 @@ from funkwhale_api.federation import factories as federation_factories
from funkwhale_api.music import factories as music_factories
from funkwhale_api.users import factories as users_factories
from . import serializers
@registry.register
class InstancePolicyFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
@ -51,3 +53,13 @@ class ReportFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
class Params:
anonymous = factory.Trait(actor=None, submitter_email=factory.Faker("email"))
assigned = factory.Trait(
assigned_to=factory.SubFactory(federation_factories.ActorFactory)
)
@factory.post_generation
def _set_target_owner(self, create, extracted, **kwargs):
if not self.target:
return
self.target_owner = serializers.get_target_owner(self.target)

Wyświetl plik

@ -160,26 +160,29 @@ def get_target_owner(target):
return mapping[target.__class__](target)
TARGET_FIELD = common_fields.GenericRelation(
{
"artist": {"queryset": music_models.Artist.objects.all()},
"album": {"queryset": music_models.Album.objects.all()},
"track": {"queryset": music_models.Track.objects.all()},
"library": {
"queryset": music_models.Library.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"playlist": {"queryset": playlists_models.Playlist.objects.all()},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": get_actor_query,
},
}
)
class ReportSerializer(serializers.ModelSerializer):
target = common_fields.GenericRelation(
{
"artist": {"queryset": music_models.Artist.objects.all()},
"album": {"queryset": music_models.Album.objects.all()},
"track": {"queryset": music_models.Track.objects.all()},
"library": {
"queryset": music_models.Library.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"playlist": {"queryset": playlists_models.Playlist.objects.all()},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": get_actor_query,
},
}
)
target = TARGET_FIELD
class Meta:
model = models.Report

Wyświetl plik

@ -521,3 +521,31 @@ def test_manage_tag_serializer(factories, to_api_date):
s = serializers.ManageTagSerializer(tag)
assert s.data == expected
def test_manage_report_serializer(factories, to_api_date):
artist = factories["music.Artist"](attributed=True)
report = factories["moderation.Report"](
target=artist, target_state={"hello": "world"}, assigned=True
)
expected = {
"id": report.id,
"uuid": str(report.uuid),
"fid": report.fid,
"creation_date": to_api_date(report.creation_date),
"handled_date": None,
"summary": report.summary,
"is_handled": report.is_handled,
"type": report.type,
"submitter_email": None,
"submitter": serializers.ManageBaseActorSerializer(report.submitter).data,
"assigned_to": serializers.ManageBaseActorSerializer(report.assigned_to).data,
"target": {"type": "artist", "id": artist.pk},
"target_owner": serializers.ManageBaseActorSerializer(
artist.attributed_to
).data,
"target_state": report.target_state,
}
s = serializers.ManageReportSerializer(report)
assert s.data == expected