Skip to content

Commit

Permalink
Merge pull request #101 from certego/revert-100-develop
Browse files Browse the repository at this point in the history
Revert "1.2.11"
  • Loading branch information
Lorygold authored Mar 7, 2024
2 parents f42b739 + 15b7b65 commit 61ae45b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
## 1.2.x
### 1.2.11
#### Bugfix
* Fixed the update of the login.updated field
* Added logging for the clear_models_periodically function
### 1.2.10
#### Changes
* Added settings into the Config model (instead of into the settings.py file)
Expand Down
14 changes: 7 additions & 7 deletions buffalogs/impossible_travel/modules/impossible_travel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def update_model(self, db_user, new_login):
:param new_user_agent: user_agent of last login
:type new_user_agent: string
"""
login = db_user.login_set.get(user_agent=new_login["agent"], country=new_login["country"], index=new_login["index"])
login.timestamp = new_login["timestamp"]
login.latitude = new_login["lat"]
login.longitude = new_login["lon"]
login.event_id = new_login["id"]
login.ip = new_login["ip"]
login.save()
db_user.login_set.filter(user_agent=new_login["agent"], country=new_login["country"], index=new_login["index"]).update(
timestamp=new_login["timestamp"],
latitude=new_login["lat"],
longitude=new_login["lon"],
event_id=new_login["id"],
ip=new_login["ip"],
)

def add_new_login(self, db_user, new_login_field):
"""Add new login if there isn't previous login on db relative to that user
Expand Down
12 changes: 4 additions & 8 deletions buffalogs/impossible_travel/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ def clear_models_periodically():
app_config = Config.objects.get(id=1)
now = timezone.now()
delete_user_time = now - timedelta(days=app_config.user_max_days)
deleted_users, _ = User.objects.filter(updated__lte=delete_user_time).delete()
logger.info(f"Deleted {deleted_users} users for periodic cleaning")
User.objects.filter(updated__lte=delete_user_time).delete()

delete_login_time = now - timedelta(days=app_config.login_max_days)
deleted_logins, _ = Login.objects.filter(updated__lte=delete_login_time).delete()
logger.info(f"Deleted {deleted_logins} logins for periodic cleaning")
Login.objects.filter(updated__lte=delete_login_time).delete()

delete_alert_time = now - timedelta(days=app_config.alert_max_days)
deleted_alerts, _ = Alert.objects.filter(updated__lte=delete_alert_time).delete()
logger.info(f"Deleted {deleted_alerts} alerts for periodic cleaning")
Alert.objects.filter(updated__lte=delete_alert_time).delete()

delete_ip_time = now - timedelta(days=app_config.ip_max_days)
deleted_usersIP, _ = UsersIP.objects.filter(updated__lte=delete_ip_time).delete()
logger.info(f"Deleted {deleted_usersIP} usersIP for periodic cleaning")
UsersIP.objects.filter(updated__lte=delete_ip_time).delete()


@shared_task(name="BuffalogsUpdateRiskLevelTask")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def test_update_model(self):
self.assertEqual(new_login_db.latitude, new_login_fields["lat"])
self.assertEqual(new_login_db.longitude, new_login_fields["lon"])
self.assertEqual(new_login_db.timestamp, new_login_fields["timestamp"])
self.assertLessEqual((timezone.now() - new_login_db.updated).seconds, 1)

def test_add_new_login(self):
new_time = timezone.now()
Expand Down

0 comments on commit 61ae45b

Please sign in to comment.