Skip to content

Commit

Permalink
[req-changes] Moved logic to models
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Nov 1, 2023
1 parent 6e5edde commit 21c82e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
20 changes: 20 additions & 0 deletions openwisp_radius/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,3 +1560,23 @@ class Meta:
abstract = True
verbose_name = _('Registration Information')
verbose_name_plural = verbose_name

@classmethod
def unverify_inactive_users(cls):
if not app_settings.UNVERIFY_INACTIVE_USERS:
return
cls.objects.filter(
user__is_staff=False,
user__last_login__lt=timezone.now()
- timedelta(days=app_settings.UNVERIFY_INACTIVE_USERS),
).update(is_verified=False)

@classmethod
def delete_inactive_users(cls):
if not app_settings.DELETE_INACTIVE_USERS:
return
User.objects.filter(
is_staff=False,
last_login__lt=timezone.now()
- timedelta(days=app_settings.DELETE_INACTIVE_USERS),
).delete()
19 changes: 3 additions & 16 deletions openwisp_radius/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from openwisp_utils.admin_theme.email import send_email
from openwisp_utils.tasks import OpenwispCeleryTask

from . import settings as app_settings
from .radclient.client import RadClient
from .utils import load_model

Expand Down Expand Up @@ -58,26 +57,14 @@ def delete_unverified_users(older_than_days=1, exclude_methods=''):

@shared_task
def unverify_inactive_users():
if not app_settings.UNVERIFY_INACTIVE_USERS:
return
RegisteredUser = load_model('RegisteredUser')
RegisteredUser.objects.filter(
user__is_staff=False,
user__last_login__lt=timezone.now()
- timedelta(days=app_settings.UNVERIFY_INACTIVE_USERS),
).update(is_verified=False)
RegisteredUser.unverify_inactive_users()


@shared_task
def delete_inactive_users():
if not app_settings.DELETE_INACTIVE_USERS:
return
User = get_user_model()
User.objects.filter(
is_staff=False,
last_login__lt=timezone.now()
- timedelta(days=app_settings.DELETE_INACTIVE_USERS),
).delete()
RegisteredUser = load_model('RegisteredUser')
RegisteredUser.delete_inactive_users()


@shared_task
Expand Down

0 comments on commit 21c82e5

Please sign in to comment.