Merge lp:~widelands-dev/widelands-website/anti_spambot into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 474
Proposed branch: lp:~widelands-dev/widelands-website/anti_spambot
Merge into: lp:widelands-website
Diff against target: 42 lines (+13/-1)
2 files modified
local_settings.py.sample (+1/-0)
pybb/views.py (+12/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/anti_spambot
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+332911@code.launchpad.net

Description of the change

Logout a user if he has written MAX_HIDDEN_POSTS and set his property 'is_active' to false, so he can't log in anymore. The user get prompted with a forbidden page then.

This assumes a human would not write the same thing much often when he get prompted with the 'Posts have to be mederated' info, but bots do.

The initial idea was a two step approach, by first logging out only after x hidden posts and additionally set him inactive after x+y hidden posts. But i think this is unrewarding because the url to add a new topic/post asks for login.

To post a comment you must log in.
475. By kaputtnik

formatting

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, not tested.

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Thanks :-) merged and deployed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'local_settings.py.sample'
2--- local_settings.py.sample 2017-10-17 20:07:08 +0000
3+++ local_settings.py.sample 2017-10-27 17:30:38 +0000
4@@ -51,6 +51,7 @@
5 ANTI_SPAM_BODY = ['spam']
6 ANTI_SPAM_TOPIC = ['spam']
7 ANTI_SPAM_PHONE_NR = re.compile('\d{8,16}')
8+MAX_HIDDEN_POSTS = 5
9
10 # Uncomment 'LOGGING = {...}' for debugging purposes when you have set DEBUG=False.
11 # Use then in the code:
12
13=== modified file 'pybb/views.py'
14--- pybb/views.py 2017-08-21 19:13:19 +0000
15+++ pybb/views.py 2017-10-27 17:30:38 +0000
16@@ -11,6 +11,7 @@
17 from django.db import connection
18 from django.utils import translation
19 from django.shortcuts import render
20+from django.contrib.auth import logout
21
22 from pybb.util import render_to, paged, build_form, quote_text, ajax, urlize
23 from pybb.models import Category, Forum, Topic, Post, PrivateMessage, Attachment,\
24@@ -161,7 +162,17 @@
25 post.topic.subscribers.add(request.user)
26
27 if post.hidden:
28- # Redirect to an info page to inform the user
29+ hidden_posts_count = Post.objects.filter(
30+ user=request.user, hidden=True).count()
31+
32+ if hidden_posts_count >= settings.MAX_HIDDEN_POSTS:
33+ user = get_object_or_404(User, username=request.user)
34+ # Set the user inactive so he can't login
35+ user.is_active = False
36+ user.save()
37+ # Log the user out
38+ logout(request)
39+ return HttpResponse(status=403)
40 return HttpResponseRedirect('pybb_moderate_info')
41
42 return HttpResponseRedirect(post.get_absolute_url())

Subscribers

People subscribed via source and target branches