kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
See #890: initial admin serializer for reports
rodzic
19b8adb358
commit
b659eec4df
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -160,8 +160,7 @@ def get_target_owner(target):
|
|||
return mapping[target.__class__](target)
|
||||
|
||||
|
||||
class ReportSerializer(serializers.ModelSerializer):
|
||||
target = common_fields.GenericRelation(
|
||||
TARGET_FIELD = common_fields.GenericRelation(
|
||||
{
|
||||
"artist": {"queryset": music_models.Artist.objects.all()},
|
||||
"album": {"queryset": music_models.Album.objects.all()},
|
||||
|
@ -179,7 +178,11 @@ class ReportSerializer(serializers.ModelSerializer):
|
|||
"get_query": get_actor_query,
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ReportSerializer(serializers.ModelSerializer):
|
||||
target = TARGET_FIELD
|
||||
|
||||
class Meta:
|
||||
model = models.Report
|
||||
|
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue