From 62c84570ccfe2ea506b50f4f194f2a1afcf0b1d9 Mon Sep 17 00:00:00 2001 From: Esther Kleinhenz Date: Tue, 30 Oct 2018 18:51:48 +0100 Subject: [PATCH] removed blacklist things --- .../python3.6/site-packages/hitcount/admin.py | 44 +------------------ .../migrations/0003_auto_20181030_1850.py | 19 ++++++++ .../site-packages/hitcount/models.py | 28 ------------ .../python3.6/site-packages/hitcount/views.py | 13 +----- 4 files changed, 22 insertions(+), 82 deletions(-) create mode 100644 thesisenv/lib/python3.6/site-packages/hitcount/migrations/0003_auto_20181030_1850.py diff --git a/thesisenv/lib/python3.6/site-packages/hitcount/admin.py b/thesisenv/lib/python3.6/site-packages/hitcount/admin.py index 3ab1616..abf031d 100644 --- a/thesisenv/lib/python3.6/site-packages/hitcount/admin.py +++ b/thesisenv/lib/python3.6/site-packages/hitcount/admin.py @@ -4,7 +4,7 @@ from django.contrib import admin from django.core.exceptions import PermissionDenied from django.utils.translation import ugettext_lazy as _ -from .models import Hit, HitCount, BlacklistIP, BlacklistUserAgent +from .models import Hit, HitCount class HitAdmin(admin.ModelAdmin): @@ -31,36 +31,6 @@ class HitAdmin(admin.ModelAdmin): del actions['delete_selected'] return actions - def blacklist_ips(self, request, queryset): - for obj in queryset: - ip, created = BlacklistIP.objects.get_or_create(ip=obj.ip) - if created: - ip.save() - msg = _("Successfully blacklisted %d IPs") % queryset.count() - self.message_user(request, msg) - blacklist_ips.short_description = _("Blacklist selected IP addresses") - - def blacklist_user_agents(self, request, queryset): - for obj in queryset: - ua, created = BlacklistUserAgent.objects.get_or_create( - user_agent=obj.user_agent) - if created: - ua.save() - msg = _("Successfully blacklisted %d User Agents") % queryset.count() - self.message_user(request, msg) - blacklist_user_agents.short_description = _("Blacklist selected User Agents") - - def blacklist_delete_ips(self, request, queryset): - self.blacklist_ips(request, queryset) - self.delete_queryset(request, queryset) - blacklist_delete_ips.short_description = _( - "Delete selected hits and blacklist related IP addresses") - - def blacklist_delete_user_agents(self, request, queryset): - self.blacklist_user_agents(request, queryset) - self.delete_queryset(request, queryset) - blacklist_delete_user_agents.short_description = _( - "Delete selected hits and blacklist related User Agents") def delete_queryset(self, request, queryset): if not self.has_delete_permission(request): @@ -88,15 +58,3 @@ class HitCountAdmin(admin.ModelAdmin): return False admin.site.register(HitCount, HitCountAdmin) - - -class BlacklistIPAdmin(admin.ModelAdmin): - pass - -admin.site.register(BlacklistIP, BlacklistIPAdmin) - - -class BlacklistUserAgentAdmin(admin.ModelAdmin): - pass - -admin.site.register(BlacklistUserAgent, BlacklistUserAgentAdmin) diff --git a/thesisenv/lib/python3.6/site-packages/hitcount/migrations/0003_auto_20181030_1850.py b/thesisenv/lib/python3.6/site-packages/hitcount/migrations/0003_auto_20181030_1850.py new file mode 100644 index 0000000..0476160 --- /dev/null +++ b/thesisenv/lib/python3.6/site-packages/hitcount/migrations/0003_auto_20181030_1850.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.2 on 2018-10-30 17:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('hitcount', '0002_index_ip_and_session'), + ] + + operations = [ + migrations.DeleteModel( + name='BlacklistIP', + ), + migrations.DeleteModel( + name='BlacklistUserAgent', + ), + ] diff --git a/thesisenv/lib/python3.6/site-packages/hitcount/models.py b/thesisenv/lib/python3.6/site-packages/hitcount/models.py index f58b8d0..0487342 100644 --- a/thesisenv/lib/python3.6/site-packages/hitcount/models.py +++ b/thesisenv/lib/python3.6/site-packages/hitcount/models.py @@ -155,34 +155,6 @@ class Hit(models.Model): super(Hit, self).delete() -@python_2_unicode_compatible -class BlacklistIP(models.Model): - - ip = models.CharField(max_length=40, unique=True) - - class Meta: - db_table = "hitcount_blacklist_ip" - verbose_name = _("Blacklisted IP") - verbose_name_plural = _("Blacklisted IPs") - - def __str__(self): - return '%s' % self.ip - - -@python_2_unicode_compatible -class BlacklistUserAgent(models.Model): - - user_agent = models.CharField(max_length=255, unique=True) - - class Meta: - db_table = "hitcount_blacklist_user_agent" - verbose_name = _("Blacklisted User Agent") - verbose_name_plural = _("Blacklisted User Agents") - - def __str__(self): - return '%s' % self.user_agent - - class HitCountMixin(object): """ HitCountMixin provides an easy way to add a `hit_count` property to your diff --git a/thesisenv/lib/python3.6/site-packages/hitcount/views.py b/thesisenv/lib/python3.6/site-packages/hitcount/views.py index 9d1b1e5..2a24562 100644 --- a/thesisenv/lib/python3.6/site-packages/hitcount/views.py +++ b/thesisenv/lib/python3.6/site-packages/hitcount/views.py @@ -8,7 +8,7 @@ from django.conf import settings from django.views.generic import View, DetailView from hitcount.utils import get_ip -from hitcount.models import Hit, HitCount, BlacklistIP, BlacklistUserAgent +from hitcount.models import Hit, HitCount from hitcount.utils import RemovedInHitCount13Warning @@ -49,16 +49,7 @@ class HitCountMixin(object): hits_per_ip_limit = getattr(settings, 'HITCOUNT_HITS_PER_IP_LIMIT', 0) exclude_user_group = getattr(settings, 'HITCOUNT_EXCLUDE_USER_GROUP', None) - # first, check our request against the IP blacklist - if BlacklistIP.objects.filter(ip__exact=ip): - return UpdateHitCountResponse( - False, 'Not counted: user IP has been blacklisted') - - # second, check our request against the user agent blacklist - if BlacklistUserAgent.objects.filter(user_agent__exact=user_agent): - return UpdateHitCountResponse( - False, 'Not counted: user agent has been blacklisted') - + # third, see if we are excluding a specific user group or not if exclude_user_group and is_authenticated_user: if user.groups.filter(name__in=exclude_user_group):