Commit 2e9017a7 authored by David Seaward's avatar David Seaward

* create missing limits when user is saved

* define deactivation task
parent d58b2c80
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import UserManager as BaseUserManager
from ldapdb.models.fields import CharField, ListField
import logging
import ldap
import ldapdb.models
import logging
import pyasn1.type.univ
import pyasn1.type.namedtype
import pyasn1.codec.ber.encoder
import pyasn1.type.namedtype
import pyasn1.type.univ
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import UserManager as BaseUserManager
from django.db import connections, router
from django.utils.crypto import salted_hmac
from ldapdb.models.fields import CharField, ListField
from limitmonitor import models as limitmonitor_models
log = logging.getLogger(__name__)
......@@ -66,6 +69,11 @@ class User(AbstractUser):
# force null password (will use LDAP password)
self.set_unusable_password()
# create any missing limits
# FIXME: this make ldapregister dependant on limitmonitor
# https://code.puri.sm/purist/account_web/issues/25
limitmonitor_models.create_missing_user_limits(self)
def set_password(self, raw_password):
# force null password (will use LDAP password)
......
......@@ -12,13 +12,18 @@ SERVICE_CHOICES = (
)
def create_missing_user_limits(user):
for code, label in SERVICE_CHOICES:
if not Limit.objects.filter(user=user, service=code).exists():
Limit(user=user, service=code).save()
class Limit(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
service = models.CharField(max_length=30, choices=SERVICE_CHOICES)
expiry_date = models.DateTimeField(default=None, blank=True, null=True)
volume_total = models.DecimalField(decimal_places=2, max_digits=6)
time_total = models.DecimalField(decimal_places=2, max_digits=6)
is_active = models.BooleanField()
volume_total = models.DecimalField(default=0, decimal_places=2, max_digits=6)
time_total = models.DecimalField(default=0, decimal_places=2, max_digits=6)
is_active = models.BooleanField(default=False)
created_date = models.DateTimeField(default=timezone.now)
updated_date = models.DateTimeField(default=timezone.now)
......
......@@ -167,6 +167,17 @@ def monitor_woo1():
logger.exception("Skipping result " + str(result))
@shared_task
def deactivate_all_expired_limits():
now = timezone.now()
overdue_list = Limit.objects.filter(expiry_date__lte=now, is_active=True)
for limit in overdue_list:
limit.is_active = False
limit.save()
# TODO: also send deactivation command
@shared_task
def debug_task(self):
woo_connection = get_woo_connection()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment