This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3103 from groovecoder/django-ratelimit-1122658
bug 1113260 - use django-ratelimit for ip bans
- Loading branch information
Showing
22 changed files
with
249 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib import admin | ||
|
||
from kuma.core.models import IPBan | ||
|
||
|
||
class IPBanAdmin(admin.ModelAdmin): | ||
list_display = ('ip', 'created', 'deleted') | ||
|
||
|
||
admin.site.register(IPBan, IPBanAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Delete old revision IPs | ||
""" | ||
from optparse import make_option | ||
|
||
from django.core.management.base import BaseCommand | ||
from .tasks import delete_old_ip_bans | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Delete old IP Bans" | ||
option_list = BaseCommand.option_list + ( | ||
make_option('--days', dest="days", default=30, type=int, | ||
help="How many days 'old' (Default 30)"), | ||
) | ||
|
||
def handle(self, *args, **options): | ||
self.options = options | ||
delete_old_ip_bans(days=options['days']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
import datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
# Adding model 'IPBan' | ||
db.create_table('core_ipban', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('ip', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39)), | ||
('created', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now, db_index=True)), | ||
('deleted', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)), | ||
)) | ||
db.send_create_signal('core', ['IPBan']) | ||
|
||
|
||
def backwards(self, orm): | ||
# Deleting model 'IPBan' | ||
db.delete_table('core_ipban') | ||
|
||
|
||
models = { | ||
'core.ipban': { | ||
'Meta': {'object_name': 'IPBan'}, | ||
'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'db_index': 'True'}), | ||
'deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}) | ||
} | ||
} | ||
|
||
complete_apps = ['core'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from datetime import date, timedelta | ||
|
||
from nose.tools import eq_ | ||
|
||
from django.test import TestCase | ||
|
||
from ..models import IPBan | ||
|
||
|
||
class RevisionIPTests(TestCase): | ||
def test_delete_older_than_default_30_days(self): | ||
old_date = date.today() - timedelta(days=31) | ||
IPBan(ip='127.0.0.1', created=old_date).save() | ||
eq_(1, IPBan.objects.count()) | ||
IPBan.objects.delete_old() | ||
eq_(0, IPBan.objects.count()) | ||
|
||
def test_delete_older_than_days_argument(self): | ||
ban_date = date.today() - timedelta(days=5) | ||
IPBan(ip='127.0.0.1', created=ban_date).save() | ||
eq_(1, IPBan.objects.count()) | ||
IPBan.objects.delete_old(days=4) | ||
eq_(0, IPBan.objects.count()) | ||
|
||
def test_delete_older_than_only_deletes_older_than(self): | ||
oldest_date = date.today() - timedelta(days=31) | ||
IPBan(ip='127.0.0.1', created=oldest_date).save() | ||
|
||
old_date = date.today() - timedelta(days=29) | ||
IPBan(ip='127.0.0.2', created=old_date).save() | ||
|
||
now_date = date.today() | ||
IPBan(ip='127.0.0.3', created=now_date).save() | ||
eq_(3, IPBan.objects.count()) | ||
IPBan.objects.delete_old() | ||
eq_(2, IPBan.objects.count()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.