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 throttling to contact api endpoint #1231

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rdmo/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ def visibility(self, request, pk=None):
throttle_classes=[EmailThrottle])
def contact(self, request, pk):
if settings.PROJECT_CONTACT:
try:
project = self.get_object()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self.get_object() (permission handling) is needed by the try ... except is not. Since I am not sold on the caching thing yet, I will fix this in the original branch.

except Http404:
return Response(status=status.HTTP_404_NOT_FOUND)

if request.method == 'POST':
subject = request.data.get('subject')
message = request.data.get('message')
Expand All @@ -347,11 +352,10 @@ def contact(self, request, pk):
'message': [_('This field may not be blank.')] if not message else []
})
else:
project = self.get_object()
project.catalog.prefetch_elements()
return Response(get_contact_message(request, project))
else:
return 404
return Response(status=status.HTTP_404_NOT_FOUND)

@action(detail=False, url_path='upload-accept', permission_classes=(IsAuthenticated, ))
def upload_accept(self, request):
Expand Down
Loading