kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
See #890: initial API endpoint to handle management of reports
rodzic
815d9c02f8
commit
8f7ab82117
|
@ -339,3 +339,26 @@ class ManageTagFilterSet(filters.FilterSet):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = tags_models.Tag
|
model = tags_models.Tag
|
||||||
fields = ["q"]
|
fields = ["q"]
|
||||||
|
|
||||||
|
|
||||||
|
class ManageReportFilterSet(filters.FilterSet):
|
||||||
|
q = fields.SmartSearchFilter(
|
||||||
|
config=search.SearchConfig(
|
||||||
|
search_fields={"summary": {"to": "summary"}},
|
||||||
|
filter_fields={
|
||||||
|
"uuid": {"to": "uuid"},
|
||||||
|
"id": {"to": "id"},
|
||||||
|
"is_handled": {"to": "is_handled"},
|
||||||
|
"domain": {"to": "target_owner__domain_id"},
|
||||||
|
"type": {"to": "type"},
|
||||||
|
"submitter": get_actor_filter("submitter"),
|
||||||
|
"assigned_to": get_actor_filter("assigned_to"),
|
||||||
|
"target_owner": get_actor_filter("target_owner"),
|
||||||
|
"submitter_email": {"to": "submitter_email"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = moderation_models.Report
|
||||||
|
fields = ["q", "is_handled", "type", "submitter_email"]
|
||||||
|
|
|
@ -17,6 +17,7 @@ moderation_router = routers.OptionalSlashRouter()
|
||||||
moderation_router.register(
|
moderation_router.register(
|
||||||
r"instance-policies", views.ManageInstancePolicyViewSet, "instance-policies"
|
r"instance-policies", views.ManageInstancePolicyViewSet, "instance-policies"
|
||||||
)
|
)
|
||||||
|
moderation_router.register(r"reports", views.ManageReportViewSet, "reports")
|
||||||
|
|
||||||
users_router = routers.OptionalSlashRouter()
|
users_router = routers.OptionalSlashRouter()
|
||||||
users_router.register(r"users", views.ManageUserViewSet, "users")
|
users_router.register(r"users", views.ManageUserViewSet, "users")
|
||||||
|
|
|
@ -459,6 +459,25 @@ class ManageInstancePolicyViewSet(
|
||||||
serializer.save(actor=self.request.user.actor)
|
serializer.save(actor=self.request.user.actor)
|
||||||
|
|
||||||
|
|
||||||
|
class ManageReportViewSet(
|
||||||
|
mixins.ListModelMixin,
|
||||||
|
mixins.RetrieveModelMixin,
|
||||||
|
mixins.DestroyModelMixin,
|
||||||
|
mixins.UpdateModelMixin,
|
||||||
|
viewsets.GenericViewSet,
|
||||||
|
):
|
||||||
|
lookup_field = "uuid"
|
||||||
|
queryset = (
|
||||||
|
moderation_models.Report.objects.all()
|
||||||
|
.order_by("-creation_date")
|
||||||
|
.select_related()
|
||||||
|
)
|
||||||
|
serializer_class = serializers.ManageReportSerializer
|
||||||
|
filterset_class = filters.ManageReportFilterSet
|
||||||
|
required_scope = "instance:reports"
|
||||||
|
ordering_fields = ["id", "creation_date", "handled_date"]
|
||||||
|
|
||||||
|
|
||||||
class ManageTagViewSet(
|
class ManageTagViewSet(
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
mixins.RetrieveModelMixin,
|
mixins.RetrieveModelMixin,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class UserFilterFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
||||||
@registry.register
|
@registry.register
|
||||||
class ReportFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
class ReportFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
|
||||||
submitter = factory.SubFactory(federation_factories.ActorFactory)
|
submitter = factory.SubFactory(federation_factories.ActorFactory)
|
||||||
target = None
|
target = factory.SubFactory(music_factories.ArtistFactory)
|
||||||
summary = factory.Faker("paragraph")
|
summary = factory.Faker("paragraph")
|
||||||
type = "other"
|
type = "other"
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from django.utils import timezone
|
||||||
from funkwhale_api.federation import models as federation_models
|
from funkwhale_api.federation import models as federation_models
|
||||||
from funkwhale_api.federation import utils as federation_utils
|
from funkwhale_api.federation import utils as federation_utils
|
||||||
|
|
||||||
|
|
||||||
class InstancePolicyQuerySet(models.QuerySet):
|
class InstancePolicyQuerySet(models.QuerySet):
|
||||||
def active(self):
|
def active(self):
|
||||||
return self.filter(is_active=True)
|
return self.filter(is_active=True)
|
||||||
|
@ -168,4 +169,4 @@ def set_handled_date(sender, instance, **kwargs):
|
||||||
if instance.is_handled is True and not instance.handled_date:
|
if instance.is_handled is True and not instance.handled_date:
|
||||||
instance.handled_date = timezone.now()
|
instance.handled_date = timezone.now()
|
||||||
elif not instance.is_handled:
|
elif not instance.is_handled:
|
||||||
instance.handled_date = None
|
instance.handled_date = None
|
||||||
|
|
|
@ -417,3 +417,47 @@ def test_tag_delete(factories, superuser_api_client):
|
||||||
response = superuser_api_client.delete(url)
|
response = superuser_api_client.delete(url)
|
||||||
|
|
||||||
assert response.status_code == 204
|
assert response.status_code == 204
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_detail(factories, superuser_api_client):
|
||||||
|
report = factories["moderation.Report"]()
|
||||||
|
url = reverse(
|
||||||
|
"api:v1:manage:moderation:reports-detail", kwargs={"uuid": report.uuid}
|
||||||
|
)
|
||||||
|
response = superuser_api_client.get(url)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.data["summary"] == report.summary
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_list(factories, superuser_api_client, settings):
|
||||||
|
report = factories["moderation.Report"]()
|
||||||
|
url = reverse("api:v1:manage:moderation:reports-list")
|
||||||
|
response = superuser_api_client.get(url)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
assert response.data["count"] == 1
|
||||||
|
assert response.data["results"][0]["summary"] == report.summary
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_update(factories, superuser_api_client):
|
||||||
|
report = factories["moderation.Report"]()
|
||||||
|
url = reverse(
|
||||||
|
"api:v1:manage:moderation:reports-detail", kwargs={"uuid": report.uuid}
|
||||||
|
)
|
||||||
|
response = superuser_api_client.patch(url, {"is_handled": True})
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
report.refresh_from_db()
|
||||||
|
assert report.is_handled is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_delete(factories, superuser_api_client):
|
||||||
|
report = factories["moderation.Report"]()
|
||||||
|
url = reverse(
|
||||||
|
"api:v1:manage:moderation:reports-detail", kwargs={"uuid": report.uuid}
|
||||||
|
)
|
||||||
|
response = superuser_api_client.delete(url)
|
||||||
|
|
||||||
|
assert response.status_code == 204
|
||||||
|
|
Ładowanie…
Reference in New Issue