-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add package listing report feature #1062
base: master
Are you sure you want to change the base?
Conversation
django/thunderstore/community/api/experimental/views/listing.py
Outdated
Show resolved
Hide resolved
Add ts_reports app Add PackageReport model Add PackageReport admin
Create an API for reporting PackageListings (creating a PackageReport)
Adds a report button to the package details page Adds the react / tsx necessary to make it work Modifies APIError to take an extractedMessage Renames BaseApiError to BaseValidationError Adds the "required" optional property to FormSelectFieldProps
Add tests for the Package Listing Report API and serializer
Create a Cyberstorm Package Listing Report API for future use.
class ReportListingAPIView(PackageListingAPIView): | ||
queryset = PackageListing.objects.active().select_related( | ||
"package", | ||
) | ||
serializer_class = ReportPackageListingRequestSerializer | ||
permission_classes = [IsAuthenticated] | ||
|
||
def post(self, request, *args, **kwargs): | ||
serializer = self.get_serializer(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
|
||
listing: PackageListing = self.get_object() | ||
package: Package = listing.package | ||
version: PackageVersion = package.latest | ||
reason: str = serializer.validated_data["reason"] | ||
description: Optional[str] = serializer.validated_data.get("description", None) | ||
|
||
try: | ||
PackageReport.handle_user_report( | ||
reason=reason, | ||
submitted_by=request.user, | ||
package=package, | ||
package_listing=listing, | ||
package_version=version, | ||
description=description, | ||
) | ||
return Response(status=status.HTTP_200_OK) | ||
except PermissionError: | ||
raise PermissionDenied() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this view and its serializer is almost identical to the experimental one, would it be possible to break out the shared functionality instead of having this much duplicated functionality in these two APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep all the Cyberstorm API logic within the Cyberstorm folders. Consider that this is already the case for the other Cyberstorm APIs, it's only a coincidence that the logic here is a near duplicate (because it was designed for a react modal which the new site will have plenty of).
Add tests for Cyberstorm listing report API
This PR adds the PackageReport model, as well as an API for sending reports for specific listings and a button / react component to use said API.
This is heavily based on this branch: https://github.com/thunderstore-io/Thunderstore/tree/report-feature
firefox_PafGD8xsH4.mp4