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

Force one config object #107

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 1.3.x
### 1.3.1
### Changes
* Forced the existence of only 1 Config object with id=1
### 1.3.0
#### Feature
* Added configuration panel in order to set custom preferences
Expand Down
12 changes: 12 additions & 0 deletions buffalogs/impossible_travel/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.db import models
from impossible_travel.constants import AlertDetectionType, AlertFilterType, UserRiskScoreType

Expand Down Expand Up @@ -133,3 +134,14 @@ class Config(models.Model):
default=settings.CERTEGO_BUFFALOGS_ALERT_MAX_DAYS, help_text="Days after which the alerts will be removed from the db"
)
ip_max_days = models.PositiveIntegerField(default=settings.CERTEGO_BUFFALOGS_IP_MAX_DAYS, help_text="Days after which the IPs will be removed from the db")

def clean(self):
if not self.pk and Config.objects.exists():
raise ValidationError("A Config object already exist - it is possible just to modify it, not to create a new one")
else:
# Config.id=1 always
self.pk = 1

def save(self, *args, **kwargs):
self.clean()
super().save(*args, **kwargs)