Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add package listing report feature #1062

wants to merge 6 commits into from

Conversation

x753
Copy link
Contributor

@x753 x753 commented Sep 16, 2024

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

@x753 x753 requested a review from MythicManiac January 3, 2025 18:34
x753 added 3 commits January 22, 2025 09:50
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
x753 added 2 commits January 26, 2025 20:57
Add tests for the Package Listing Report API and serializer
Create a Cyberstorm Package Listing Report API for future use.
Comment on lines +210 to +238
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()
Copy link
Contributor

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?

Copy link
Contributor Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants