Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da96fee

Browse files
committed
Merge pull request python#857 from malemburg/master
Disable anonymous postings by returning a 404.
2 parents ca4fdf5 + 1fcd1e3 commit da96fee

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

jobs/tests/test_views.py

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def test_job_create(self):
193193
'email': '[email protected]'
194194
}
195195

196+
# Check that anonymous posting is not allowed. See #852.
197+
response = self.client.post(url, post_data)
198+
self.assertEqual(response.status_code, 404)
199+
196200
if 0:
197201
# Disabled for now, until we have found a better solution
198202
# to fight spammers. See #852.

jobs/views.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ def get_form_kwargs(self):
278278

279279
def form_valid(self, form):
280280
""" set the creator to the current user """
281-
# Associate Job to user if they are logged in
282-
if self.request.user.is_authenticated():
283-
form.instance.creator = self.request.user
284-
else:
285-
# Temporary measure against spammers. See #852.
286-
return super().form_invalid(form)
287-
return super().form_valid(form)
288-
281+
282+
# Don't allow anonymous postings; see #852.
283+
if not self.request.user.is_authenticated():
284+
raise Http404
285+
286+
# Associate Job to user
287+
form.instance.creator = self.request.user
288+
return super().form_valid(form)
289289

290290

291291
class JobEdit(JobMixin, UpdateView):

0 commit comments

Comments
 (0)