diff --git a/cotisations/models.py b/cotisations/models.py index 60e8672e..4d775ae0 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -30,6 +30,8 @@ from django.core.validators import MinValueValidator from django.utils import timezone +from machines.models import regen + class Facture(models.Model): PRETTY_NAME = "Factures émises" @@ -180,3 +182,14 @@ class Cotisation(models.Model): def __str__(self): return str(self.vente) +@receiver(post_save, sender=Cotisation) +def cotisation_post_save(sender, **kwargs): + regen('dns') + regen('dhcp') + regen('mac_ip_list') + +@receiver(post_delete, sender=Cotisation) +def vente_post_delete(sender, **kwargs): + cotisation = kwargs['instance'] + if not cotisation.vente.facture.user.has_access(): + regen('mac_ip_list') diff --git a/machines/models.py b/machines/models.py index a54fdc32..54585849 100644 --- a/machines/models.py +++ b/machines/models.py @@ -320,8 +320,9 @@ class Service(models.Model): def regen(service): """ Fonction externe pour régérération d'un service, prend un objet service en arg""" - obj, created = Service.objects.get_or_create(service_type=service) - obj.ask_regen() + obj = Service.objects.filter(service_type=service) + if obj: + obj[0].ask_regen() return class Service_link(models.Model): @@ -360,6 +361,9 @@ def machine_post_delete(sender, **kwargs): machine = kwargs['instance'] user = machine.user user.ldap_sync(base=False, access_refresh=False, mac_refresh=True) + regen('dns') + regen('dhcp') + regen('mac_ip_list') @receiver(post_save, sender=Interface) def interface_post_save(sender, **kwargs): diff --git a/users/models.py b/users/models.py index b86060c7..34f20fdc 100644 --- a/users/models.py +++ b/users/models.py @@ -46,7 +46,7 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.core.validators import MinLengthValidator from topologie.models import Room from cotisations.models import Cotisation, Facture, Paiement, Vente -from machines.models import Interface, Machine +from machines.models import Interface, Machine, regen from preferences.models import GeneralOption, AssoOption, OptionalUser now = timezone.now() @@ -640,11 +640,18 @@ def ban_post_save(sender, **kwargs): user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) if is_created: ban.notif_ban() + regen('dhcp') + regen('mac_ip_list') + if user.has_access(): + regen('dhcp') + regen('mac_ip_list') @receiver(post_delete, sender=Ban) def ban_post_delete(sender, **kwargs): user = kwargs['instance'].user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + regen('dhcp') + regen('mac_ip_list') class Whitelist(models.Model): PRETTY_NAME = "Liste des accès gracieux" @@ -662,11 +669,20 @@ def whitelist_post_save(sender, **kwargs): whitelist = kwargs['instance'] user = whitelist.user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + is_created = kwargs['created'] + if is_created: + regen('dhcp') + regen('mac_ip_list') + if user.has_access(): + regen('dhcp') + regen('mac_ip_list') @receiver(post_delete, sender=Whitelist) def whitelist_post_delete(sender, **kwargs): user = kwargs['instance'].user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + regen('dhcp') + regen('mac_ip_list') class Request(models.Model): PASSWD = 'PW'